From 64fffd2cf161e809ae8e5af923c18162ae437738 Mon Sep 17 00:00:00 2001 From: Alisher Nurmanov Date: Fri, 3 Oct 2025 12:17:50 +0500 Subject: [PATCH] qs: Jira-related PR should have format like [AIR-123] {text} --- gitcmds/gitcmds.go | 12 +++++++++--- gitcmds/pr.go | 6 +++--- internal/jira/jira.go | 36 ++++++++++++++++++++---------------- internal/systrun/types.go | 16 +++------------- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/gitcmds/gitcmds.go b/gitcmds/gitcmds.go index e7b2afd..03ce5bb 100644 --- a/gitcmds/gitcmds.go +++ b/gitcmds/gitcmds.go @@ -3060,7 +3060,7 @@ func printLn(stdout string) { } } -func getIssueDescription(notes []string) (string, error) { +func GetIssueDescription(notes []string) (string, error) { var ( description string err error @@ -3077,9 +3077,15 @@ func getIssueDescription(notes []string) (string, error) { switch { case len(notesObj.GithubIssueURL) > 0: - description, err = GetIssueDescription(notesObj.GithubIssueURL) + description, err = GetGitHubIssueDescription(notesObj.GithubIssueURL) case len(notesObj.JiraTicketURL) > 0: - description, err = jira.GetJiraIssueName(notesObj.JiraTicketURL, "") + var jiraTicketID string + description, jiraTicketID, err = jira.GetJiraIssueName(notesObj.JiraTicketURL, "") + if err != nil { + return "", err + } + + description = "[" + jiraTicketID + "] " + description } if err != nil { return "", fmt.Errorf("error retrieving issue description: %w", err) diff --git a/gitcmds/pr.go b/gitcmds/pr.go index 59fd8e3..82f69e0 100644 --- a/gitcmds/pr.go +++ b/gitcmds/pr.go @@ -55,7 +55,7 @@ func Pr(wd string, needDraft bool) error { return err } - issueDescription, err := getIssueDescription(notes) + issueDescription, err := GetIssueDescription(notes) if err != nil { return err } @@ -526,8 +526,8 @@ func createPRBranch(wd, devBranchName, issueDescription string) (string, error) return prBranchName, nil } -// GetIssueDescription retrieves the title and body of a GitHub issue from its URL. -func GetIssueDescription(issueURL string) (string, error) { +// GetGitHubIssueDescription retrieves the title and body of a GitHub issue from its URL. +func GetGitHubIssueDescription(issueURL string) (string, error) { // Extract issue number from URL parts := strings.Split(issueURL, "/") if len(parts) < 1 { diff --git a/internal/jira/jira.go b/internal/jira/jira.go index cb28f12..b03b21c 100644 --- a/internal/jira/jira.go +++ b/internal/jira/jira.go @@ -44,7 +44,7 @@ func GetJiraBranchName(args ...string) (branch string, comments []string, err er jiraTicketID, ok := GetJiraTicketIDFromArgs(arg) if ok { var brName string - issueName, err := GetJiraIssueName("", jiraTicketID) + issueName, _, err := GetJiraIssueName("", jiraTicketID) if err != nil { return "", nil, err } @@ -82,13 +82,13 @@ func GetJiraBranchName(args ...string) (branch string, comments []string, err er // parameters: // - ticketURL: The URL of the JIRA ticket (optional). // - ticketID: The ID of the JIRA ticket (optional). -func GetJiraIssueName(ticketURL, ticketID string) (name string, err error) { +func GetJiraIssueName(ticketURL, ticketID string) (string, string, error) { // Validate the issue key if ticketID == "" { var ok bool ticketID, ok = GetJiraTicketIDFromArgs(ticketURL) if !ok { - return "", errors.New("error: ticketID or ticketURL is required") + return "", ticketID, errors.New("error: ticketID or ticketURL is required") } } @@ -101,18 +101,22 @@ func GetJiraIssueName(ticketURL, ticketID string) (name string, err error) { fmt.Println(" https://id.atlassian.com/manage-profile/security/api-tokens ") fmt.Println("--------------------------------------------------------------------------------") - return "", errors.New("error: JIRA API token not found") + return "", ticketID, errors.New("error: JIRA API token not found") } - var email string + var ( + email string + err error + ) + email = os.Getenv("JIRA_EMAIL") if email == "" { email, err = helper.GetUserEmail() // Replace with your email - } - if err != nil { - return "", err + if err != nil { + return "", ticketID, err + } } if email == "" { - return "", errors.New("error: please export JIRA_EMAIL") + return "", ticketID, errors.New("error: please export JIRA_EMAIL") } fmt.Println("User email: ", email) @@ -122,7 +126,7 @@ func GetJiraIssueName(ticketURL, ticketID string) (name string, err error) { // Create HTTP client and request req, err := http.NewRequest("GET", url, nil) if err != nil { - return "", err + return "", ticketID, err } req.SetBasicAuth(email, apiToken) req.Header.Set("Content-Type", "application/json") @@ -130,18 +134,18 @@ func GetJiraIssueName(ticketURL, ticketID string) (name string, err error) { client := &http.Client{} resp, err := client.Do(req) if err != nil { - return "", err + return "", ticketID, err } defer resp.Body.Close() // Read and parse the response body, err := io.ReadAll(resp.Body) if err != nil { - return "", err + return "", ticketID, err } if resp.StatusCode != http.StatusOK { - return "", err + return "", ticketID, err } var result struct { @@ -150,13 +154,13 @@ func GetJiraIssueName(ticketURL, ticketID string) (name string, err error) { } `json:"fields"` } if err := json.Unmarshal(body, &result); err != nil { - return "", fmt.Errorf("error parsing JSON response: %w", err) + return "", ticketID, fmt.Errorf("error parsing JSON response: %w", err) } // Check if the summary field exists if result.Fields.Summary == "" { - return "", nil + return "", ticketID, nil } - return result.Fields.Summary, nil + return result.Fields.Summary, ticketID, nil } diff --git a/internal/systrun/types.go b/internal/systrun/types.go index 76c22f6..be24dc9 100644 --- a/internal/systrun/types.go +++ b/internal/systrun/types.go @@ -16,7 +16,6 @@ import ( "github.com/untillpro/qs/gitcmds" contextCfg "github.com/untillpro/qs/internal/context" "github.com/untillpro/qs/internal/helper" - "github.com/untillpro/qs/internal/jira" notesPkg "github.com/untillpro/qs/internal/notes" ) @@ -497,18 +496,9 @@ func ExpectationPRCreated(ctx context.Context) error { } // extract expected PR title from GitHub issue or JIRA ticket - var expectedPRTitle string - if notesObj.GithubIssueURL != "" { - expectedPRTitle, err = gitcmds.GetIssueDescription(notesObj.GithubIssueURL) - if err != nil { - return err - } - } - if notesObj.JiraTicketURL != "" { - expectedPRTitle, err = jira.GetJiraIssueName(notesObj.JiraTicketURL, "") - if err != nil { - return err - } + expectedPRTitle, err := gitcmds.GetIssueDescription(notes) + if err != nil { + return err } // check actual PR title with expected one