diff --git a/src/modals/PluginDataModal.ts b/src/modals/PluginDataModal.ts index 5ff745b..fbccd09 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]) || + await fetchManifest(repo, releases[0].tag_name) || + await fetchManifest(repo); + if (!manifest) { + new Notice('Plugin manifest could not be found in releases, tag ref, or default branch!'); + 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..5be8806 100644 --- a/src/modals/PluginTroubleshootingModal.ts +++ b/src/modals/PluginTroubleshootingModal.ts @@ -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 @@ -42,7 +41,14 @@ export class PluginTroubleshootingModal extends Modal { .setPlaceholder('Username') .setValue(username) .onChange(value => { - username = value; + if (value.contains('/')) { + const repoSections = value.split('/'); + username = repoSections[0]; + repository = repoSections[1]; + } + else { + username = value; + } updateRepo(); })); @@ -53,7 +59,14 @@ export class PluginTroubleshootingModal extends Modal { .setPlaceholder('Repository') .setValue(repository) .onChange(value => { - repository = value; + if (value.contains('/')) { + const repoSections = value.split('/'); + username = repoSections[0]; + repository = repoSections[1]; + } + else { + repository = value; + } updateRepo(); })); @@ -67,23 +80,9 @@ export class PluginTroubleshootingModal extends Modal { .onClick(() => { this.update(); })); - + + let releases: Partial[] | undefined = undefined; if (repositoryRegEx.test(this.pluginInfo.repo)) { - manifest = 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?') - .addExtraButton(button => button - .setIcon(hasManifest ? ICON_ACCEPT : ICON_DENY) - .setTooltip(hasManifest ? '' : 'Try again?') - .setDisabled(hasManifest) - .onClick(() => { - this.update(); - })); - } - - if (hasManifest) { releases = await fetchReleases(this.pluginInfo.repo); hasReleases = releases !== undefined && (releases.length > 0); new Setting(contentEl) @@ -98,6 +97,24 @@ export class PluginTroubleshootingModal extends Modal { })); } + 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 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?') + .setDisabled(hasManifest) + .onClick(() => { + this.update(); + })); + } + new Setting(contentEl) .addButton(button => button .setButtonText('Save') diff --git a/src/settings/SettingsTab.ts b/src/settings/SettingsTab.ts index c6141f7..88019d9 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 release = plugin.releases.find(release => release.tag_name === plugin.targetVersion); + const manifest = + await fetchManifest(undefined,undefined,release) || + 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..846eaff 100644 --- a/src/util/GitHub.ts +++ b/src/util/GitHub.ts @@ -85,6 +85,7 @@ 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 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): Promise { - const 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 (!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;