Skip to content

Commit

Permalink
refactor: no need to check validity if repo was already validated
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed May 8, 2024
1 parent 2287c01 commit 8d810d6
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8d810d6

Please sign in to comment.