Skip to content

Commit

Permalink
Remove unnecessary calls while resolving issue key
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 94fbf35b7602a523ae48c2f324a09093c1a9d78a
Author: Jarosław Zywert <[email protected]>
Date:   Wed Mar 9 07:13:18 2022 +0100

    changelog

commit 31afb231f81e7af132b638b52f3bb72496e7bfee
Author: Jarosław Zywert <[email protected]>
Date:   Tue Mar 8 10:18:05 2022 +0100

    changelog

commit 2d65c859c779ef00b3bc6065a070af709368dd6c
Author: Jarosław Zywert <[email protected]>
Date:   Tue Mar 8 10:16:13 2022 +0100

    JiraTicket -> JiraIssue

commit a0db196dbb15f5df5298cba7a40cab3e90b1921c
Author: Jarosław Zywert <[email protected]>
Date:   Tue Mar 8 10:15:30 2022 +0100

    ResolveIssueKey method + context passing JiraTicket info
  • Loading branch information
jzyinq committed Mar 9, 2022
1 parent 1deb561 commit c09f837
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

## [0.3.1] - 2022-03-09
### Changed
- Replace multiple methods for fetching issue key with single `ResolveIssueKey` method

## [0.3.0] - 2022-02-21
### Added
### Added
- `gojira view` command that opens up issue in default browser - works with issue key as arg and fetched from git branch name

### Changed
Expand All @@ -33,7 +37,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Added
- Initial release of gojira

[Unreleased]: https://github.com/jzyinq/gojira/compare/0.3.0...master
[Unreleased]: https://github.com/jzyinq/gojira/compare/0.3.1...master
[0.3.1]: https://github.com/jzyinq/gojira/compare/0.3.0...0.3.1
[0.3.0]: https://github.com/jzyinq/gojira/compare/0.2.2...0.3.0
[0.2.2]: https://github.com/jzyinq/gojira/compare/0.2.1...0.2.2
[0.2.1]: https://github.com/jzyinq/gojira/compare/0.2.0...0.2.1
Expand Down
23 changes: 7 additions & 16 deletions gojira/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,8 @@ var LogWorkCommand = &cli.Command{
Usage: "Log work to specified issue",
ArgsUsage: "ISSUE [TIME_SPENT]",
Action: func(context *cli.Context) error {
issueKey := FindIssueKeyInString(context.Args().Get(0))
issueKey := ResolveIssueKey(context)
timeSpent := context.Args().Get(1)
if issueKey == "" {
issueKey = GetTicketFromGitBranch()
}
if issueKey == "" {
log.Fatalln("No issue key given / detected in git branch.")
}
Expand All @@ -104,9 +101,9 @@ var DefaultAction = func(c *cli.Context) error {
fmt.Printf("Command not found: %v\n", c.Args().Get(0))
os.Exit(1)
}

ticketFromBranch := GetTicketFromGitBranch()
ticketFromBranch := ResolveIssueKey(c)
if ticketFromBranch != "" {
c.App.Metadata["JiraIssue"] = ticketFromBranch
fmt.Printf("Detected possible ticket in git branch name - %s\n", ticketFromBranch)
prompt := promptui.Select{
Label: "Select Action",
Expand All @@ -131,12 +128,10 @@ var DefaultAction = func(c *cli.Context) error {
}

var GitOrIssueListAction = func(c *cli.Context) error {
ticketFromBranch := GetTicketFromGitBranch()
if ticketFromBranch != "" {
fmt.Printf("Detected possible ticket in git branch name - %s\n", ticketFromBranch)
issue := GetIssue(ticketFromBranch)
issueKey := ResolveIssueKey(c)
if issueKey != "" {
issue := GetIssue(issueKey)
fmt.Printf("Status: %s\nSummary: %s\n", issue.Fields.Status.Name, issue.Fields.Summary)

// log time or view issue
timeSpent, err := PromptForTimeSpent("Add work log")
if err != nil {
Expand All @@ -154,11 +149,7 @@ var GitOrIssueListAction = func(c *cli.Context) error {
}

var ViewIssueInBrowserAction = func(c *cli.Context) error {
issueKey := FindIssueKeyInString(c.Args().Get(0))
if issueKey == "" {
issueKey = GetTicketFromGitBranch()
}

issueKey := ResolveIssueKey(c)
if issueKey != "" {
OpenUrl(fmt.Sprintf("%s/browse/%s", Config.JiraUrl, issueKey))
}
Expand Down
2 changes: 1 addition & 1 deletion gojira/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func GetLatestIssues() JQLResponse {
payload := &JQLSearch{
Expand: []string{"names"},
Jql: "assignee in (currentUser()) ORDER BY updated DESC, created DESC",
MaxResults: 5,
MaxResults: 10,
FieldsByKeys: false,
Fields: []string{"summary", "status"},
StartAt: 0,
Expand Down
2 changes: 1 addition & 1 deletion gojira/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func PromptForIssueSelection(issues []Issue) (Issue, error) {
Label: "Recently updated jira tickets assigned to you:",
Items: issues,
Templates: templates,
Size: 5,
Size: 10,
Searcher: searcher,
HideHelp: true,
}
Expand Down
14 changes: 14 additions & 0 deletions gojira/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gojira
import (
"fmt"
"github.com/pkg/browser"
"github.com/urfave/cli/v2"
"math"
"os/exec"
"regexp"
Expand Down Expand Up @@ -40,6 +41,19 @@ func FormatTimeSpent(timeSpentSeconds int) string {
return timeSpent
}

func ResolveIssueKey(c *cli.Context) string {
issueKey := ""
if c.App.Metadata["JiraIssue"] != nil {
issueKey = fmt.Sprintf("%s", c.App.Metadata["JiraTicket"])
}
issueKey = FindIssueKeyInString(c.Args().Get(0))
if issueKey == "" {
issueKey = GetTicketFromGitBranch()
}

return issueKey
}

func GetTicketFromGitBranch() string {
gitBranch, err := exec.Command("git", "branch", "--show-current").CombinedOutput()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
Calling without arguments will try to detect issue from git branch,
otherwise it will display list of last updated issues you're are assigned to.`,
Version: "0.3.0",
Version: "0.3.1",
Before: func(context *cli.Context) error {
if context.Args().First() != "config" {
// dont' check envs on ConfigCommand
Expand Down

0 comments on commit c09f837

Please sign in to comment.