Skip to content

Commit a97cd3c

Browse files
committed
Back off when PR has too many commits
Skip commit iteration and fail all rules when the PR has more than 100 commits, as this likely indicates the PR targets the wrong branch. Applied to both MergeCommitsCheck and JiraIssuesCheck. Assisted-By: Claude Code <noreply@anthropic.com>
1 parent dedb4cf commit a97cd3c

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

src/main/java/org/hibernate/infra/bot/CheckPullRequestContributionRules.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,25 @@ public void perform(PullRequestCheckRunContext context, PullRequestCheckRunOutpu
196196
}
197197

198198
static class MergeCommitsCheck extends PullRequestCheck {
199+
private static final int MAX_COMMITS = 100;
199200

200201
MergeCommitsCheck() {
201202
super( "Contribution — Merge commits" );
202203
}
203204

204205
@Override
205206
public void perform(PullRequestCheckRunContext context, PullRequestCheckRunOutput output) throws IOException {
207+
String mergeCommitRuleName = "The pull request should not contain merge commits";
208+
String fixupSquashRuleName = "The pull request should not contain fixup! or squash! commits";
209+
210+
if ( context.pullRequest.getCommits() > MAX_COMMITS ) {
211+
String tooManyCommits = "Too many commits (%d) to process; the pull request is probably targeting the wrong branch."
212+
.formatted( context.pullRequest.getCommits() );
213+
output.rule( mergeCommitRuleName ).failed( tooManyCommits );
214+
output.rule( fixupSquashRuleName ).failed( tooManyCommits );
215+
return;
216+
}
217+
206218
List<String> mergeCommitShas = new ArrayList<>();
207219
List<String> fixupSquashCommitShas = new ArrayList<>();
208220
for ( GHPullRequestCommitDetail commitDetail : context.pullRequest.listCommits() ) {
@@ -215,8 +227,7 @@ public void perform(PullRequestCheckRunContext context, PullRequestCheckRunOutpu
215227
}
216228
}
217229

218-
PullRequestCheckRunRule mergeCommitRule = output.rule(
219-
"The pull request should not contain merge commits" );
230+
PullRequestCheckRunRule mergeCommitRule = output.rule( mergeCommitRuleName );
220231
if ( mergeCommitShas.isEmpty() ) {
221232
mergeCommitRule.passed();
222233
}
@@ -232,8 +243,7 @@ public void perform(PullRequestCheckRunContext context, PullRequestCheckRunOutpu
232243
);
233244
}
234245

235-
PullRequestCheckRunRule fixupSquashRule = output.rule(
236-
"The pull request should not contain fixup! or squash! commits" );
246+
PullRequestCheckRunRule fixupSquashRule = output.rule( fixupSquashRuleName );
237247
if ( fixupSquashCommitShas.isEmpty() ) {
238248
fixupSquashRule.passed();
239249
}
@@ -270,6 +280,16 @@ static class JiraIssuesCheck extends IgnorablePullRequestCheck {
270280

271281
@Override
272282
public void doPerform(PullRequestCheckRunContext context, PullRequestCheckRunOutput output) throws IOException {
283+
String commitRuleName = "All commit messages should start with a JIRA issue key matching pattern `"
284+
+ issueKeyPattern + "`";
285+
286+
if ( context.pullRequest.getCommits() > MergeCommitsCheck.MAX_COMMITS ) {
287+
output.rule( commitRuleName )
288+
.failed( "Too many commits (%d) to process; the pull request is probably targeting the wrong branch."
289+
.formatted( context.pullRequest.getCommits() ) );
290+
return;
291+
}
292+
273293
String title = context.pullRequest.getTitle();
274294
String body = context.pullRequest.getBody();
275295

@@ -287,9 +307,7 @@ public void doPerform(PullRequestCheckRunContext context, PullRequestCheckRunOut
287307
}
288308
}
289309

290-
PullRequestCheckRunRule commitRule =
291-
output.rule( "All commit messages should start with a JIRA issue key matching pattern `"
292-
+ issueKeyPattern + "`" );
310+
PullRequestCheckRunRule commitRule = output.rule( commitRuleName );
293311
if ( commitsWithMessageNotStartingWithIssueKey.isEmpty() ) {
294312
commitRule.passed();
295313
}

0 commit comments

Comments
 (0)