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

chore: auto close pr if opened from fork's main branch #27627

Merged
merged 5 commits into from
Oct 20, 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
29 changes: 20 additions & 9 deletions tools/@aws-cdk/prlint/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,26 @@ export class PullRequestLinter {
body,
});

// Commenting this code to first test that linter rule works
// since this can lead to other PRs closing if not setup correctly
// // Closing the PR if it is opened from main branch of author's fork
// if (failureMessages.includes(PR_FROM_MAIN_ERROR)) {
// await this.client.pulls.update({
// ...this.prParams,
// state: 'closed',
// });
// }
// Closing the PR if it is opened from main branch of author's fork
if (failureMessages.includes(PR_FROM_MAIN_ERROR)) {

const errorMessageBody = 'Your pull request must be based off of a branch in a personal account '
+ '(not an organization owned account, and not the main branch). You must also have the setting '
+ 'enabled that <a href="https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork">allows the CDK team to push changes to your branch</a> '
+ '(this setting is enabled by default for personal accounts, and cannot be enabled for organization owned accounts). '
+ 'The reason for this is that our automation needs to synchronize your branch with our main after it has been approved, '
+ 'and we cannot do that if we cannot push to your branch.'

await this.client.issues.createComment({
...this.issueParams,
body: errorMessageBody,
});

await this.client.pulls.update({
...this.prParams,
state: 'closed',
});
}

throw new LinterError(body);
}
Expand Down
2 changes: 2 additions & 0 deletions tools/@aws-cdk/prlint/test/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,8 @@ function configureMock(pr: Subset<linter.GitHubPr>, prFiles?: linter.GitHubFile[
listReviews: mockListReviews,

dismissReview() {},

update() {},
};

const issuesClient = {
Expand Down
Loading