Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cascading): add support for multi repositories with more than 10… #548

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions apps/github-cascading-app/src/cascading/cascading-probot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +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,
// eslint-disable-next-line @typescript-eslint/naming-convention, camelcase
per_page: 100
});
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,11 +375,12 @@ 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);
cascadingBranch = conflictCascadingBranch;
}
}
await this.createPullRequestWithMessage(cascadingBranch, currentBranch.branch, targetBranch.branch, config);
await this.createPullRequestWithMessage(cascadingBranch, currentBranch.branch, targetBranch.branch, config, isConflicting);
}

/**
Expand Down