Skip to content

Commit

Permalink
chore: catch config not found hopefully it does throw
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Feb 27, 2024
1 parent 4acdcd5 commit 3fcbd6a
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,22 @@ export async function getUbiquiBotConfig(octokit: Octokit, owner: string, repo:
}

async function fetchConfig(octokit: Octokit, owner: string, repo: string): Promise<UbiquiBotConfig | null> {
const response = await octokit.rest.repos.getContent({
owner,
repo,
path: ".github/ubiquibot-config.yml",
});

// Check if the response data is a file and has a content property
if ("content" in response.data && typeof response.data.content === "string") {
// Convert the content from Base64 to string and parse the YAML content
const content = atob(response.data.content).toString();
return yaml.load(content) as UbiquiBotConfig;
} else {
try {
const response = await octokit.rest.repos.getContent({
owner,
repo,
path: ".github/ubiquibot-config.yml",
});
// Check if the response data is a file and has a content property
if ("content" in response.data && typeof response.data.content === "string") {
// Convert the content from Base64 to string and parse the YAML content
const content = atob(response.data.content).toString();
return yaml.load(content) as UbiquiBotConfig;
} else {
return null;
}
} catch (err) {
console.error(err);
return null;
}
}

0 comments on commit 3fcbd6a

Please sign in to comment.