From 08e67483892fa168252e017260f7e2e03a3ac39b Mon Sep 17 00:00:00 2001 From: Jan Baraniewski Date: Mon, 24 Jul 2023 17:52:16 +0200 Subject: [PATCH] Update custom PR name --- cmd/issuectl/pr.go | 12 ++++++++---- pkg/issue.go | 10 ++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cmd/issuectl/pr.go b/cmd/issuectl/pr.go index 8beac16..882749c 100644 --- a/cmd/issuectl/pr.go +++ b/cmd/issuectl/pr.go @@ -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 } diff --git a/pkg/issue.go b/pkg/issue.go index 68d4e17..61eab58 100644 --- a/pkg/issue.go +++ b/pkg/issue.go @@ -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") @@ -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, @@ -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,