Skip to content

Commit

Permalink
fix: try to merge the upstream repo branch on the fork (#330)
Browse files Browse the repository at this point in the history
When forking, the forked repo is often way out of sync with its upstream repo. When using `fork`, we should attempt to sync the branch.

Fixes #335
  • Loading branch information
chingor13 authored Feb 23, 2022
1 parent 1cd08e7 commit 2d5c3f9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,28 @@ async function createPullRequest(
};
const origin: RepoDomain =
options.fork === false ? upstream : await fork(octokit, upstream);
if (options.fork) {
// try to sync the fork
await retry(
async () =>
await octokit.repos.mergeUpstream({
owner: origin.owner,
repo: origin.repo,
branch: gitHubConfigs.primary,
}),
{
retries: options.retry,
factor: 2.8411, // https://www.wolframalpha.com/input/?i=Sum%5B3000*x%5Ek%2C+%7Bk%2C+0%2C+4%7D%5D+%3D+5+*+60+*+1000
minTimeout: 3000,
randomize: false,
onRetry: (e, attempt) => {
e.message = `Error creating syncing upstream: ${e.message}`;
logger.error(e);
logger.info(`Retry attempt #${attempt}...`);
},
}
);
}
const originBranch: BranchDomain = {
...origin,
branch: gitHubConfigs.branch,
Expand Down

0 comments on commit 2d5c3f9

Please sign in to comment.