From 9dac3cbee13b286ba5c692cd521a8e22cece5d3e Mon Sep 17 00:00:00 2001 From: Julius Date: Sat, 30 Sep 2023 16:44:54 +0300 Subject: [PATCH] publishMultiple: stop if nothing to publish (#433) * publishMultiple: stop if nothing to publish * commands: validate github settings before commands --- main.ts | 14 ++++++++ src/publisher/Publisher.ts | 66 +++++++++++++++----------------------- 2 files changed, 39 insertions(+), 41 deletions(-) diff --git a/main.ts b/main.ts index 0caf5568..4932b822 100644 --- a/main.ts +++ b/main.ts @@ -171,6 +171,7 @@ export default class DigitalGarden extends Plugin { metadataCache, this.settings, ); + publisher.validateSettings(); const siteManager = new DigitalGardenSiteManager( metadataCache, @@ -191,6 +192,18 @@ export default class DigitalGarden extends Plugin { const filesToDelete = publishStatus.deletedNotePaths; const imagesToDelete = publishStatus.deletedImagePaths; + const totalItems = + filesToPublish.length + + filesToDelete.length + + imagesToDelete.length; + + if (totalItems === 0) { + new Notice("Garden is already fully synced!"); + statusBarItem.remove(); + + return; + } + const statusBar = new PublishStatusBar( statusBarItem, filesToPublish.length + @@ -387,6 +400,7 @@ export default class DigitalGarden extends Plugin { metadataCache, this.settings, ); + publisher.validateSettings(); const publishSuccessful = await publisher.publish(activeFile); if (publishSuccessful) { diff --git a/src/publisher/Publisher.ts b/src/publisher/Publisher.ts index a9457b1f..fa18a1b5 100644 --- a/src/publisher/Publisher.ts +++ b/src/publisher/Publisher.ts @@ -86,27 +86,7 @@ export default class Publisher { } async delete(path: string): Promise { - if (!this.settings.githubRepo) { - new Notice( - "Config error: You need to define a GitHub repo in the plugin settings", - ); - throw {}; - } - - if (!this.settings.githubUserName) { - new Notice( - "Config error: You need to define a GitHub Username in the plugin settings", - ); - throw {}; - } - - if (!this.settings.githubToken) { - new Notice( - "Config error: You need to define a GitHub Token in the plugin settings", - ); - throw {}; - } - + this.validateSettings(); const octokit = new Octokit({ auth: this.settings.githubToken }); const payload = { @@ -173,26 +153,7 @@ export default class Publisher { } async uploadToGithub(path: string, content: string) { - if (!this.settings.githubRepo) { - new Notice( - "Config error: You need to define a GitHub repo in the plugin settings", - ); - throw {}; - } - - if (!this.settings.githubUserName) { - new Notice( - "Config error: You need to define a GitHub Username in the plugin settings", - ); - throw {}; - } - - if (!this.settings.githubToken) { - new Notice( - "Config error: You need to define a GitHub Token in the plugin settings", - ); - throw {}; - } + this.validateSettings(); const octokit = new Octokit({ auth: this.settings.githubToken }); @@ -249,4 +210,27 @@ export default class Publisher { await this.uploadImage(image.path, image.content); } } + + validateSettings() { + if (!this.settings.githubRepo) { + new Notice( + "Config error: You need to define a GitHub repo in the plugin settings", + ); + throw {}; + } + + if (!this.settings.githubUserName) { + new Notice( + "Config error: You need to define a GitHub Username in the plugin settings", + ); + throw {}; + } + + if (!this.settings.githubToken) { + new Notice( + "Config error: You need to define a GitHub Token in the plugin settings", + ); + throw {}; + } + } }