Skip to content

Commit 03fd4f9

Browse files
committed
close #63 open issue in browser from terminal
1 parent 9a38ca7 commit 03fd4f9

File tree

7 files changed

+114
-22
lines changed

7 files changed

+114
-22
lines changed

ci/notes/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
The release brings some much needed features to the phlow. Requests for opening GitHub issues have been heard, and here it is.
2+
We have also tried to address the issues with the workon command, where in some cases it was unable to locate the issues on github.
3+
As always we strive for perfection and try to make the code pretty as a butterfly.
4+
5+
#### Features
6+
- web command #63 (Browser can be started from phlow) @groenborg
7+
- list issues #69 (Lists opens issues in the terminal)
8+
9+
#### Bug fixes
10+
- now finds remote issues #64 (both ssh and https urls now work) @groenborg

ci/notes/release-notes.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

ci/pipeline.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ jobs:
117117
name: resource-version/version
118118
tag: resource-version/version
119119
tag_prefix: v
120-
body: git-phlow/ci/notes/release-notes.md
120+
body: git-phlow/ci/notes/CHANGELOG.md
121121
globs:
122122
- phlow-artifact-linux-s3/git-phlow-*-linux-amd64.tar.gz
123123
- phlow-artifact-darwin-s3/git-phlow-*-darwin-amd64.tar.gz
@@ -137,7 +137,7 @@ jobs:
137137
name: resource-version/version
138138
tag: resource-version/version
139139
tag_prefix: v
140-
body: git-phlow/ci/notes/release-notes.md
140+
body: git-phlow/ci/notes/CHANGELOG.md
141141
globs:
142142
- phlow-artifact-linux-s3/git-phlow-*-linux-amd64.tar.gz
143143
- phlow-artifact-darwin-s3/git-phlow-*-darwin-amd64.tar.gz
@@ -157,7 +157,7 @@ jobs:
157157
name: resource-version/version
158158
tag: resource-version/version
159159
tag_prefix: v
160-
body: git-phlow/ci/notes/release-notes.md
160+
body: git-phlow/ci/notes/CHANGELOG.md
161161
globs:
162162
- phlow-artifact-linux-s3/git-phlow-*-linux-amd64.tar.gz
163163
- phlow-artifact-darwin-s3/git-phlow-*-darwin-amd64.tar.gz

cmd/web.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
"github.com/praqma/git-phlow/phlow"
8+
"strconv"
9+
"os"
10+
)
11+
12+
// webCmd represents the web command
13+
var webCmd = &cobra.Command{
14+
Use: "web [issue]",
15+
Short: "open your issues on github",
16+
Long: `
17+
web opens a github issue or githubs issue list based on it's arguments'
18+
If no argument is passed, it tries to locate an issue on the current checked out branch,
19+
if that fails it will simply open GitHubs issue list in your default browser
20+
`,
21+
Run: func(cmd *cobra.Command, args []string) {
22+
23+
if len(args) > 0 {
24+
if val, err := strconv.Atoi(args[0]); err == nil {
25+
phlow.Web(val)
26+
} else {
27+
fmt.Println("argument must be a number")
28+
os.Exit(0)
29+
}
30+
} else {
31+
phlow.Web(-1)
32+
}
33+
},
34+
}
35+
36+
func init() {
37+
RootCmd.AddCommand(webCmd)
38+
}

phlow/web.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package phlow
2+
3+
import (
4+
"github.com/praqma/git-phlow/executor"
5+
"github.com/praqma/git-phlow/githandler"
6+
"github.com/praqma/git-phlow/plugins"
7+
"fmt"
8+
"os"
9+
)
10+
11+
func Web(userIssue int) {
12+
13+
var issueListURL = "https://github.com/%s/%s/issues"
14+
var issueInfoURL = "https://github.com/%s/%s/issues/%d"
15+
16+
//Get organisation and repository for repository
17+
orgAndRepo, err := githandler.Remote()
18+
if err != nil {
19+
fmt.Println(err)
20+
os.Exit(1)
21+
}
22+
23+
//Get your current branch
24+
branchInfo, err := githandler.Branch()
25+
if err != nil {
26+
fmt.Println(err)
27+
os.Exit(1)
28+
}
29+
30+
branchIssue := plugins.IssueFromBranchName(branchInfo.Current)
31+
32+
if userIssue != -1 {
33+
issueInfoURL = fmt.Sprintf(issueInfoURL, orgAndRepo.Organisation, orgAndRepo.Repository, userIssue)
34+
_, err := executor.ExecuteCommand("open", issueInfoURL)
35+
if err != nil {
36+
fmt.Println(err)
37+
}
38+
os.Exit(0)
39+
}
40+
41+
if branchIssue != -1 {
42+
issueInfoURL = fmt.Sprintf(issueInfoURL, orgAndRepo.Organisation, orgAndRepo.Repository, branchIssue)
43+
executor.ExecuteCommand("open", issueInfoURL)
44+
os.Exit(0)
45+
}
46+
47+
issueListURL = fmt.Sprintf(issueListURL, orgAndRepo.Organisation, orgAndRepo.Repository)
48+
executor.ExecuteCommand("open", issueListURL)
49+
}

phlow/workon.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ package phlow
33
import (
44
"fmt"
55
"os"
6-
"strconv"
7-
"strings"
8-
96
"github.com/praqma/git-phlow/githandler"
107
"github.com/praqma/git-phlow/plugins"
118
"github.com/praqma/git-phlow/ui"
@@ -29,13 +26,13 @@ func WorkOn(issue int) {
2926
}
3027

3128
fmt.Fprintln(os.Stdout, "Locating existing issue branches")
32-
if GetIssueFromBranch(branchInfo.Current) == issue {
29+
if plugins.IssueFromBranchName(branchInfo.Current) == issue {
3330
fmt.Fprintf(os.Stdout, "You are already on branch %s \n", ui.BranchFormat(branchInfo.Current))
3431
return
3532
}
3633

3734
for _, branch := range branchInfo.List {
38-
if GetIssueFromBranch(branch) == issue {
35+
if plugins.IssueFromBranchName(branch) == issue {
3936
if err = githandler.CheckOut(branch); err != nil {
4037
fmt.Println(err)
4138
}
@@ -96,13 +93,3 @@ func UpdateIssue(issue int) {
9693
fmt.Println("----------------------------------")
9794
return
9895
}
99-
100-
//GetIssueFromBranch ...
101-
//Extracts the issue number from the branch name
102-
func GetIssueFromBranch(branch string) int {
103-
iss, err := strconv.Atoi(strings.Split(branch, "-")[0])
104-
if err != nil {
105-
return -1
106-
}
107-
return iss
108-
}

plugins/plugin.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ func BranchNameFromIssue(issue int, name string) string {
7979
return strconv.Itoa(issue) + "-" + result
8080
}
8181

82+
83+
//IssueFromBranchName
84+
//Extracts the issue number from the branch name
85+
func IssueFromBranchName(branch string) int {
86+
iss, err := strconv.Atoi(strings.Split(branch, "-")[0])
87+
if err != nil {
88+
return -1
89+
}
90+
return iss
91+
}
92+
93+
8294
//efficientConcatString
8395
//Concatenate strings in an effective way
8496
func efficientConcatString(args ...string) string {

0 commit comments

Comments
 (0)