Skip to content

Commit 01c2dd5

Browse files
committed
Clarify that existing checks are exclusively about pull requests
1 parent cce2376 commit 01c2dd5

7 files changed

+63
-63
lines changed

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

+19-19
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
import jakarta.inject.Inject;
1111

12-
import org.hibernate.infra.bot.check.Check;
13-
import org.hibernate.infra.bot.check.CheckRunContext;
14-
import org.hibernate.infra.bot.check.CheckRunOutput;
15-
import org.hibernate.infra.bot.check.CheckRunRule;
12+
import org.hibernate.infra.bot.prcheck.PullRequestCheck;
13+
import org.hibernate.infra.bot.prcheck.PullRequestCheckRunContext;
14+
import org.hibernate.infra.bot.prcheck.PullRequestCheckRunOutput;
15+
import org.hibernate.infra.bot.prcheck.PullRequestCheckRunRule;
1616
import org.hibernate.infra.bot.config.DeploymentConfig;
1717
import org.hibernate.infra.bot.config.RepositoryConfig;
1818
import org.hibernate.infra.bot.util.CommitMessages;
@@ -82,14 +82,14 @@ private void checkPullRequestContributionRules(GHRepository repository, Reposito
8282
return;
8383
}
8484

85-
CheckRunContext context = new CheckRunContext( deploymentConfig, repository, repositoryConfig, pullRequest );
86-
List<Check> checks = createChecks( repositoryConfig );
87-
List<CheckRunOutput> outputs = new ArrayList<>();
88-
for ( Check check : checks ) {
89-
outputs.add( Check.run( context, check ) );
85+
PullRequestCheckRunContext context = new PullRequestCheckRunContext( deploymentConfig, repository, repositoryConfig, pullRequest );
86+
List<PullRequestCheck> checks = createChecks( repositoryConfig );
87+
List<PullRequestCheckRunOutput> outputs = new ArrayList<>();
88+
for ( PullRequestCheck check : checks ) {
89+
outputs.add( PullRequestCheck.run( context, check ) );
9090
}
9191

92-
boolean passed = outputs.stream().allMatch( CheckRunOutput::passed );
92+
boolean passed = outputs.stream().allMatch( PullRequestCheckRunOutput::passed );
9393
GHIssueComment existingComment = findExistingComment( pullRequest );
9494
// Avoid creating noisy comments for no reason, in particular if checks passed
9595
// or if the pull request was already closed.
@@ -133,8 +133,8 @@ private GHIssueComment findExistingComment(GHPullRequest pullRequest) throws IOE
133133
return null;
134134
}
135135

