Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions gitcmds/gitcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions gitcmds/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
36 changes: 20 additions & 16 deletions internal/jira/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
}
}

Expand All @@ -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)

Expand All @@ -122,26 +126,26 @@ 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")

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 {
Expand All @@ -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
}
16 changes: 3 additions & 13 deletions internal/systrun/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down