Skip to content

Commit

Permalink
Merge pull request #1478 from argos-ci/retry-merge-commit-error
Browse files Browse the repository at this point in the history
chore: retry GitHub merge base request
  • Loading branch information
gregberge authored Dec 21, 2024
2 parents c71ba6e + f68ddef commit c14e6cf
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions apps/backend/src/build/strategy/strategies/ci/strategies/github.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { invariant } from "@argos/util/invariant";
import pRetry from "p-retry";

import {
GithubInstallation,
Expand Down Expand Up @@ -57,23 +58,28 @@ export const GithubStrategy: MergeBaseStrategy<{
return args.build.baseCommit;
}

try {
const { data } =
await args.ctx.octokit.rest.repos.compareCommitsWithBasehead({
owner: args.ctx.owner,
repo: args.ctx.repo,
basehead: `${args.base}...${args.head}`,
per_page: 1,
});
return data.merge_base_commit.sha;
} catch (error) {
// If we can't find the base commit, then we can't give a bucket
if (checkErrorStatus(404, error)) {
return null;
}
return pRetry(
async () => {
try {
const { data } =
await args.ctx.octokit.rest.repos.compareCommitsWithBasehead({
owner: args.ctx.owner,
repo: args.ctx.repo,
basehead: `${args.base}...${args.head}`,
per_page: 1,
});
return data.merge_base_commit.sha;
} catch (error) {
// If we can't find the base commit, then we can't give a bucket
if (checkErrorStatus(404, error)) {
return null;
}

throw error;
}
throw error;
}
},
{ retries: 3 },
);
},
listParentCommitShas: async (args) => {
// If the app is light, we just find the last bucket ancest on the base branch.
Expand Down

0 comments on commit c14e6cf

Please sign in to comment.