Skip to content

Commit

Permalink
fix: fix GitHub API request
Browse files Browse the repository at this point in the history
  • Loading branch information
nwtgck committed Mar 5, 2020
1 parent 0ab16ef commit 1a696fe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion backend/src/infra/DefaultGitHubApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class DefaultGitHubApiService implements GitHubApiService {
if (jsonStr === undefined) {
this.logger.info(`Repository JSON ${repoName} is not cached`);

let query = '';
const headers= (() => {
if (this.githubCredential === undefined) {
return {};
Expand All @@ -26,11 +27,12 @@ export class DefaultGitHubApiService implements GitHubApiService {
// Basic Auth
"Authorization": `Basic: ${Buffer.from(`${githubClientId}:${githubClientSecret}`).toString("base64")}`,
};
query = `?client_id=${githubClientId}&client_secret=${githubClientSecret}`;
return h;
}
})();

const githubRes = await fetch(`https://api.github.com/repos/${repoName}`, {
const githubRes = await fetch(`https://api.github.com/repos/${repoName}${query}`, {
headers,
});
if (githubRes.status !== 200) {
Expand Down
1 change: 1 addition & 0 deletions backend/src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function createServer(
const repoResult = await gitHubApiService.getRepository(`${repoName}`);

if ("status" in repoResult) {
logger.error(`GitHub API error: ${JSON.stringify(repoResult)}`);
if (repoResult.status === 404) {
res.status(404);
res.send(`${repoName} not found\n`);
Expand Down

1 comment on commit 1a696fe

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.