Skip to content

Commit

Permalink
feat(cascading): add support for multi repositories with more than 10…
Browse files Browse the repository at this point in the history
…0 branches
  • Loading branch information
kpanot committed Jul 19, 2023
1 parent 7f1d3a7 commit 40c88e4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
18 changes: 16 additions & 2 deletions apps/github-cascading-app/src/cascading/cascading-probot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,22 @@ export class CascadingProbot extends Cascading {
/** @inheritdoc */
protected async getBranches() {
this.logger.debug('List remote branches');
const res = await this.options.octokit.repos.listBranches(this.options.repo);
return res.data.map(({name}) => name);
/* eslint-disable camelcase, @typescript-eslint/naming-convention */
const per_page = 100;
let pageIndex = 1;
let getCurrentPage = true;
const branchNames: string[] = [];
while (getCurrentPage && pageIndex <= 20) {
const res = await this.options.octokit.repos.listBranches({
...this.options.repo,
per_page,
page: pageIndex++
});
branchNames.push(...res.data.map(({ name }) => name));
getCurrentPage = res.data.length === per_page;
}
return branchNames;
/* eslint-enable camelcase, @typescript-eslint/naming-convention */
}

/** @inheritdoc */
Expand Down
6 changes: 5 additions & 1 deletion apps/github-cascading-app/src/cascading/cascading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export abstract class Cascading {
const openPr = await this.findOpenPullRequest(cascadingBranch, targetBranch);

if (!openPr) {
this.logger.debug(`Will recreate the branch ${cascadingBranch}`);
try {
await this.deleteBranch(cascadingBranch);
await this.createBranch(cascadingBranch, currentBranch);
Expand All @@ -263,6 +264,7 @@ export abstract class Cascading {
}
return this.createPullRequestWithMessage(cascadingBranch, currentBranch, targetBranch, config, true);
} else {
this.logger.debug(`Updating the PR ${openPr.id}`);
const message = await this.generatePullRequestBody({
...(openPr.context || { bypassReviewers: config.bypassReviewers, currentBranch, targetBranch, isConflicting: false}),
bypassReviewers: false
Expand Down Expand Up @@ -352,6 +354,7 @@ export abstract class Cascading {
return;
}

let isConflicting = false;
if (branches.includes(cascadingBranch)) {
try {
await this.merge(currentBranch.branch, cascadingBranch);
Expand All @@ -372,10 +375,11 @@ export abstract class Cascading {
this.logger.warn(`Fail to remove the cascading branch "${cascadingBranch}"`);
}
const conflictCascadingBranch = this.determineCascadingBranchName(currentBranch.semver?.format() || currentBranch.branch, targetBranch.semver?.format() || targetBranch.branch, true);
isConflicting = true;
await this.createBranch(conflictCascadingBranch, currentBranch.branch);
}
}
await this.createPullRequestWithMessage(cascadingBranch, currentBranch.branch, targetBranch.branch, config);
await this.createPullRequestWithMessage(cascadingBranch, currentBranch.branch, targetBranch.branch, config, isConflicting);
}

/**
Expand Down

0 comments on commit 40c88e4

Please sign in to comment.