diff --git a/CHANGELOG.md b/CHANGELOG.md index 131ffd0..acf8711 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,16 +4,25 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +## [0.3.0] - 2022-02-21 +### Added +- `gojira view` command that opens up issue in default browser - works with issue key as arg and fetched from git branch name + +### Changed +- default behavior of argument-less `gojira` call if git branch is detected, now it allows to select do you want to log worklog or view issue in browser + ## [0.2.2] - 2021-05-04 ### Fixed -- time spent input now properly handles lack of whitespace between time parts - `1h30m` +- time spent input now properly handles lack of whitespace between time parts - `1h30m` ## [0.2.1] - 2021-05-04 -### Fixed +### Fixed - `gojira worklogs` now properly reports overall time spent after editing work log ## [0.2.0] - 2021-05-04 -### Added +### Added - `gojira log` improvements: - command verifies entered issue key by asking jira api about details - details are displayed along logging time or before time spent prompt @@ -21,10 +30,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), basically any string containing something that looks like jira ticket will be accepted ## [0.1.0] - 2021-05-03 - ### Added - Initial release of gojira +[Unreleased]: https://github.com/jzyinq/gojira/compare/0.3.0...master +[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 [0.2.0]: https://github.com/jzyinq/gojira/compare/0.1.0...0.2.0 [0.1.0]: https://github.com/jzyinq/gojira/tree/0.1.0 \ No newline at end of file diff --git a/go.mod b/go.mod index 89a8bc7..cb48f04 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,6 @@ go 1.13 require ( github.com/manifoldco/promptui v0.8.0 + github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 github.com/urfave/cli/v2 v2.3.0 ) diff --git a/go.sum b/go.sum index 7d8420a..2ec7aac 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,3 @@ -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= @@ -12,7 +11,6 @@ github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a h1:FaWFmfWdAUKbSCtOU github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -24,6 +22,8 @@ github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRU github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= @@ -32,10 +32,10 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5I github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= -golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b h1:MQE+LT/ABUuuvEZ+YQAMSXindAdUh7slEmAkup74op4= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71 h1:X/2sJAybVknnUnV7AD2HdT6rm2p5BP6eH2j+igduWgk= +golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/gojira/cli.go b/gojira/cli.go index 30946ad..d8603fd 100644 --- a/gojira/cli.go +++ b/gojira/cli.go @@ -2,6 +2,7 @@ package gojira import ( "fmt" + "github.com/manifoldco/promptui" "github.com/urfave/cli/v2" "log" "os" @@ -63,6 +64,12 @@ var IssuesCommand = &cli.Command{ }, } +var ViewIssueCommand = &cli.Command{ + Name: "view", + Usage: "View issue in browser", + Action: ViewIssueInBrowserAction, +} + var LogWorkCommand = &cli.Command{ Name: "log", Usage: "Log work to specified issue", @@ -71,7 +78,10 @@ var LogWorkCommand = &cli.Command{ issueKey := FindIssueKeyInString(context.Args().Get(0)) timeSpent := context.Args().Get(1) if issueKey == "" { - log.Fatalln("You need to provide at least an issue key as argument") + issueKey = GetTicketFromGitBranch() + } + if issueKey == "" { + log.Fatalln("No issue key given / detected in git branch.") } issue := GetIssue(issueKey) fmt.Printf("%s %s\n", issue.Key, issue.Fields.Summary) @@ -94,6 +104,29 @@ var DefaultAction = func(c *cli.Context) error { fmt.Printf("Command not found: %v\n", c.Args().Get(0)) os.Exit(1) } + + ticketFromBranch := GetTicketFromGitBranch() + if ticketFromBranch != "" { + fmt.Printf("Detected possible ticket in git branch name - %s\n", ticketFromBranch) + prompt := promptui.Select{ + Label: "Select Action", + Items: []string{"Log Work", "View Issue"}, + } + _, action, err := prompt.Run() + + if err != nil { + fmt.Printf("Prompt failed %v\n", err) + return nil + } + fmt.Printf("You choose %q\n", action) + if action == "Log Work" { + return GitOrIssueListAction(c) //fixme pass resolved Issue in context + } + if action == "View Issue" { + return ViewIssueInBrowserAction(c) //fixme pass resolved Issue in context + } + } + return GitOrIssueListAction(c) } @@ -103,6 +136,8 @@ var GitOrIssueListAction = func(c *cli.Context) error { fmt.Printf("Detected possible ticket in git branch name - %s\n", ticketFromBranch) issue := GetIssue(ticketFromBranch) 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 { return nil @@ -118,6 +153,18 @@ var GitOrIssueListAction = func(c *cli.Context) error { return nil } +var ViewIssueInBrowserAction = func(c *cli.Context) error { + issueKey := FindIssueKeyInString(c.Args().Get(0)) + if issueKey == "" { + issueKey = GetTicketFromGitBranch() + } + + if issueKey != "" { + OpenUrl(fmt.Sprintf("%s/browse/%s", Config.JiraUrl, issueKey)) + } + return nil +} + var ConfigCommand = &cli.Command{ Name: "config", Usage: "configuration help", diff --git a/gojira/utils.go b/gojira/utils.go index 67e1156..8b1064b 100644 --- a/gojira/utils.go +++ b/gojira/utils.go @@ -2,6 +2,7 @@ package gojira import ( "fmt" + "github.com/pkg/browser" "math" "os/exec" "regexp" @@ -52,3 +53,14 @@ func FindIssueKeyInString(possibleUrl string) string { match := r.FindString(possibleUrl) return match } + +func OpenUrl(url string) { + // silence browser logs + browser.Stdout = nil + browser.Stderr = nil + err := browser.OpenURL(url) + if err != nil { + fmt.Println(err) + return + } +} diff --git a/main.go b/main.go index 21f9ea1..700e82e 100644 --- a/main.go +++ b/main.go @@ -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.2.2", + Version: "0.3.0", Before: func(context *cli.Context) error { if context.Args().First() != "config" { // dont' check envs on ConfigCommand @@ -27,6 +27,7 @@ func main() { IssuesCommand, WorkLogsCommand, ConfigCommand, + ViewIssueCommand, }, Action: DefaultAction, }