Skip to content

Commit

Permalink
refactor: Adding noticeMessage for workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed May 23, 2022
1 parent 6506664 commit 712d381
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 40 deletions.
43 changes: 8 additions & 35 deletions mkdocsPublisher/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "./settings";
import { ShareStatusBar } from "./utils/status_bar";
import MkdocsPublish from "./utils/publication";
import { disablePublish } from "./utils/utils";
import { disablePublish, noticeMessage } from "./utils/utils";

export default class MkdocsPublication extends Plugin {
settings: MkdocsPublicationSettings;
Expand Down Expand Up @@ -40,13 +40,7 @@ export default class MkdocsPublication extends Plugin {
const publishSuccess =
await publish.publish(file, true);
if (publishSuccess) {
new Notice('Send "' + file.basename + '" to ' + this.settings.githubRepo + ".\nNow, waiting for the workflow to be completed...")
await publish.workflowGestion();
new Notice(
"Successfully published " +
file.basename +
" to " + this.settings.githubRepo + "."
);
await noticeMessage(publish, file, this.settings)
}

} catch (e) {
Expand Down Expand Up @@ -84,13 +78,7 @@ export default class MkdocsPublication extends Plugin {
const publishSuccess =
await publish.publish(view.file, true);
if (publishSuccess) {
new Notice('Send "' + view.file.basename + '" to ' + this.settings.githubRepo + ".\nNow, waiting for the workflow to be completed...")
await publish.workflowGestion();
new Notice(
"Successfully published " +
view.file.basename +
" to " + this.settings.githubRepo + "."
);
await noticeMessage(publish, view.file, this.settings)
}
} catch (e) {
console.error(e);
Expand Down Expand Up @@ -129,13 +117,7 @@ export default class MkdocsPublication extends Plugin {
true
);
if (publishSuccess) {
new Notice('Send "' + currentFile.basename + '"to ' + this.settings.githubRepo + ".\nNow, waiting for the workflow to be completed...")
publishFile.workflowGestion();
new Notice(
"Successfully published " +
currentFile.basename +
" to " + this.settings.githubRepo + "."
);
noticeMessage(publishFile, currentFile, this.settings);
}
} catch (e) {
console.error(e);
Expand Down Expand Up @@ -172,11 +154,11 @@ export default class MkdocsPublication extends Plugin {
);
// upload list of published files in Source
const publishedFilesText = JSON.stringify(publishedFiles).toString();
const publishedJsonPath = this.settings.folderDefaultName + '/vault_published.json'
const vaultPublisherJSON = this.settings.folderDefaultName.length>0? `${this.settings.folderDefaultName}/vault_published.json`:`vault_published.json`;
await publish.uploadText(
"vault_published.json",
publishedFilesText,
publishedJsonPath
vaultPublisherJSON
);
for (
let files = 0;
Expand All @@ -195,17 +177,8 @@ export default class MkdocsPublication extends Plugin {
}
}
statusBar.finish(8000);
new Notice(
`Send ${
publishedFiles.length - errorCount
} notes to ${this.settings.githubRepo}`
);
await publish.workflowGestion();
new Notice(
`Successfully published ${
publishedFiles.length - errorCount
} notes to ${this.settings.githubRepo}.\nNow, waiting for the workflow to be completed...`
);
const noticeValue = `${publishedFiles.length - errorCount} notes`
await noticeMessage(publish, noticeValue, this.settings)
}
} catch (e) {
// statusBarItems.remove();
Expand Down
12 changes: 7 additions & 5 deletions mkdocsPublisher/utils/publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default class MkdocsPublish {
if (folder.length > 0) {
const publishedFiles = folder.map(file => file.name);
const publishedFilesText = JSON.stringify(publishedFiles).toString();
const vaultPublisherJSON = this.settings.folderDefaultName + '/vault_published.json';
const vaultPublisherJSON = this.settings.folderDefaultName.length>0? `${this.settings.folderDefaultName}/vault_published.json`:`vault_published.json`;
await this.uploadText('vault_published.json', publishedFilesText, vaultPublisherJSON);
}
}
Expand Down Expand Up @@ -175,7 +175,10 @@ export default class MkdocsPublish {
}

async workflowGestion () {
if (this.settings.workflowName.length > 0) {
let finished=false;
if (this.settings.workflowName.length === 0) {
return false;
} else {
const octokit = new Octokit({
auth: this.settings.GhToken
})
Expand All @@ -185,7 +188,6 @@ export default class MkdocsPublish {
workflow_id: this.settings.workflowName,
ref: 'main'
})
let finished = false;
while (!finished) {
await sleep(10000)
const workflowGet = await octokit.request('GET /repos/{owner}/{repo}/actions/runs', {
Expand All @@ -195,11 +197,11 @@ export default class MkdocsPublish {
if (workflowGet.data.workflow_runs.length > 0) {
const build = workflowGet.data.workflow_runs.find(run => run.name === this.settings.workflowName.replace('.yml', ''))
if (build.status === 'completed') {
finished = true
finished = true;
return true;
}
}
}
}
return;
}
}

0 comments on commit 712d381

Please sign in to comment.