-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8bff53
commit ecb77f0
Showing
3 changed files
with
64 additions
and
1 deletion.
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
44 changes: 44 additions & 0 deletions
44
src/main/java/net/neoforged/automation/webhook/label/BlockPRHandler.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,44 @@ | ||
package net.neoforged.automation.webhook.label; | ||
|
||
import org.kohsuke.github.GHCheckRun; | ||
import org.kohsuke.github.GHCheckRunBuilder; | ||
import org.kohsuke.github.GHIssue; | ||
import org.kohsuke.github.GHLabel; | ||
import org.kohsuke.github.GHPullRequest; | ||
import org.kohsuke.github.GHUser; | ||
import org.kohsuke.github.GitHub; | ||
|
||
public record BlockPRHandler() implements LabelHandler { | ||
private static final String NAME = "PR Block"; | ||
|
||
@Override | ||
public void onLabelAdded(GitHub gitHub, GHUser actor, GHIssue issue, GHLabel label) throws Exception { | ||
if (issue.getPullRequest() != null) { | ||
block(issue.getRepository().getPullRequest(issue.getNumber())); | ||
} | ||
} | ||
|
||
@Override | ||
public void onLabelRemoved(GitHub gitHub, GHUser actor, GHIssue issue, GHLabel label) throws Exception { | ||
if (issue.getPullRequest() != null) { | ||
var pr = issue.getRepository().getPullRequest(issue.getNumber()); | ||
issue.getRepository() | ||
.createCheckRun(NAME, pr.getHead().getSha()) | ||
.withConclusion(GHCheckRun.Conclusion.SUCCESS) | ||
.add(new GHCheckRunBuilder.Output("PR block label removed", "PR block label removed")) | ||
.create(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onSynchronized(GitHub gitHub, GHPullRequest pullRequest, GHLabel label) throws Exception { | ||
block(pullRequest); | ||
} | ||
|
||
private void block(GHPullRequest pr) throws Exception { | ||
pr.getRepository().createCheckRun(NAME, pr.getHead().getSha()) | ||
.withConclusion(GHCheckRun.Conclusion.FAILURE) | ||
.add(new GHCheckRunBuilder.Output("PR blocked as requested through label", "PR blocked")) | ||
.create(); | ||
} | ||
} |
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