Skip to content

Commit

Permalink
Add an option to GithubCreatePRCommand to add labels
Browse files Browse the repository at this point in the history
A list of labels can be added when the PR is created
  • Loading branch information
ja-openai committed Sep 23, 2024
1 parent 3ab619a commit 629debe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ public class GithubCreatePRCommand extends Command {
description = "Enable auto-merge with the specified method")
EnableAutoMergeType enableAutoMerge = EnableAutoMergeType.NONE;

@Parameter(
names = {"--labels"},
required = false,
variableArity = true,
description = "The PR labels")
List<String> labels;

enum EnableAutoMergeType {
SQUASH,
MERGE,
Expand All @@ -98,12 +105,17 @@ public boolean shouldShowInCommandList() {
protected void execute() throws CommandException {
try {

GHPullRequest pr =
githubClients.getClient(owner).createPR(repository, title, head, base, body, reviewers);
GithubClient githubClient = githubClients.getClient(owner);

GHPullRequest pr = githubClient.createPR(repository, title, head, base, body, reviewers);

consoleWriter.a("PR created: ").fg(Ansi.Color.CYAN).a(pr.getHtmlUrl().toString()).println();
if (!EnableAutoMergeType.NONE.equals(enableAutoMerge)) {
githubClients.getClient(owner).enableAutoMerge(pr, GithubClient.AutoMergeType.SQUASH);
githubClient.enableAutoMerge(pr, GithubClient.AutoMergeType.SQUASH);
}

githubClient.addLabelsToPR(pr, labels);

} catch (GithubException e) {
throw new CommandException(e);
}
Expand Down
10 changes: 10 additions & 0 deletions common/src/main/java/com/box/l10n/mojito/github/GithubClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,16 @@ public void enableAutoMerge(GHPullRequest pullRequest, AutoMergeType autoMergeTy
}
}

public void addLabelsToPR(GHPullRequest pullRequest, List<String> labels) {
if (labels != null) {
try {
pullRequest.addLabels(labels.toArray(new String[0]));
} catch (IOException e) {
throw new GithubException("Can't add labels to PR", e);
}
}
}

public String getOwner() {
return owner;
}
Expand Down

0 comments on commit 629debe

Please sign in to comment.