Skip to content

Commit

Permalink
Update custom PR name
Browse files Browse the repository at this point in the history
  • Loading branch information
janekbaraniewski committed Jul 24, 2023
1 parent 37612c2 commit 08e6748
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 8 additions & 4 deletions cmd/issuectl/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,26 @@ func getIssueIDFromParentDirectory(config issuectl.IssuectlConfig) string {

func initOpenPullRequestCommand(rootCmd *cobra.Command) {
openPRCmd := &cobra.Command{
Use: "openpr [issue number]",
Short: "Opens a pull request for the specified issue",
Long: `This command opens a pull request for the specified issue on GitHub`, // FIXME: Github?? // it requires exactly one argument
Use: "openpr [issue number] [pr title]",
Short: "Opens a pull request for the specified issue. You can specify title, if left empty default title will be generated from issue title",
Long: `This command opens a pull request for the specified issue in Repository Backend`, // FIXME: Github?? // it requires exactly one argument
RunE: func(cmd *cobra.Command, args []string) error {
config := issuectl.LoadConfig()
var issueID string
var customTitle string
if len(args) == 1 {
issueID = args[0]
} else if len(args) == 0 {
// check if can detect issue from pwd
issueID = getIssueIDFromParentDirectory(config)
} else if len(args) == 2 {
issueID = args[0]
customTitle = args[1]
}
if issueID == "" {
return errors.New("Missing issueID")
}
err := issuectl.OpenPullRequest(issuectl.IssueID(issueID))
err := issuectl.OpenPullRequest(issuectl.IssueID(issueID), customTitle)
if err != nil {
return err
}
Expand Down
10 changes: 8 additions & 2 deletions pkg/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ func AddRepoToIssue(repoName string, issueID IssueID) error {
}

// OpenPullRequest opens pull request
func OpenPullRequest(issueID IssueID) error {
func OpenPullRequest(issueID IssueID, customTitle string) error {
config := LoadConfig()

issue, found := config.GetIssue(issueID)
if !found {
return errors.New("Issue not found")
Expand All @@ -244,6 +245,11 @@ func OpenPullRequest(issueID IssueID) error {

repo := config.GetRepository(profile.DefaultRepository)

title := customTitle
if title == "" {
title = fmt.Sprintf("%v | %v", issue.ID, issue.Name)
}

Log.Infofp("📂", "Opening PR for issue %v in %v/%v [%v]",
issueID,
repo.Owner,
Expand All @@ -254,7 +260,7 @@ func OpenPullRequest(issueID IssueID) error {
prId, err := repoBackend.OpenPullRequest(
repo.Owner,
repo.Name,
fmt.Sprintf("%v | %v", issue.ID, issue.Name),
title,
fmt.Sprintf("Resolves #%v ✅", issue.ID),
"master", // TODO: make configurable
issue.BranchName,
Expand Down

0 comments on commit 08e6748

Please sign in to comment.