-
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.
Affect
triage/needs-rebase
on Pull Requests with merge conflicts
This adds the `triage/needs-rebase` label (or removes it) on opened pull-requests, making it easier to find pull-requests that require a rebase to be merged Apply suggestions from code review Co-authored-by: Guillaume Smet <[email protected]>
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
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
51 changes: 51 additions & 0 deletions
51
src/main/java/io/quarkus/bot/AffectNeedsRebaseToOpenedPullRequests.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,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); | ||
} | ||
} else { | ||
if (!hasNeedsRebaseLabel) { | ||
pullRequest.addLabels(Labels.TRIAGE_NEEDS_REBASE); | ||
} | ||
} | ||
} | ||
} | ||
} |
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