From 16511ede303233a6a802d732cf87de58d5568fae Mon Sep 17 00:00:00 2001 From: Blue Falcon Date: Mon, 24 Jun 2024 17:09:10 -0700 Subject: [PATCH 01/10] patch manifest url --- src/modals/PluginDataModal.ts | 15 +++++++++------ src/modals/PluginTroubleshootingModal.ts | 2 +- src/settings/SettingsTab.ts | 6 +++++- src/util/GitHub.ts | 13 +++++++++---- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/modals/PluginDataModal.ts b/src/modals/PluginDataModal.ts index 5ff745b..1f23932 100644 --- a/src/modals/PluginDataModal.ts +++ b/src/modals/PluginDataModal.ts @@ -62,18 +62,21 @@ export class PluginDataModal extends Modal { new Notice('Github / do not match the pattern!'); return; } - // Check a manifest could be fetched - const manifest = await fetchManifest(repo); - if (!manifest) { - new Notice('Github repository could not be found!'); - return; - } // check there are releases for the repo const releases = await fetchReleases(repo); if (!releases || releases.length <= 0) { new Notice('No releases found for this plugin. May it do not have any.'); return; } + // Check a manifest could be fetched + const manifest = + await fetchManifest(undefined,undefined,releases[0].manifest_url) || + await fetchManifest(repo, releases[0].tag_name) || + await fetchManifest(repo); + if (!manifest) { + new Notice('Github repository could not be found!'); + return; + } // Combine data const pluginInfo = Object.assign({}, manifest, { repo, releases }) as PluginInfo; pluginInfo.targetVersion = pluginInfo.version; diff --git a/src/modals/PluginTroubleshootingModal.ts b/src/modals/PluginTroubleshootingModal.ts index c1b07e1..433b005 100644 --- a/src/modals/PluginTroubleshootingModal.ts +++ b/src/modals/PluginTroubleshootingModal.ts @@ -69,7 +69,7 @@ export class PluginTroubleshootingModal extends Modal { })); if (repositoryRegEx.test(this.pluginInfo.repo)) { - manifest = await fetchManifest(this.pluginInfo.repo); + manifest = await fetchManifest(this.pluginInfo.repo); // leaving this one alone as it seems to serve a different purpose - Blue Falcon hasManifest = manifest !== undefined; new Setting(contentEl) .setName('Test connection') diff --git a/src/settings/SettingsTab.ts b/src/settings/SettingsTab.ts index c6141f7..b5084b6 100644 --- a/src/settings/SettingsTab.ts +++ b/src/settings/SettingsTab.ts @@ -186,7 +186,11 @@ export class VareSettingTab extends PluginSettingTab { .onClick(async () => { try { // Fetch the manifest from GitHub - const manifest = await fetchManifest(plugin.repo, plugin.targetVersion); + const manifest_url = plugin.releases.find(release => release.tag_name === plugin.targetVersion)?.manifest_url; + const manifest = + await fetchManifest(undefined,undefined,manifest_url) || + await fetchManifest(plugin.repo, plugin.targetVersion) || + await fetchManifest(plugin.repo); if (!manifest) { throw Error('No manifest found for this plugin!'); } diff --git a/src/util/GitHub.ts b/src/util/GitHub.ts index 606d2ec..6818da4 100644 --- a/src/util/GitHub.ts +++ b/src/util/GitHub.ts @@ -16,6 +16,7 @@ export interface CommunityPlugin { export type Release = { url: string; + manifest_url: string; html_url: string; assets_url: string; upload_url: string; @@ -85,6 +86,9 @@ export async function fetchReleases(repository: string): Promise { + asset.name === 'manifest.json'; + })?.browser_download_url, }; }); return releases; @@ -99,16 +103,17 @@ export async function fetchReleases(repository: string): Promise/ of the plugin * @param tag_name The name of the tag associated with a release. Required if a specific manifest version is needed. + * @param url The url to the manifest file. Optional. If not provided, the default url will be used. * @returns The plugin manifest object */ -export async function fetchManifest(repository: string, tag_name?: string): Promise { - const URL = `https://raw.githubusercontent.com/${repository}/${tag_name ? tag_name : 'HEAD'}/manifest.json`; +export async function fetchManifest(repository?: string, tag_name?: string, url?:string): Promise { + url = url ? url : `https://raw.githubusercontent.com/${repository}/${tag_name ? tag_name : 'HEAD'}/manifest.json`; try { - if (!repositoryRegEx.test(repository)) { + if (repository && !repositoryRegEx.test(repository)) { throw Error('Repository string do not match the pattern!'); } // Do a request to the url - const response = await request({ url: URL }); + const response = await request({ url }); // Process the response return (await JSON.parse(response)) as PluginManifest; From 97e348032716de4d27d621d561f942a5d7dfe5e1 Mon Sep 17 00:00:00 2001 From: Blue Falcon Date: Mon, 24 Jun 2024 17:46:29 -0700 Subject: [PATCH 02/10] fix: :ambulance: fix fetchReleases() --- src/util/GitHub.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/util/GitHub.ts b/src/util/GitHub.ts index 6818da4..8959d28 100644 --- a/src/util/GitHub.ts +++ b/src/util/GitHub.ts @@ -86,9 +86,7 @@ export async function fetchReleases(repository: string): Promise { - asset.name === 'manifest.json'; - })?.browser_download_url, + manifest_url: value.assets.find((asset: Asset) => asset.name === 'manifest.json')?.browser_download_url, }; }); return releases; From 7814eedd6ecf6ecab699e867bac02db2fb18c2b3 Mon Sep 17 00:00:00 2001 From: Blue Falcon Date: Tue, 25 Jun 2024 10:12:14 -0700 Subject: [PATCH 03/10] refactor: :construction: implement 4Source's requested change see: https://github.com/4Source/vare-obsidian-plugin/pull/14/files#r1652895731 --- src/modals/PluginDataModal.ts | 4 +-- src/modals/PluginTroubleshootingModal.ts | 39 ++++++++++++------------ src/settings/SettingsTab.ts | 4 +-- src/util/GitHub.ts | 9 +++--- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/modals/PluginDataModal.ts b/src/modals/PluginDataModal.ts index 1f23932..fbccd09 100644 --- a/src/modals/PluginDataModal.ts +++ b/src/modals/PluginDataModal.ts @@ -70,11 +70,11 @@ export class PluginDataModal extends Modal { } // Check a manifest could be fetched const manifest = - await fetchManifest(undefined,undefined,releases[0].manifest_url) || + await fetchManifest(undefined,undefined,releases[0]) || await fetchManifest(repo, releases[0].tag_name) || await fetchManifest(repo); if (!manifest) { - new Notice('Github repository could not be found!'); + new Notice('Plugin manifest could not be found in releases, tag ref, or default branch!'); return; } // Combine data diff --git a/src/modals/PluginTroubleshootingModal.ts b/src/modals/PluginTroubleshootingModal.ts index 433b005..d36dc71 100644 --- a/src/modals/PluginTroubleshootingModal.ts +++ b/src/modals/PluginTroubleshootingModal.ts @@ -67,13 +67,29 @@ export class PluginTroubleshootingModal extends Modal { .onClick(() => { this.update(); })); + + releases = await fetchReleases(this.pluginInfo.repo); + hasReleases = releases !== undefined && (releases.length > 0); + new Setting(contentEl) + .setName('Test releases') + .setDesc(hasReleases ? '' : 'Could not find releases on GitHub. May this plugin did not have any.') + .addExtraButton(button => button + .setIcon(hasReleases ? ICON_ACCEPT : ICON_DENY) + .setTooltip(hasReleases ? '' : 'Try again?') + .setDisabled(hasReleases) + .onClick(() => { + this.update(); + })); - if (repositoryRegEx.test(this.pluginInfo.repo)) { - manifest = await fetchManifest(this.pluginInfo.repo); // leaving this one alone as it seems to serve a different purpose - Blue Falcon + if (repositoryRegEx.test(this.pluginInfo.repo) || hasReleases) { + const last_release = releases ? releases[0] : undefined; + manifest = + await fetchManifest(undefined,undefined,last_release) || + await fetchManifest(this.pluginInfo.repo); hasManifest = manifest !== undefined; new Setting(contentEl) - .setName('Test connection') - .setDesc(hasManifest ? '' : 'Repo could not be found on GitHub. Is everything typed correctly?') + .setName('Test manifest') + .setDesc(hasManifest ? '' : 'Manifest could not be found on GitHub. Is everything including the repo typed correctly?') .addExtraButton(button => button .setIcon(hasManifest ? ICON_ACCEPT : ICON_DENY) .setTooltip(hasManifest ? '' : 'Try again?') @@ -83,21 +99,6 @@ export class PluginTroubleshootingModal extends Modal { })); } - if (hasManifest) { - releases = await fetchReleases(this.pluginInfo.repo); - hasReleases = releases !== undefined && (releases.length > 0); - new Setting(contentEl) - .setName('Test releases') - .setDesc(hasReleases ? '' : 'Could not find releases on GitHub. May this plugin did not have any.') - .addExtraButton(button => button - .setIcon(hasReleases ? ICON_ACCEPT : ICON_DENY) - .setTooltip(hasReleases ? '' : 'Try again?') - .setDisabled(hasReleases) - .onClick(() => { - this.update(); - })); - } - new Setting(contentEl) .addButton(button => button .setButtonText('Save') diff --git a/src/settings/SettingsTab.ts b/src/settings/SettingsTab.ts index b5084b6..88019d9 100644 --- a/src/settings/SettingsTab.ts +++ b/src/settings/SettingsTab.ts @@ -186,9 +186,9 @@ export class VareSettingTab extends PluginSettingTab { .onClick(async () => { try { // Fetch the manifest from GitHub - const manifest_url = plugin.releases.find(release => release.tag_name === plugin.targetVersion)?.manifest_url; + const release = plugin.releases.find(release => release.tag_name === plugin.targetVersion); const manifest = - await fetchManifest(undefined,undefined,manifest_url) || + await fetchManifest(undefined,undefined,release) || await fetchManifest(plugin.repo, plugin.targetVersion) || await fetchManifest(plugin.repo); if (!manifest) { diff --git a/src/util/GitHub.ts b/src/util/GitHub.ts index 8959d28..06b6757 100644 --- a/src/util/GitHub.ts +++ b/src/util/GitHub.ts @@ -16,7 +16,6 @@ export interface CommunityPlugin { export type Release = { url: string; - manifest_url: string; html_url: string; assets_url: string; upload_url: string; @@ -86,7 +85,6 @@ export async function fetchReleases(repository: string): Promise asset.name === 'manifest.json')?.browser_download_url, }; }); return releases; @@ -101,11 +99,12 @@ export async function fetchReleases(repository: string): Promise/ of the plugin * @param tag_name The name of the tag associated with a release. Required if a specific manifest version is needed. - * @param url The url to the manifest file. Optional. If not provided, the default url will be used. + * @param release The release object of the plugin. Used to replicate Obsidian's behavior of fetching the manifest for the plugin. * @returns The plugin manifest object */ -export async function fetchManifest(repository?: string, tag_name?: string, url?:string): Promise { - url = url ? url : `https://raw.githubusercontent.com/${repository}/${tag_name ? tag_name : 'HEAD'}/manifest.json`; +export async function fetchManifest(repository?: string, tag_name?: string, release?: Partial): Promise { + const download_url: string | undefined = release?.assets?.find((asset: Asset) => asset.name === 'manifest.json')?.browser_download_url; + const url: string = download_url ? download_url : `https://raw.githubusercontent.com/${repository}/${tag_name ? tag_name : 'HEAD'}/manifest.json`; try { if (repository && !repositoryRegEx.test(repository)) { throw Error('Repository string do not match the pattern!'); From 28de80a3879fd53885f14b3fe15c660dabb5988d Mon Sep 17 00:00:00 2001 From: Blue Falcon Date: Tue, 25 Jun 2024 10:20:10 -0700 Subject: [PATCH 04/10] fix: :rotating_light: fix linter warnings --- src/modals/PluginTroubleshootingModal.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modals/PluginTroubleshootingModal.ts b/src/modals/PluginTroubleshootingModal.ts index d36dc71..4344ab4 100644 --- a/src/modals/PluginTroubleshootingModal.ts +++ b/src/modals/PluginTroubleshootingModal.ts @@ -23,7 +23,7 @@ export class PluginTroubleshootingModal extends Modal { let repository = this.pluginInfo.repo.split('/').at(1) || ''; let manifest: PluginManifest | undefined; let hasManifest = false; - let releases: Partial[] | undefined; + // let releases: Partial[] | undefined; let hasReleases = false; // Debonce text input @@ -68,7 +68,7 @@ export class PluginTroubleshootingModal extends Modal { this.update(); })); - releases = await fetchReleases(this.pluginInfo.repo); + const releases = await fetchReleases(this.pluginInfo.repo); hasReleases = releases !== undefined && (releases.length > 0); new Setting(contentEl) .setName('Test releases') From 26bfa79cf31838d83b2a4d82473ade70155c51ee Mon Sep 17 00:00:00 2001 From: Blue Falcon Date: Tue, 25 Jun 2024 10:21:54 -0700 Subject: [PATCH 05/10] fix: :ambulance: fix linter warnings --- src/modals/PluginTroubleshootingModal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modals/PluginTroubleshootingModal.ts b/src/modals/PluginTroubleshootingModal.ts index 4344ab4..46b816c 100644 --- a/src/modals/PluginTroubleshootingModal.ts +++ b/src/modals/PluginTroubleshootingModal.ts @@ -2,7 +2,7 @@ import { Modal, PluginManifest, Setting, debounce } from 'obsidian'; import { ICON_ACCEPT, ICON_DENY } from 'src/constants'; import VarePlugin from 'src/main'; import { PluginInfo } from 'src/settings/SettingsInterface'; -import { Release, fetchManifest, fetchReleases, repositoryRegEx } from 'src/util/GitHub'; +import { /* Release, */ fetchManifest, fetchReleases, repositoryRegEx } from 'src/util/GitHub'; export class PluginTroubleshootingModal extends Modal { plugin: VarePlugin; From bba6e6a3c8b0ba30190f5f7cf3d7a7cf298339b4 Mon Sep 17 00:00:00 2001 From: Blue Falcon Date: Tue, 25 Jun 2024 10:30:48 -0700 Subject: [PATCH 06/10] fix: :ambulance: fix missing partial release property --- src/util/GitHub.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/GitHub.ts b/src/util/GitHub.ts index 06b6757..846eaff 100644 --- a/src/util/GitHub.ts +++ b/src/util/GitHub.ts @@ -85,6 +85,7 @@ export async function fetchReleases(repository: string): Promise Date: Tue, 25 Jun 2024 12:59:58 -0700 Subject: [PATCH 07/10] style: :pencil2: implement 4Source's requested change --- src/modals/PluginTroubleshootingModal.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/modals/PluginTroubleshootingModal.ts b/src/modals/PluginTroubleshootingModal.ts index 46b816c..932d569 100644 --- a/src/modals/PluginTroubleshootingModal.ts +++ b/src/modals/PluginTroubleshootingModal.ts @@ -2,7 +2,7 @@ import { Modal, PluginManifest, Setting, debounce } from 'obsidian'; import { ICON_ACCEPT, ICON_DENY } from 'src/constants'; import VarePlugin from 'src/main'; import { PluginInfo } from 'src/settings/SettingsInterface'; -import { /* Release, */ fetchManifest, fetchReleases, repositoryRegEx } from 'src/util/GitHub'; +import { fetchManifest, fetchReleases, repositoryRegEx } from 'src/util/GitHub'; export class PluginTroubleshootingModal extends Modal { plugin: VarePlugin; @@ -23,7 +23,6 @@ export class PluginTroubleshootingModal extends Modal { let repository = this.pluginInfo.repo.split('/').at(1) || ''; let manifest: PluginManifest | undefined; let hasManifest = false; - // let releases: Partial[] | undefined; let hasReleases = false; // Debonce text input From 7e063be01c0717cf4867537396b6f1f37425fde4 Mon Sep 17 00:00:00 2001 From: 4Source <38220764+4Source@users.noreply.github.com> Date: Tue, 25 Jun 2024 22:36:16 +0200 Subject: [PATCH 08/10] Fixes additional / if copy path in username/repository --- src/modals/PluginTroubleshootingModal.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/modals/PluginTroubleshootingModal.ts b/src/modals/PluginTroubleshootingModal.ts index 932d569..64a4da5 100644 --- a/src/modals/PluginTroubleshootingModal.ts +++ b/src/modals/PluginTroubleshootingModal.ts @@ -41,7 +41,14 @@ export class PluginTroubleshootingModal extends Modal { .setPlaceholder('Username') .setValue(username) .onChange(value => { + if (value.contains('/')) { + const repoSections = value.split('/'); + username = repoSections[0]; + repository = repoSections[1]; + } + else { username = value; + } updateRepo(); })); @@ -52,7 +59,14 @@ export class PluginTroubleshootingModal extends Modal { .setPlaceholder('Repository') .setValue(repository) .onChange(value => { + if (value.contains('/')) { + const repoSections = value.split('/'); + username = repoSections[0]; + repository = repoSections[1]; + } + else { repository = value; + } updateRepo(); })); From c34964d5410643f7f8dea178db1f3774d2e5dc32 Mon Sep 17 00:00:00 2001 From: 4Source <38220764+4Source@users.noreply.github.com> Date: Tue, 25 Jun 2024 22:37:20 +0200 Subject: [PATCH 09/10] More consistant look of Troubleshooting state --- src/modals/PluginTroubleshootingModal.ts | 37 +++++++++++++----------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/modals/PluginTroubleshootingModal.ts b/src/modals/PluginTroubleshootingModal.ts index 64a4da5..d8a9371 100644 --- a/src/modals/PluginTroubleshootingModal.ts +++ b/src/modals/PluginTroubleshootingModal.ts @@ -47,7 +47,7 @@ export class PluginTroubleshootingModal extends Modal { repository = repoSections[1]; } else { - username = value; + username = value; } updateRepo(); })); @@ -65,7 +65,7 @@ export class PluginTroubleshootingModal extends Modal { repository = repoSections[1]; } else { - repository = value; + repository = value; } updateRepo(); })); @@ -80,24 +80,27 @@ export class PluginTroubleshootingModal extends Modal { .onClick(() => { this.update(); })); - - const releases = await fetchReleases(this.pluginInfo.repo); - hasReleases = releases !== undefined && (releases.length > 0); - new Setting(contentEl) - .setName('Test releases') - .setDesc(hasReleases ? '' : 'Could not find releases on GitHub. May this plugin did not have any.') - .addExtraButton(button => button - .setIcon(hasReleases ? ICON_ACCEPT : ICON_DENY) - .setTooltip(hasReleases ? '' : 'Try again?') - .setDisabled(hasReleases) - .onClick(() => { - this.update(); - })); + + let releases = undefined; + if (repositoryRegEx.test(this.pluginInfo.repo)) { + releases = await fetchReleases(this.pluginInfo.repo); + hasReleases = releases !== undefined && (releases.length > 0); + new Setting(contentEl) + .setName('Test releases') + .setDesc(hasReleases ? '' : 'Could not find releases on GitHub. May this plugin did not have any.') + .addExtraButton(button => button + .setIcon(hasReleases ? ICON_ACCEPT : ICON_DENY) + .setTooltip(hasReleases ? '' : 'Try again?') + .setDisabled(hasReleases) + .onClick(() => { + this.update(); + })); + } - if (repositoryRegEx.test(this.pluginInfo.repo) || hasReleases) { + if (repositoryRegEx.test(this.pluginInfo.repo) && hasReleases) { const last_release = releases ? releases[0] : undefined; manifest = - await fetchManifest(undefined,undefined,last_release) || + await fetchManifest(undefined, undefined, last_release) || await fetchManifest(this.pluginInfo.repo); hasManifest = manifest !== undefined; new Setting(contentEl) From e06546e50538bc5a64da1b2b59c003980a251903 Mon Sep 17 00:00:00 2001 From: 4Source <38220764+4Source@users.noreply.github.com> Date: Tue, 25 Jun 2024 22:58:10 +0200 Subject: [PATCH 10/10] Fix missing Type for releases --- src/modals/PluginTroubleshootingModal.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modals/PluginTroubleshootingModal.ts b/src/modals/PluginTroubleshootingModal.ts index d8a9371..5be8806 100644 --- a/src/modals/PluginTroubleshootingModal.ts +++ b/src/modals/PluginTroubleshootingModal.ts @@ -2,7 +2,7 @@ import { Modal, PluginManifest, Setting, debounce } from 'obsidian'; import { ICON_ACCEPT, ICON_DENY } from 'src/constants'; import VarePlugin from 'src/main'; import { PluginInfo } from 'src/settings/SettingsInterface'; -import { fetchManifest, fetchReleases, repositoryRegEx } from 'src/util/GitHub'; +import { Release, fetchManifest, fetchReleases, repositoryRegEx } from 'src/util/GitHub'; export class PluginTroubleshootingModal extends Modal { plugin: VarePlugin; @@ -81,7 +81,7 @@ export class PluginTroubleshootingModal extends Modal { this.update(); })); - let releases = undefined; + let releases: Partial[] | undefined = undefined; if (repositoryRegEx.test(this.pluginInfo.repo)) { releases = await fetchReleases(this.pluginInfo.repo); hasReleases = releases !== undefined && (releases.length > 0);