Merge remote-tracking branch 'origin/trunk' into prompt-factory
This commit is contained in:
commit
6bc89ebbc2
8 changed files with 835 additions and 792 deletions
6
go.mod
6
go.mod
|
|
@ -25,8 +25,8 @@ require (
|
|||
github.com/itchyny/gojq v0.12.8
|
||||
github.com/joho/godotenv v1.4.0
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
|
||||
github.com/mattn/go-colorable v0.1.12
|
||||
github.com/mattn/go-isatty v0.0.14
|
||||
github.com/mattn/go-colorable v0.1.13
|
||||
github.com/mattn/go-isatty v0.0.16
|
||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
|
||||
github.com/muesli/reflow v0.3.0
|
||||
github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0
|
||||
|
|
@ -39,7 +39,7 @@ require (
|
|||
github.com/stretchr/testify v1.7.5
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
|
||||
golang.org/x/text v0.3.7
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
|
|
|
|||
11
go.sum
11
go.sum
|
|
@ -184,12 +184,13 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
|
||||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||
|
|
@ -366,11 +367,11 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"net/url"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
|
@ -62,6 +63,9 @@ func NewCmdBrowse(f *cmdutil.Factory, runF func(*BrowseOptions) error) *cobra.Co
|
|||
$ gh browse 217
|
||||
#=> Open issue or pull request 217
|
||||
|
||||
$ gh browse 77507cd94ccafcf568f8560cfecde965fcfa63
|
||||
#=> Open commit page
|
||||
|
||||
$ gh browse --settings
|
||||
#=> Open repository settings
|
||||
|
||||
|
|
@ -169,6 +173,10 @@ func parseSection(baseRepo ghrepo.Interface, opts *BrowseOptions) (string, error
|
|||
return fmt.Sprintf("issues/%s", opts.SelectorArg), nil
|
||||
}
|
||||
|
||||
if isCommit(opts.SelectorArg) {
|
||||
return fmt.Sprintf("commit/%s", opts.SelectorArg), nil
|
||||
}
|
||||
|
||||
filePath, rangeStart, rangeEnd, err := parseFile(*opts, opts.SelectorArg)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
@ -252,6 +260,13 @@ func isNumber(arg string) bool {
|
|||
return err == nil
|
||||
}
|
||||
|
||||
// sha1 and sha256 are supported
|
||||
var commitHash = regexp.MustCompile(`\A[a-f0-9]{7,64}\z`)
|
||||
|
||||
func isCommit(arg string) bool {
|
||||
return commitHash.MatchString(arg)
|
||||
}
|
||||
|
||||
// gitClient is used to implement functions that can be performed on both local and remote git repositories
|
||||
type gitClient interface {
|
||||
LastCommit() (*git.Commit, error)
|
||||
|
|
|
|||
|
|
@ -414,6 +414,35 @@ func Test_runBrowse(t *testing.T) {
|
|||
expectedURL: "https://github.com/bchadwic/test/blob/branch/with%20spaces%3F/%3F=hello%20world/%20%2A?plain=1#L23-L44",
|
||||
wantsErr: false,
|
||||
},
|
||||
{
|
||||
name: "commit hash in selector arg",
|
||||
opts: BrowseOptions{
|
||||
SelectorArg: "77507cd94ccafcf568f8560cfecde965fcfa63e7",
|
||||
},
|
||||
baseRepo: ghrepo.New("bchadwic", "test"),
|
||||
expectedURL: "https://github.com/bchadwic/test/commit/77507cd94ccafcf568f8560cfecde965fcfa63e7",
|
||||
wantsErr: false,
|
||||
},
|
||||
{
|
||||
name: "short commit hash in selector arg",
|
||||
opts: BrowseOptions{
|
||||
SelectorArg: "6e3689d5",
|
||||
},
|
||||
baseRepo: ghrepo.New("bchadwic", "test"),
|
||||
expectedURL: "https://github.com/bchadwic/test/commit/6e3689d5",
|
||||
wantsErr: false,
|
||||
},
|
||||
|
||||
{
|
||||
name: "commit hash with extension",
|
||||
opts: BrowseOptions{
|
||||
SelectorArg: "77507cd94ccafcf568f8560cfecde965fcfa63e7.txt",
|
||||
Branch: "trunk",
|
||||
},
|
||||
baseRepo: ghrepo.New("bchadwic", "test"),
|
||||
expectedURL: "https://github.com/bchadwic/test/tree/trunk/77507cd94ccafcf568f8560cfecde965fcfa63e7.txt",
|
||||
wantsErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
|
|
@ -66,11 +66,13 @@ func newSSHCmd(app *App) *cobra.Command {
|
|||
|
||||
Note that the codespace you are connecting to must have an SSH server pre-installed.
|
||||
If the docker image being used for the codespace does not have an SSH server,
|
||||
install it in your Dockerfile or you can try adding the following snippet
|
||||
in your devcontainer.json:
|
||||
|
||||
install it in your Dockerfile or, for codespaces that use Debian-based images,
|
||||
you can add the following to your devcontainer.json:
|
||||
|
||||
"features": {
|
||||
"sshd": "latest"
|
||||
"ghcr.io/devcontainers/features/sshd:1": {
|
||||
"version": "latest"
|
||||
}
|
||||
}
|
||||
`),
|
||||
Example: heredoc.Doc(`
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/itchyny/gojq"
|
||||
)
|
||||
|
|
@ -14,6 +15,16 @@ func FilterJSON(w io.Writer, input io.Reader, queryStr string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
code, err := gojq.Compile(
|
||||
query,
|
||||
gojq.WithEnvironLoader(func() []string {
|
||||
return os.Environ()
|
||||
}))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jsonData, err := io.ReadAll(input)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -25,7 +36,7 @@ func FilterJSON(w io.Writer, input io.Reader, queryStr string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
iter := query.Run(responseData)
|
||||
iter := code.Run(responseData)
|
||||
for {
|
||||
v, ok := iter.Next()
|
||||
if !ok {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import (
|
|||
)
|
||||
|
||||
func Test_filterJSON(t *testing.T) {
|
||||
t.Setenv("CODE", "code_c")
|
||||
|
||||
type args struct {
|
||||
json io.Reader
|
||||
query string
|
||||
|
|
@ -69,6 +71,27 @@ func Test_filterJSON(t *testing.T) {
|
|||
Alas, tis' the end ,feature
|
||||
`),
|
||||
},
|
||||
{
|
||||
name: "with env var",
|
||||
args: args{
|
||||
json: strings.NewReader(heredoc.Doc(`[
|
||||
{
|
||||
"title": "code_a",
|
||||
"labels": [{"name":"bug"}, {"name":"help wanted"}]
|
||||
},
|
||||
{
|
||||
"title": "code_b",
|
||||
"labels": []
|
||||
},
|
||||
{
|
||||
"title": "code_c",
|
||||
"labels": [{}, {"name":"feature"}]
|
||||
}
|
||||
]`)),
|
||||
query: `.[]| select(.title == env.CODE) | .labels`,
|
||||
},
|
||||
wantW: "[{},{\"name\":\"feature\"}]\n",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue