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

Affect triage/needs-rebase on Pull Requests with merge conflicts #232

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ The bot will automatically remove these labels when they are outdated:

The bot enforces a specific color for any label created that starts with `area/` so that all these labels are consistent.

=== Include `triage/needs-rebase` on unmergeable pull-requests

Pull requests may require a rebase when conflicts appear. The bot adds a `triage/needs-rebase` label on pull requests that cannot be merged and removes it when the pull request is in a mergeable state again.


== Contributing

To participate to the development of this GitHub App, create a playground project in your own org and
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.quarkus.bot;

import io.quarkiverse.githubapp.event.PullRequest;
import io.quarkiverse.githubapp.event.Push;
import io.quarkus.bot.util.Labels;
import org.kohsuke.github.GHEventPayload;
import org.kohsuke.github.GHIssueState;
import org.kohsuke.github.GHPullRequest;
import org.kohsuke.github.GHRepository;

import java.io.IOException;

public class AffectNeedsRebaseToOpenedPullRequests {

/**
* Affect triage/needs-rebase label on pull request events
*/
void triageNeedsRebaseOnPullRequest(
@PullRequest.Opened @PullRequest.Reopened @PullRequest.Synchronize GHEventPayload.PullRequest pullRequestPayload)
throws IOException {
affectNeedsRebaseLabel(pullRequestPayload.getPullRequest());
}

void triageNeedsRebaseOnRepositoryPush(@Push GHEventPayload.Push pushRequestPayload) throws IOException {
GHRepository repository = pushRequestPayload.getRepository();
String defaultBranch = repository.getDefaultBranch();
for (GHPullRequest pullRequest : repository.getPullRequests(GHIssueState.OPEN)) {
if (!defaultBranch.equals(pullRequest.getBase().getRef())) {
continue;
}
affectNeedsRebaseLabel(pullRequest);
}
}

private void affectNeedsRebaseLabel(GHPullRequest pullRequest) throws IOException {
Boolean mergeable = pullRequest.getMergeable();
boolean hasNeedsRebaseLabel = pullRequest.getLabels().stream()
.anyMatch(label -> Labels.TRIAGE_NEEDS_REBASE.equals(label.getName()));
if (mergeable != null) {
if (mergeable) {
if (hasNeedsRebaseLabel) {
pullRequest.removeLabels(Labels.TRIAGE_NEEDS_REBASE);
gastaldi marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
if (!hasNeedsRebaseLabel) {
pullRequest.addLabels(Labels.TRIAGE_NEEDS_REBASE);
}
}
}
}
}
1 change: 1 addition & 0 deletions src/main/java/io/quarkus/bot/util/Labels.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Labels {
public static final String AREA_PREFIX = "area/";
public static final String AREA_INFRA = "area/infra";
public static final String TRIAGE_INVALID = "triage/invalid";
public static final String TRIAGE_NEEDS_REBASE = "triage/needs-rebase";
public static final String TRIAGE_NEEDS_TRIAGE = "triage/needs-triage";
public static final String TRIAGE_WAITING_FOR_CI = "triage/waiting-for-ci";
public static final String TRIAGE_QE = "triage/qe?";
Expand Down