Skip to content

Commit

Permalink
Merge pull request #513 from gsmet/guarded-branch
Browse files Browse the repository at this point in the history
Ping people for pull requests targeting guarded branches
  • Loading branch information
gsmet authored Jan 23, 2025
2 parents 0862d16 + f9d3238 commit 42df558
Show file tree
Hide file tree
Showing 4 changed files with 515 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/main/java/io/quarkus/bot/TriagePullRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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.config.QuarkusGitHubBotConfigFile.TriageRule;
import io.quarkus.bot.util.GHIssues;
import io.quarkus.bot.util.Mentions;
Expand Down Expand Up @@ -48,10 +49,6 @@ void triagePullRequest(
return;
}

if (quarkusBotConfigFile.triage.rules.isEmpty()) {
return;
}

GHPullRequest pullRequest = pullRequestPayload.getPullRequest();
Set<String> labels = new TreeSet<>();
Mentions mentions = new Mentions();
Expand All @@ -78,20 +75,32 @@ void triagePullRequest(
}
}

// remove from the set the labels already present on the pull request
pullRequest.getLabels().stream().map(GHLabel::getName).forEach(labels::remove);
for (GuardedBranch guardedBranch : quarkusBotConfigFile.triage.guardedBranches) {
if (guardedBranch.ref.equals(pullRequest.getBase().getRef())) {
for (String mention : guardedBranch.notify) {
mentions.add(mention, guardedBranch.ref);
}
}
}

// remove from the set the labels already present on the pull request
if (!labels.isEmpty()) {
if (!quarkusBotConfig.isDryRun()) {
pullRequest.addLabels(limit(labels).toArray(new String[0]));
} else {
LOG.info("Pull Request #" + pullRequest.getNumber() + " - Add labels: " + String.join(", ", limit(labels)));
pullRequest.getLabels().stream().map(GHLabel::getName).forEach(labels::remove);

if (!labels.isEmpty()) {
if (!quarkusBotConfig.isDryRun()) {
pullRequest.addLabels(limit(labels).toArray(new String[0]));
} else {
LOG.info("Pull Request #" + pullRequest.getNumber() + " - Add labels: " + String.join(", ", limit(labels)));
}
}
}

mentions.removeAlreadyParticipating(GHIssues.getParticipatingUsers(pullRequest, gitHubGraphQLClient));
if (!mentions.isEmpty()) {
comments.add("/cc " + mentions.getMentionsString());
mentions.removeAlreadyParticipating(GHIssues.getParticipatingUsers(pullRequest, gitHubGraphQLClient));
if (!mentions.isEmpty()) {
comments.add("/cc " + mentions.getMentionsString());
}
}

for (String comment : comments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public static class TriageConfig {

public List<TriageRule> rules = new ArrayList<>();

public List<GuardedBranch> guardedBranches = new ArrayList<>();

public QE qe = new QE();

public Discussions discussions = new Discussions();
Expand Down Expand Up @@ -149,6 +151,14 @@ public static class Develocity {
public String url;
}

public static class GuardedBranch {

public String ref;

@JsonDeserialize(as = TreeSet.class)
public Set<String> notify = new TreeSet<>();
}

boolean isFeatureEnabled(Feature feature) {
return features.contains(Feature.ALL) || features.contains(feature);
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/io/quarkus/bot/it/PullRequestOpenedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,23 @@ void triageIdNotify() throws IOException {
});
}

@Test
void triageGuardedBranches() throws IOException {
given().github(mocks -> mocks.configFile("quarkus-github-bot.yml")
.fromString("features: [ TRIAGE_ISSUES_AND_PULL_REQUESTS ]\n"
+ "triage:\n"
+ " guardedBranches:\n"
+ " - ref: 3.15\n"
+ " notify: [jmartisk,gsmet]\n"))
.when().payloadFromClasspath("/pullrequest-opened-guarded-branch.json")
.event(GHEvent.PULL_REQUEST)
.then().github(mocks -> {
verify(mocks.pullRequest(527350930))
.comment("/cc @gsmet (3.15), @jmartisk (3.15)");
verifyNoMoreInteractions(mocks.ghObjects());
});
}

@Test
void descriptionMissingForSmallDocChange() throws IOException {
given()
Expand Down
Loading

0 comments on commit 42df558

Please sign in to comment.