136-
private List<Check> createChecks(RepositoryConfig repositoryConfig) {
137-
List<Check> checks = new ArrayList<>();
136+
private List<PullRequestCheck> createChecks(RepositoryConfig repositoryConfig) {
137+
List<PullRequestCheck> checks = new ArrayList<>();
138138
checks.add( new TitleCheck() );
139139

140140
if ( repositoryConfig != null && repositoryConfig.jira != null ) {
@@ -153,14 +153,14 @@ private List<Check> createChecks(RepositoryConfig repositoryConfig) {
153153
return checks;
154154
}
155155

156-
static class TitleCheck extends Check {
156+
static class TitleCheck extends PullRequestCheck {
157157

158158
TitleCheck() {
159159
super( "Contribution — Title" );
160160
}
161161

162162
@Override
163-
public void perform(CheckRunContext context, CheckRunOutput output) {
163+
public void perform(PullRequestCheckRunContext context, PullRequestCheckRunOutput output) {
164164
String title = context.pullRequest.getTitle();
165165

166166
output.rule( "The pull request title should contain at least 2 words to describe the change properly" )
@@ -170,7 +170,7 @@ public void perform(CheckRunContext context, CheckRunOutput output) {
170170
}
171171
}
172172

173-
static class JiraIssuesCheck extends Check {
173+
static class JiraIssuesCheck extends PullRequestCheck {
174174

175175
private final Pattern issueKeyPattern;
176176

@@ -190,7 +190,7 @@ static class JiraIssuesCheck extends Check {
190190
}
191191

192192
@Override
193-
public void perform(CheckRunContext context, CheckRunOutput output) throws IOException {
193+
public void perform(PullRequestCheckRunContext context, PullRequestCheckRunOutput output) throws IOException {
194194
if ( !shouldCheckPullRequest( context ) ) {
195195
// Means we have an ignore rule configured that matches our pull request.
196196
// No need to check anything else.
@@ -214,7 +214,7 @@ public void perform(CheckRunContext context, CheckRunOutput output) throws IOExc
214214
}
215215
}
216216

217-
CheckRunRule commitRule =
217+
PullRequestCheckRunRule commitRule =
218218
output.rule( "All commit messages should start with a JIRA issue key matching pattern `"
219219
+ issueKeyPattern + "`" );
220220
if ( commitsWithMessageNotStartingWithIssueKey.isEmpty() ) {
@@ -226,7 +226,7 @@ public void perform(CheckRunContext context, CheckRunOutput output) throws IOExc
226226

227227
if ( issueLinksLimit == null || issueKeys.size() > issueLinksLimit ) {
228228
// We only need to check mentions if automatic body editing is disabled
229-
CheckRunRule pullRequestRule = output.rule(
229+
PullRequestCheckRunRule pullRequestRule = output.rule(
230230
"The PR title or body should list the keys of all JIRA issues mentioned in the commits" );
231231
List<String> issueKeysNotMentionedInPullRequest = issueKeys.stream()
232232
.filter( issueKey -> ( title == null || !title.contains( issueKey ) )
@@ -242,7 +242,7 @@ public void perform(CheckRunContext context, CheckRunOutput output) throws IOExc
242242
}
243243
}
244244

245-
private boolean shouldCheckPullRequest(CheckRunContext context) throws IOException {
245+
private boolean shouldCheckPullRequest(PullRequestCheckRunContext context) throws IOException {
246246
GHUser author = context.pullRequest.getUser();
247247
String title = context.pullRequest.getTitle();
248248
for ( RepositoryConfig.IgnoreConfiguration ignore : ignoredPRConfigurations ) {

src/main/java/org/hibernate/infra/bot/check/Check.java

-19
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.hibernate.infra.bot.prcheck;
2+
3+
import java.io.IOException;
4+
5+
public abstract class PullRequestCheck {
6+
7+
public static PullRequestCheckRunOutput run(PullRequestCheckRunContext context, PullRequestCheck check) throws IOException {
8+
PullRequestCheckRun run = PullRequestCheckRun.create( context, check );
9+
return run.perform();
10+
}
11+
12+
final String name;
13+
14+
protected PullRequestCheck(String name) {
15+
this.name = name;
16+
}
17+
18+
public abstract void perform(PullRequestCheckRunContext context, PullRequestCheckRunOutput output) throws IOException;
19+
}

src/main/java/org/hibernate/infra/bot/check/CheckRun.java renamed to src/main/java/org/hibernate/infra/bot/prcheck/PullRequestCheckRun.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.hibernate.infra.bot.check;
1+
package org.hibernate.infra.bot.prcheck;
22

33
import java.io.IOException;
44
import java.time.Instant;
@@ -10,37 +10,37 @@
1010
import org.kohsuke.github.GHCheckRun;
1111
import org.kohsuke.github.GHCheckRunBuilder;
1212

13-
public final class CheckRun {
13+
public final class PullRequestCheckRun {
1414

15-
private static final Logger LOG = Logger.getLogger( CheckRun.class );
15+
private static final Logger LOG = Logger.getLogger( PullRequestCheckRun.class );
1616

17-
static CheckRun create(CheckRunContext context, Check check) throws IOException {
17+
static PullRequestCheckRun create(PullRequestCheckRunContext context, PullRequestCheck check) throws IOException {
1818
if ( !context.deploymentConfig.isDryRun() ) {
1919
GHCheckRun checkRun = context.repository.createCheckRun(
2020
check.name, context.pullRequest.getHead().getSha() )
2121
.withStartedAt( Date.from( Instant.now() ) )
2222
.withStatus( GHCheckRun.Status.IN_PROGRESS )
2323
.create();
24-
return new CheckRun( context, check, checkRun.getId() );
24+
return new PullRequestCheckRun( context, check, checkRun.getId() );
2525
}
2626
else {
2727
LOG.info( "Pull request #" + context.pullRequest.getNumber() + " - Create check run '" + check.name + "'" );
28-
return new CheckRun( context, check, 42L );
28+
return new PullRequestCheckRun( context, check, 42L );
2929
}
3030
}
3131

32-
private final CheckRunContext context;
33-
private final Check check;
32+
private final PullRequestCheckRunContext context;
33+
private final PullRequestCheck check;
3434
public final long id;
3535

36-
CheckRun(CheckRunContext context, Check check, long id) {
36+
PullRequestCheckRun(PullRequestCheckRunContext context, PullRequestCheck check, long id) {
3737
this.context = context;
3838
this.check = check;
3939
this.id = id;
4040
}
4141

42-
CheckRunOutput perform() throws IOException {
43-
CheckRunOutput output = new CheckRunOutput( id, check.name );
42+
PullRequestCheckRunOutput perform() throws IOException {
43+
PullRequestCheckRunOutput output = new PullRequestCheckRunOutput( id, check.name );
4444

4545
try {
4646
check.perform( context, output );

src/main/java/org/hibernate/infra/bot/check/CheckRunContext.java renamed to src/main/java/org/hibernate/infra/bot/prcheck/PullRequestCheckRunContext.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
package org.hibernate.infra.bot.check;
1+
package org.hibernate.infra.bot.prcheck;
22

33
import org.hibernate.infra.bot.config.DeploymentConfig;
44
import org.hibernate.infra.bot.config.RepositoryConfig;
55

66
import org.kohsuke.github.GHPullRequest;
77
import org.kohsuke.github.GHRepository;
88

9-
public final class CheckRunContext {
9+
public final class PullRequestCheckRunContext {
1010

1111
public final DeploymentConfig deploymentConfig;
1212
public final GHRepository repository;
1313
public final GHPullRequest pullRequest;
1414
public final RepositoryConfig repositoryConfig;
1515

16-
public CheckRunContext(DeploymentConfig deploymentConfig, GHRepository repository,
16+
public PullRequestCheckRunContext(DeploymentConfig deploymentConfig, GHRepository repository,
1717
RepositoryConfig repositoryConfig, GHPullRequest pullRequest) {
1818
this.deploymentConfig = deploymentConfig;
1919
this.repository = repository;

src/main/java/org/hibernate/infra/bot/check/CheckRunOutput.java renamed to src/main/java/org/hibernate/infra/bot/prcheck/PullRequestCheckRunOutput.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
package org.hibernate.infra.bot.check;
1+
package org.hibernate.infra.bot.prcheck;
22

33
import java.util.ArrayList;
44
import java.util.List;
55

6-
public final class CheckRunOutput {
6+
public final class PullRequestCheckRunOutput {
77

88
public final long id;
99
public final String name;
1010

11-
private final List<CheckRunRule> rules = new ArrayList<>();
11+
private final List<PullRequestCheckRunRule> rules = new ArrayList<>();
1212

13-
CheckRunOutput(long id, String name) {
13+
PullRequestCheckRunOutput(long id, String name) {
1414
this.id = id;
1515
this.name = name;
1616
}
1717

18-
public CheckRunRule rule(String description) {
19-
CheckRunRule rule = new CheckRunRule( description );
18+
public PullRequestCheckRunRule rule(String description) {
19+
PullRequestCheckRunRule rule = new PullRequestCheckRunRule( description );
2020
rules.add( rule );
2121
return rule;
2222
}
@@ -26,7 +26,7 @@ public boolean passed() {
2626
}
2727

2828
public String title() {
29-
List<CheckRunRule> failingRules = rules.stream().filter( r -> !r.passed ).toList();
29+
List<PullRequestCheckRunRule> failingRules = rules.stream().filter( r -> !r.passed ).toList();
3030
if ( failingRules.isEmpty() ) {
3131
return "All rules passed";
3232
}
@@ -49,7 +49,7 @@ public void appendFailingRules(StringBuilder comment) {
4949
}
5050

5151
private void appendRules(StringBuilder comment, boolean includePassed) {
52-
for ( CheckRunRule rule : rules ) {
52+
for ( PullRequestCheckRunRule rule : rules ) {
5353
if ( rule.passed && !includePassed ) {
5454
continue;
5555
}

src/main/java/org/hibernate/infra/bot/check/CheckRunRule.java renamed to src/main/java/org/hibernate/infra/bot/prcheck/PullRequestCheckRunRule.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
package org.hibernate.infra.bot.check;
1+
package org.hibernate.infra.bot.prcheck;
22

3-
public final class CheckRunRule {
3+
public final class PullRequestCheckRunRule {
44

55
final String description;
66

77
boolean passed;
88
String commentOrNull;
99

10-
public CheckRunRule(String description) {
10+
public PullRequestCheckRunRule(String description) {
1111
this.description = description;
1212
}
1313

0 commit comments

Comments
 (0)