From 8d810d6f97e7dce471ab27c52d998a76ac7a1baa Mon Sep 17 00:00:00 2001 From: Mara Date: Wed, 8 May 2024 05:21:38 +0200 Subject: [PATCH] refactor: no need to check validity if repo was already validated --- src/main.ts | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main.ts b/src/main.ts index fa820dc1..2273af44 100644 --- a/src/main.ts +++ b/src/main.ts @@ -157,21 +157,17 @@ export default class GithubPublisher extends Plugin { } /** - * Create a new instance of Octokit to load a new instance of GithubBranch + * Create a new instance of Octokit to load a new instance of GithubBranch + * @param {string} repo - The repository to load the Octokit for */ async reloadOctokit(repo?: string) { - let octokit: Octokit; const apiSettings = this.settings.github.api; const token = await this.loadToken(repo); - if (apiSettings.tiersForApi === GithubTiersVersion.entreprise && apiSettings.hostname.length > 0) { - octokit = new Octokit( - { - baseUrl: `${apiSettings.hostname}/api/v3`, - auth: token, - }); - } else { - octokit = new Octokit({ auth: token }); - } + const octokit = apiSettings.tiersForApi === GithubTiersVersion.entreprise && apiSettings.hostname.length > 0 ? new Octokit( + { + baseUrl: `${apiSettings.hostname}/api/v3`, + auth: token, + }) : new Octokit({ auth: token }); return new GithubBranch( octokit, this, @@ -214,9 +210,12 @@ export default class GithubPublisher extends Plugin { } for (const repository of this.settings.github.otherRepo) { - const repoOctokit = await this.reloadOctokit(repository.smartKey); - repository.verifiedRepo = await checkRepositoryValidity(repoOctokit, repository, null, false); - repository.rateLimit = await verifyRateLimitAPI(repoOctokit.octokit, this.settings); + if (!repository.verifiedRepo && (await this.loadToken(repository.smartKey)) !== "") + { + const repoOctokit = await this.reloadOctokit(repository.smartKey); + repository.verifiedRepo = await checkRepositoryValidity(repoOctokit, repository, null, false); + repository.rateLimit = await verifyRateLimitAPI(repoOctokit.octokit, this.settings); + } if (repository.set) { //take the file and update the frontmatter