Skip to content

Commit

Permalink
publishMultiple: stop if nothing to publish
Browse files Browse the repository at this point in the history
  • Loading branch information
julesvirallinen committed Sep 27, 2023
1 parent 1ec5236 commit f2e8b38
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 41 deletions.
12 changes: 12 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,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 +
Expand Down
66 changes: 25 additions & 41 deletions src/publisher/Publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,7 @@ export default class Publisher {
}

async delete(path: string): Promise<boolean> {
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 = {
Expand Down Expand Up @@ -169,26 +149,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 });

Expand Down Expand Up @@ -245,4 +206,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 {};
}
}
}

0 comments on commit f2e8b38

Please sign in to comment.