Skip to content

Attach Develocity build scans to GitHub Checks #227

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

Merged
merged 2 commits into from
Mar 21, 2024
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
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Specifically, most of the GitHub-related features in this bot are powered by

## Features

### Pull request checking

This bot checks various contribution rules on pull requests submitted to Hibernate projects on GitHub,
and notifies the pull request authors of any change they need to work on.

Expand All @@ -21,9 +23,16 @@ This includes:
* Proper formatting of commits: every commit message must start with the key of a JIRA ticket.
* Etc.

The bot can also be configured to automatically add links to JIRA issues in PR descriptions. When this is enabled
### Jira link insertion

Optionally, the bot can be configured to automatically add links to JIRA issues in PR descriptions. When this is enabled
links to JIRA tickets will be appended at the bottom of the PR body.

### Develocity build scan extraction

Optionally, the bot can be configured to automatically create a GitHub check listing Develocity build scans
for every commit that has completed checks related to CI (GitHub Actions or Jenkins).

## Configuration

### Enabling the bot in a new repository
Expand All @@ -33,7 +42,7 @@ You will need admin rights in the Hibernate organization.
Go to [the installed application settings](https://github.com/organizations/hibernate/settings/installations/15390286)
and add your repository under "Repository access".

If you wish to enable the JIRA-related features as well,
If you wish to enable the JIRA-related or Develocity-related features as well,
create the file `.github/hibernate-github-bot.yml` in default branch of your repository,
with the following content:

Expand Down Expand Up @@ -62,6 +71,11 @@ jira:
# Ignore all paths matching a given pattern
- "*/Jenkinsfile"
- "*.Jenkinsfile"
develocity:
buildScan:
# To have the bot create a GitHub check listing Develocity build scans
# for every commit that has completed checks related to CI (GitHub Actions or Jenkins)
addCheck: true
```

### Altering the infrastructure
Expand Down
12 changes: 10 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus-github-app.version>2.3.3</quarkus-github-app.version>
<quarkus-openapi-generator.version>2.4.1</quarkus-openapi-generator.version>
<!-- Using a single property for both plugin and platform, so that GitHub's Dependabot doesn't get confused -->
<quarkus.version>3.8.3</quarkus.version>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
Expand Down Expand Up @@ -91,6 +92,15 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-cache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.openapi.generator</groupId>
<artifactId>quarkus-openapi-generator</artifactId>
<version>${quarkus-openapi-generator.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-jackson</artifactId>
</dependency>
<dependency>
<groupId>com.hrakaroo</groupId>
<artifactId>glob</artifactId>
Expand All @@ -115,8 +125,6 @@
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<extensions>true</extensions>
<configuration>
</configuration>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

import jakarta.inject.Inject;

import org.hibernate.infra.bot.check.Check;
import org.hibernate.infra.bot.check.CheckRunContext;
import org.hibernate.infra.bot.check.CheckRunOutput;
import org.hibernate.infra.bot.check.CheckRunRule;
import org.hibernate.infra.bot.prcheck.PullRequestCheck;
import org.hibernate.infra.bot.prcheck.PullRequestCheckRunContext;
import org.hibernate.infra.bot.prcheck.PullRequestCheckRunOutput;
import org.hibernate.infra.bot.prcheck.PullRequestCheckRunRule;
import org.hibernate.infra.bot.config.DeploymentConfig;
import org.hibernate.infra.bot.config.RepositoryConfig;
import org.hibernate.infra.bot.util.CommitMessages;
Expand Down Expand Up @@ -82,14 +82,14 @@ private void checkPullRequestContributionRules(GHRepository repository, Reposito
return;
}

CheckRunContext context = new CheckRunContext( deploymentConfig, repository, repositoryConfig, pullRequest );
List<Check> checks = createChecks( repositoryConfig );
List<CheckRunOutput> outputs = new ArrayList<>();
for ( Check check : checks ) {
outputs.add( Check.run( context, check ) );
PullRequestCheckRunContext context = new PullRequestCheckRunContext( deploymentConfig, repository, repositoryConfig, pullRequest );
List<PullRequestCheck> checks = createChecks( repositoryConfig );
List<PullRequestCheckRunOutput> outputs = new ArrayList<>();
for ( PullRequestCheck check : checks ) {
outputs.add( PullRequestCheck.run( context, check ) );
}

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

private List<Check> createChecks(RepositoryConfig repositoryConfig) {
List<Check> checks = new ArrayList<>();
private List<PullRequestCheck> createChecks(RepositoryConfig repositoryConfig) {
List<PullRequestCheck> checks = new ArrayList<>();
checks.add( new TitleCheck() );

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

static class TitleCheck extends Check {
static class TitleCheck extends PullRequestCheck {

TitleCheck() {
super( "Contribution — Title" );
}

@Override
public void perform(CheckRunContext context, CheckRunOutput output) {
public void perform(PullRequestCheckRunContext context, PullRequestCheckRunOutput output) {
String title = context.pullRequest.getTitle();

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

static class JiraIssuesCheck extends Check {
static class JiraIssuesCheck extends PullRequestCheck {

private final Pattern issueKeyPattern;

Expand All @@ -190,7 +190,7 @@ static class JiraIssuesCheck extends Check {
}

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

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

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

private boolean shouldCheckPullRequest(CheckRunContext context) throws IOException {
private boolean shouldCheckPullRequest(PullRequestCheckRunContext context) throws IOException {
GHUser author = context.pullRequest.getUser();
String title = context.pullRequest.getTitle();
for ( RepositoryConfig.IgnoreConfiguration ignore : ignoredPRConfigurations ) {
Expand Down
Loading