-
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.
- Loading branch information
0 parents
commit 71e081d
Showing
14 changed files
with
850 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,10 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: github-actions | ||
directory: "/" | ||
schedule: | ||
interval: daily | ||
- package-ecosystem: gomod | ||
directory: "/" | ||
schedule: | ||
interval: daily |
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,55 @@ | ||
name: ci | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- v* | ||
|
||
jobs: | ||
test: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
- macOS-latest | ||
# - windows-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: go.mod | ||
cache: true | ||
|
||
- run: go mod download | ||
- run: go test -v ./... | ||
|
||
- run: go build . | ||
- run: ./git-open . | ||
|
||
release: | ||
if: startsWith(github.ref, 'refs/tags/v') | ||
runs-on: ubuntu-latest | ||
needs: [test] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: go.mod | ||
|
||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v5 | ||
with: | ||
version: latest | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} |
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,38 @@ | ||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- darwin | ||
- windows | ||
goarch: | ||
- amd64 | ||
- arm64 | ||
|
||
checksum: | ||
name_template: "checksums.txt" | ||
|
||
archives: | ||
- name_template: "{{ .ProjectName }}-v{{ .Version }}-{{ .Os }}-{{ .Arch }}" | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
|
||
brews: | ||
- name: git-open | ||
description: Opens your webbrowser | ||
homepage: https://github.com/arbourd/git-open | ||
|
||
conflicts: | ||
- git-open | ||
|
||
folder: Formula | ||
|
||
repository: | ||
owner: arbourd | ||
name: homebrew-tap | ||
token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}" | ||
|
||
commit_author: | ||
name: Dylan Arbour | ||
email: [email protected] |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Dylan Arbour | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,43 @@ | ||
# git-open | ||
|
||
`git-open` opens your browser at points it to the path you selected in the VCS. | ||
|
||
## Usage | ||
|
||
Open the root of a repository. | ||
|
||
```console | ||
$ git open | ||
``` | ||
|
||
Open a specific file or folder of a repository. | ||
|
||
```console | ||
$ git open LICENSE | ||
``` | ||
|
||
Open a specific commit of a repository. | ||
|
||
```console | ||
$ git open 7605d91 | ||
``` | ||
|
||
Open a different repository than `cwd`. | ||
|
||
```console | ||
$ git -C ~/src/my-repo open | ||
``` | ||
|
||
## Installation | ||
|
||
Install with `brew`. | ||
|
||
```console | ||
$ brew install arbourd/tap/git-open | ||
``` | ||
|
||
Install with `go install`. | ||
|
||
```console | ||
$ go install github.com/arbourd/git-open@latest | ||
``` |
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,48 @@ | ||
package gitw | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/ldez/go-git-cmd-wrapper/v2/git" | ||
"github.com/ldez/go-git-cmd-wrapper/v2/types" | ||
) | ||
|
||
// GitDir checks if the directory is a Git repository, | ||
// with the Git directory specified by path | ||
// | ||
// git -C path rev-parse --git-dir | ||
func GitDir(path string) (string, error) { | ||
out, err := git.Raw("-C", func(g *types.Cmd) { | ||
g.AddOptions(path) | ||
g.AddOptions("rev-parse") | ||
g.AddOptions("--git-dir") | ||
}) | ||
return strings.TrimSpace(out), err | ||
} | ||
|
||
// RemoteURL returns the URL of the remote, | ||
// with the Git directory specified by path | ||
// | ||
// git -C path ls-remote --get-url | ||
func RemoteURL(path string) (string, error) { | ||
out, err := git.Raw("-C", func(g *types.Cmd) { | ||
g.AddOptions(path) | ||
g.AddOptions("ls-remote") | ||
g.AddOptions("--get-url") | ||
}) | ||
return strings.TrimSpace(out), err | ||
} | ||
|
||
// CurrentRef returns the current reference or branch name, | ||
// with the Git directory specified by path | ||
// | ||
// git -C path rev-parse --abbrev-ref HEAD | ||
func CurrentRef(path string) (string, error) { | ||
out, err := git.Raw("-C", func(g *types.Cmd) { | ||
g.AddOptions(path) | ||
g.AddOptions("rev-parse") | ||
g.AddOptions("--abbrev-ref") | ||
g.AddOptions("HEAD") | ||
}) | ||
return strings.TrimSpace(out), err | ||
} |
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,5 @@ | ||
module github.com/arbourd/git-open | ||
|
||
go 1.22 | ||
|
||
require github.com/ldez/go-git-cmd-wrapper/v2 v2.6.0 |
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 @@ | ||
github.com/ldez/go-git-cmd-wrapper/v2 v2.6.0 h1:o5QIusOiH9phm1gY2UGO6JQjYSPFYbgFCcntOigBvMg= | ||
github.com/ldez/go-git-cmd-wrapper/v2 v2.6.0/go.mod h1:whnaSah+AmezZS8vwp8FyFzEBHZCLKywWILUj5D8Jq0= |
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,41 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/arbourd/git-open/open" | ||
) | ||
|
||
func main() { | ||
arg, err := processArgs(os.Args) | ||
if err != nil { | ||
fmt.Printf("Error: \"%s\"\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
url, err := open.GetURL(arg) | ||
if err != nil { | ||
fmt.Printf("Error: \"%s\"\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Printf("Opening %s in your browser.\n", url) | ||
err = open.InBrowser(url) | ||
if err != nil { | ||
fmt.Printf("Error: unable to open in browser: \"%s\"\n", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
// processArgs returns a single argument or returns an error if more than 1 argument is provided | ||
func processArgs(args []string) (string, error) { | ||
switch len(args) { | ||
case 1: | ||
return "", nil | ||
case 2: | ||
return args[1], nil | ||
default: | ||
return "", fmt.Errorf("recieved %d args, accepts 1", len(args)-1) | ||
} | ||
} |
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,41 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestProcessArgs(t *testing.T) { | ||
cases := map[string]struct { | ||
args []string | ||
expectedArg string | ||
err string | ||
}{ | ||
"no argument": { | ||
args: []string{"git-open"}, | ||
expectedArg: "", | ||
}, | ||
"one argument": { | ||
args: []string{"git-open", "LICENSE"}, | ||
expectedArg: "LICENSE", | ||
}, | ||
"two arguments": { | ||
args: []string{"git-open", "LICENSE", "README.md"}, | ||
expectedArg: "", | ||
err: "recieved 2 args, accepts 1", | ||
}, | ||
} | ||
|
||
for name, c := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
arg, err := processArgs(c.args) | ||
|
||
if err != nil && c.err == "" { | ||
t.Fatalf("unexpected error:\n\t(GOT): %#v\n\t(WNT): nil", err) | ||
} else if err == nil && len(c.err) > 0 { | ||
t.Fatalf("expected error:\n\t(GOT): nil\n\t(WNT): %s", c.err) | ||
} else if arg != c.expectedArg { | ||
t.Fatalf("unexpected arg:\n\t(GOT): %#v\n\t(WNT): %#v", arg, c.expectedArg) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.