Skip to content

Commit 629debe

Browse files
committed
Add an option to GithubCreatePRCommand to add labels
A list of labels can be added when the PR is created
1 parent 3ab619a commit 629debe

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

cli/src/main/java/com/box/l10n/mojito/cli/command/GithubCreatePRCommand.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ public class GithubCreatePRCommand extends Command {
8383
description = "Enable auto-merge with the specified method")
8484
EnableAutoMergeType enableAutoMerge = EnableAutoMergeType.NONE;
8585

86+
@Parameter(
87+
names = {"--labels"},
88+
required = false,
89+
variableArity = true,
90+
description = "The PR labels")
91+
List<String> labels;
92+
8693
enum EnableAutoMergeType {
8794
SQUASH,
8895
MERGE,
@@ -98,12 +105,17 @@ public boolean shouldShowInCommandList() {
98105
protected void execute() throws CommandException {
99106
try {
100107

101-
GHPullRequest pr =
102-
githubClients.getClient(owner).createPR(repository, title, head, base, body, reviewers);
108+
GithubClient githubClient = githubClients.getClient(owner);
109+
110+
GHPullRequest pr = githubClient.createPR(repository, title, head, base, body, reviewers);
111+
103112
consoleWriter.a("PR created: ").fg(Ansi.Color.CYAN).a(pr.getHtmlUrl().toString()).println();
104113
if (!EnableAutoMergeType.NONE.equals(enableAutoMerge)) {
105-
githubClients.getClient(owner).enableAutoMerge(pr, GithubClient.AutoMergeType.SQUASH);
114+
githubClient.enableAutoMerge(pr, GithubClient.AutoMergeType.SQUASH);
106115
}
116+
117+
githubClient.addLabelsToPR(pr, labels);
118+
107119
} catch (GithubException e) {
108120
throw new CommandException(e);
109121
}

common/src/main/java/com/box/l10n/mojito/github/GithubClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,16 @@ public void enableAutoMerge(GHPullRequest pullRequest, AutoMergeType autoMergeTy
433433
}
434434
}
435435

436+
public void addLabelsToPR(GHPullRequest pullRequest, List<String> labels) {
437+
if (labels != null) {
438+
try {
439+
pullRequest.addLabels(labels.toArray(new String[0]));
440+
} catch (IOException e) {
441+
throw new GithubException("Can't add labels to PR", e);
442+
}
443+
}
444+
}
445+
436446
public String getOwner() {
437447
return owner;
438448
}

0 commit comments

Comments
 (0)