-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to create pull request in Github
This is exploratory to see if we can avoid having to install the GH CLI or make curl command
- Loading branch information
Showing
3 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
cli/src/main/java/com/box/l10n/mojito/cli/command/GithubCreatePRCommand.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,95 @@ | ||
package com.box.l10n.mojito.cli.command; | ||
|
||
import com.beust.jcommander.Parameter; | ||
import com.beust.jcommander.Parameters; | ||
import com.box.l10n.mojito.cli.console.ConsoleWriter; | ||
import com.box.l10n.mojito.github.GithubClients; | ||
import com.box.l10n.mojito.github.GithubException; | ||
import java.util.List; | ||
import org.fusesource.jansi.Ansi; | ||
import org.kohsuke.github.GHPullRequest; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.context.annotation.Scope; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Scope("prototype") | ||
@Parameters( | ||
commandNames = {"github-pr-create"}, | ||
commandDescription = "Create a Github PR") | ||
public class GithubCreatePRCommand extends Command { | ||
|
||
@Autowired GithubClients githubClients; | ||
|
||
@Qualifier("ansiCodeEnabledFalse") | ||
@Autowired | ||
ConsoleWriter consoleWriter; | ||
|
||
@Parameter( | ||
names = {"--owner", "-o"}, | ||
required = true, | ||
arity = 1, | ||
description = "The Github repository owner") | ||
String owner; | ||
|
||
@Parameter( | ||
names = {"--repository", "-r"}, | ||
required = true, | ||
arity = 1, | ||
description = "The Github repository name") | ||
String repository; | ||
|
||
@Parameter( | ||
names = {"--title"}, | ||
required = true, | ||
arity = 1, | ||
description = "The PR title") | ||
String title; | ||
|
||
@Parameter( | ||
names = {"--head"}, | ||
required = true, | ||
arity = 1, | ||
description = "The PR head") | ||
String head; | ||
|
||
@Parameter( | ||
names = {"--base"}, | ||
required = true, | ||
arity = 1, | ||
description = "The PR base") | ||
String base; | ||
|
||
@Parameter( | ||
names = {"--body"}, | ||
required = false, | ||
arity = 1, | ||
description = "The PR body") | ||
String body; | ||
|
||
@Parameter( | ||
names = {"--reviewers"}, | ||
required = false, | ||
variableArity = true, | ||
description = "The PR reviewers") | ||
List<String> reviewers; | ||
|
||
@Override | ||
public boolean shouldShowInCommandList() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected void execute() throws CommandException { | ||
try { | ||
|
||
GHPullRequest pr = | ||
githubClients.getClient(owner).createPR(repository, title, head, base, body, reviewers); | ||
|
||
consoleWriter.a("PR created: ").fg(Ansi.Color.CYAN).a(pr.getHtmlUrl().toString()).println(); | ||
} catch (GithubException e) { | ||
throw new CommandException(e); | ||
} | ||
} | ||
} |
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
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