Skip to content
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

Ping people for pull requests targeting guarded branches #513

Merged
merged 1 commit into from
Jan 23, 2025
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
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
Loading