-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from kyoshidajp/init
Implement basic functions
- Loading branch information
Showing
10 changed files
with
445 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: go | ||
on: | ||
push: | ||
paths: | ||
- "**.go" | ||
- go.mod | ||
- go.sum | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: '1.20' | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: release | ||
on: | ||
push: | ||
tags: | ||
- "v*" | ||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: cli/gh-extension-precompile@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/gh-browse-pr | ||
/gh-browse-pr.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# gh-browse-pr | ||
|
||
`gh-browse-pr` is a GitHub CLI extention to open pull request page in your current directory. | ||
|
||
If a pull request already exists, it opens that page; otherwise, it opens the page where the pull request was created. | ||
|
||
## Installation | ||
|
||
1. Install the `gh` - see the [installation](https://github.com/cli/cli#installation) | ||
1. Install this extension: | ||
|
||
```sh | ||
gh extension install kyoshidajp/gh-browse-pr | ||
``` | ||
|
||
## Usage | ||
|
||
Run in your git working directory. | ||
|
||
```sh | ||
gh browse-pr | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module github.com/kyoshidajp/gh-browse-pr | ||
|
||
go 1.20 | ||
|
||
require ( | ||
dario.cat/mergo v1.0.0 // indirect | ||
github.com/Microsoft/go-winio v0.6.1 // indirect | ||
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect | ||
github.com/acomagu/bufpipe v1.0.4 // indirect | ||
github.com/cloudflare/circl v1.3.3 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/emirpasic/gods v1.18.1 // indirect | ||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect | ||
github.com/go-git/go-billy/v5 v5.4.1 // indirect | ||
github.com/go-git/go-git/v5 v5.8.1 // indirect | ||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/google/go-querystring v1.1.0 // indirect | ||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect | ||
github.com/kevinburke/ssh_config v1.2.0 // indirect | ||
github.com/pjbgf/sha1cd v0.3.0 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/sergi/go-diff v1.3.1 // indirect | ||
github.com/skeema/knownhosts v1.2.0 // indirect | ||
github.com/xanzy/ssh-agent v0.3.3 // indirect | ||
golang.org/x/crypto v0.12.0 // indirect | ||
golang.org/x/oauth2 v0.11.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
gopkg.in/warnings.v0 v0.1.2 // indirect | ||
) | ||
|
||
require ( | ||
github.com/cli/go-gh/v2 v2.1.0 | ||
github.com/cli/safeexec v1.0.1 // indirect | ||
github.com/cli/shurcooL-graphql v0.0.3 // indirect | ||
github.com/google/go-github/v53 v53.2.0 | ||
github.com/kr/text v0.2.0 // indirect | ||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect | ||
github.com/mattn/go-isatty v0.0.19 // indirect | ||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 | ||
github.com/rivo/uniseg v0.4.4 // indirect | ||
github.com/stretchr/testify v1.8.4 | ||
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e // indirect | ||
golang.org/x/net v0.14.0 // indirect | ||
golang.org/x/sys v0.11.0 // indirect | ||
golang.org/x/term v0.11.0 // indirect | ||
golang.org/x/text v0.12.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
go 1.20 | ||
|
||
use . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
github.com/cli/safeexec v1.0.1 h1:e/C79PbXF4yYTN/wauC4tviMxEV13BwljGj0N9j+N00= | ||
github.com/cli/safeexec v1.0.1/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q= | ||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= | ||
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= | ||
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= | ||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= | ||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= | ||
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= | ||
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= | ||
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= | ||
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= | ||
golang.org/x/oauth2 v0.11.0/go.mod h1:LdF7O/8bLR/qWK9DrpXmbHLTouvRHK0SgJl0GmDBchk= | ||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= | ||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= | ||
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= | ||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= | ||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/url" | ||
"os" | ||
"strings" | ||
|
||
"github.com/cli/go-gh/v2" | ||
"github.com/go-git/go-git/v5" | ||
"github.com/pkg/browser" | ||
) | ||
|
||
func main() { | ||
currentBranch := getCurrentBranch() | ||
repositoryUrl := getRepositoryUrl() | ||
prUrl := GetPrUrl(repositoryUrl, currentBranch) | ||
|
||
browser.OpenURL(prUrl) | ||
} | ||
|
||
func getCurrentBranch() string { | ||
dir, err := os.Getwd() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
repo, err := git.PlainOpen(dir) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
head, err := repo.Head() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
ref := head.Name().String() | ||
return strings.Replace(ref, "refs/heads/", "", 1) | ||
} | ||
|
||
func getRepositoryUrl() string { | ||
stdOut, _, err := gh.Exec("browse", "-n") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return strings.TrimSuffix(stdOut.String(), "\n") | ||
} | ||
|
||
func GetPrUrl(repository string, branch string) string { | ||
prUrl, err := url.JoinPath(repository, "pull", branch) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return prUrl | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetPrUrl(t *testing.T) { | ||
expected := "https://github.com/kyoshidajp/gh-browse-pr/pull/main" | ||
actual := GetPrUrl( | ||
"https://github.com/kyoshidajp/gh-browse-pr", | ||
"main", | ||
) | ||
|
||
assert.Equal(t, expected, actual) | ||
} |