-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #516 from gsmet/split-guarded-branches
Split guarded branches handling.
- Loading branch information
Showing
2 changed files
with
76 additions
and
21 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/main/java/io/quarkus/bot/PullRequestGuardedBranches.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package io.quarkus.bot; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.logging.Logger; | ||
import org.kohsuke.github.GHEventPayload; | ||
import org.kohsuke.github.GHPullRequest; | ||
|
||
import io.quarkiverse.githubapp.ConfigFile; | ||
import io.quarkiverse.githubapp.event.PullRequest; | ||
import io.quarkus.bot.config.Feature; | ||
import io.quarkus.bot.config.QuarkusGitHubBotConfig; | ||
import io.quarkus.bot.config.QuarkusGitHubBotConfigFile; | ||
import io.quarkus.bot.config.QuarkusGitHubBotConfigFile.GuardedBranch; | ||
import io.quarkus.bot.util.GHIssues; | ||
import io.quarkus.bot.util.Mentions; | ||
import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient; | ||
|
||
class PullRequestGuardedBranches { | ||
|
||
private static final Logger LOG = Logger.getLogger(PullRequestGuardedBranches.class); | ||
|
||
@Inject | ||
QuarkusGitHubBotConfig quarkusBotConfig; | ||
|
||
void triagePullRequest( | ||
@PullRequest.Opened GHEventPayload.PullRequest pullRequestPayload, | ||
@ConfigFile("quarkus-github-bot.yml") QuarkusGitHubBotConfigFile quarkusBotConfigFile, | ||
DynamicGraphQLClient gitHubGraphQLClient) throws IOException { | ||
if (!Feature.TRIAGE_ISSUES_AND_PULL_REQUESTS.isEnabled(quarkusBotConfigFile)) { | ||
return; | ||
} | ||
|
||
GHPullRequest pullRequest = pullRequestPayload.getPullRequest(); | ||
Mentions mentions = new Mentions(); | ||
|
||
for (GuardedBranch guardedBranch : quarkusBotConfigFile.triage.guardedBranches) { | ||
if (guardedBranch.ref.equals(pullRequest.getBase().getRef())) { | ||
for (String mention : guardedBranch.notify) { | ||
mentions.add(mention, guardedBranch.ref); | ||
} | ||
} | ||
} | ||
|
||
if (mentions.isEmpty()) { | ||
return; | ||
} | ||
|
||
mentions.removeAlreadyParticipating(GHIssues.getParticipatingUsers(pullRequest, gitHubGraphQLClient)); | ||
|
||
if (mentions.isEmpty()) { | ||
return; | ||
} | ||
|
||
String comment = "/cc " + mentions.getMentionsString(); | ||
if (!quarkusBotConfig.isDryRun()) { | ||
pullRequest.comment(comment); | ||
} else { | ||
LOG.info("Pull Request #" + pullRequest.getNumber() + " - Add comment: " + comment); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters