From 626ec9835b4450fb2994ec931357279700437b6b Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sun, 7 Mar 2021 14:09:15 +0100 Subject: [PATCH 1/2] webui: allow specifying the initial query Example use-case: given a github URL in a source code comment or commit message, one can now run: git bug webui --query 'metadata:github-url:"https://github.com/author/myproject/issues/42"' on the commandline to look up the details of that issue on the web ui quickly, offline. Fixes . --- commands/webui.go | 8 ++++++++ doc/man/git-bug-webui.1 | 4 ++++ doc/md/git-bug_webui.md | 13 +++++++------ misc/bash_completion/git-bug | 4 ++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/commands/webui.go b/commands/webui.go index d910a7034794ecf0ff5d41fa3233c2a6d9944711..3857e968cf75335a81f96c46de7e923a6f777220 100644 --- a/commands/webui.go +++ b/commands/webui.go @@ -6,6 +6,7 @@ import ( "log" "net" "net/http" + "net/url" "os" "os/signal" "strconv" @@ -34,6 +35,7 @@ type webUIOptions struct { open bool noOpen bool readOnly bool + query string } func newWebUICommand() *cobra.Command { @@ -62,6 +64,7 @@ Available git config: flags.BoolVar(&options.noOpen, "no-open", false, "Prevent the automatic opening of the web UI in the default browser") flags.IntVarP(&options.port, "port", "p", 0, "Port to listen to (default to random available port)") flags.BoolVar(&options.readOnly, "read-only", false, "Whether to run the web UI in read-only mode") + flags.StringVar(&options.query, "query", "", "Set a custom query") return cmd } @@ -78,6 +81,11 @@ func runWebUI(env *Env, opts webUIOptions, args []string) error { addr := net.JoinHostPort(opts.host, strconv.Itoa(opts.port)) webUiAddr := fmt.Sprintf("http://%s", addr) + if len(opts.query) > 0 { + // Explicitly set the query parameter instead of going with a default one. + webUiAddr = fmt.Sprintf("%s/?q=%s", webUiAddr, url.QueryEscape(opts.query)) + } + router := mux.NewRouter() // If the webUI is not read-only, use an authentication middleware with a diff --git a/doc/man/git-bug-webui.1 b/doc/man/git-bug-webui.1 index 6e4622be77b4cb36d29f09200798bbc3d5afd811..6bed91439bfe7ce058252e066e135fa384c76208 100644 --- a/doc/man/git-bug-webui.1 +++ b/doc/man/git-bug-webui.1 @@ -41,6 +41,10 @@ Available git config: \fB\-\-read\-only\fP[=false] Whether to run the web UI in read\-only mode +.PP +\fB\-\-query\fP="" + Set a custom query + .PP \fB\-h\fP, \fB\-\-help\fP[=false] help for webui diff --git a/doc/md/git-bug_webui.md b/doc/md/git-bug_webui.md index ccfaff9a6e9540f084c7ae0ac420d8a1b410442e..0cdfd51751092276573c12404b5fc3ab1a2adbf0 100644 --- a/doc/md/git-bug_webui.md +++ b/doc/md/git-bug_webui.md @@ -17,12 +17,13 @@ git-bug webui [flags] ### Options ``` - --host string Network address or hostname to listen to (default to 127.0.0.1) (default "127.0.0.1") - --open Automatically open the web UI in the default browser - --no-open Prevent the automatic opening of the web UI in the default browser - -p, --port int Port to listen to (default to random available port) - --read-only Whether to run the web UI in read-only mode - -h, --help help for webui + --host string Network address or hostname to listen to (default to 127.0.0.1) (default "127.0.0.1") + --open Automatically open the web UI in the default browser + --no-open Prevent the automatic opening of the web UI in the default browser + -p, --port int Port to listen to (default to random available port) + --read-only Whether to run the web UI in read-only mode + --query string Set a custom query + -h, --help help for webui ``` ### SEE ALSO diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index 8f2a0f8f3e7e1c2bba629787b5f5ea790c82906c..7c7cd975fa6b7a5a49cf5ffa46753643e4a2eabe 100644 --- a/misc/bash_completion/git-bug +++ b/misc/bash_completion/git-bug @@ -1347,6 +1347,10 @@ _git-bug_webui() local_nonpersistent_flags+=("-p") flags+=("--read-only") local_nonpersistent_flags+=("--read-only") + flags+=("--query=") + two_word_flags+=("--query") + local_nonpersistent_flags+=("--query") + local_nonpersistent_flags+=("--query=") must_have_one_flag=() must_have_one_noun=() From 3a819525d7811dcfb01d928af0e243de4388c456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sun, 7 Mar 2021 21:44:48 +0100 Subject: [PATCH 2/2] commands: minor fixes for the webui open with query - go fmt - add a shorthand - fix displayed webUI URL in the terminal --- commands/webui.go | 9 +++++---- doc/man/git-bug-webui.1 | 4 ++-- doc/md/git-bug_webui.md | 2 +- go.sum | 5 ----- misc/bash_completion/git-bug | 2 ++ repository/repo.go | 2 +- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/commands/webui.go b/commands/webui.go index 3857e968cf75335a81f96c46de7e923a6f777220..2f80bcd035ab674e58ce15ccd966959d0afbaadc 100644 --- a/commands/webui.go +++ b/commands/webui.go @@ -35,7 +35,7 @@ type webUIOptions struct { open bool noOpen bool readOnly bool - query string + query string } func newWebUICommand() *cobra.Command { @@ -64,7 +64,7 @@ Available git config: flags.BoolVar(&options.noOpen, "no-open", false, "Prevent the automatic opening of the web UI in the default browser") flags.IntVarP(&options.port, "port", "p", 0, "Port to listen to (default to random available port)") flags.BoolVar(&options.readOnly, "read-only", false, "Whether to run the web UI in read-only mode") - flags.StringVar(&options.query, "query", "", "Set a custom query") + flags.StringVarP(&options.query, "query", "q", "", "The query to open in the web UI bug list") return cmd } @@ -80,10 +80,11 @@ func runWebUI(env *Env, opts webUIOptions, args []string) error { addr := net.JoinHostPort(opts.host, strconv.Itoa(opts.port)) webUiAddr := fmt.Sprintf("http://%s", addr) + toOpen := webUiAddr if len(opts.query) > 0 { // Explicitly set the query parameter instead of going with a default one. - webUiAddr = fmt.Sprintf("%s/?q=%s", webUiAddr, url.QueryEscape(opts.query)) + toOpen = fmt.Sprintf("%s/?q=%s", webUiAddr, url.QueryEscape(opts.query)) } router := mux.NewRouter() @@ -162,7 +163,7 @@ func runWebUI(env *Env, opts webUIOptions, args []string) error { shouldOpen := (configOpen && !opts.noOpen) || opts.open if shouldOpen { - err = open.Run(webUiAddr) + err = open.Run(toOpen) if err != nil { env.out.Println(err) } diff --git a/doc/man/git-bug-webui.1 b/doc/man/git-bug-webui.1 index 6bed91439bfe7ce058252e066e135fa384c76208..782cba5611226cec6e952c6e19da18ef4cf54b83 100644 --- a/doc/man/git-bug-webui.1 +++ b/doc/man/git-bug-webui.1 @@ -42,8 +42,8 @@ Available git config: Whether to run the web UI in read\-only mode .PP -\fB\-\-query\fP="" - Set a custom query +\fB\-q\fP, \fB\-\-query\fP="" + The query to open in the web UI bug list .PP \fB\-h\fP, \fB\-\-help\fP[=false] diff --git a/doc/md/git-bug_webui.md b/doc/md/git-bug_webui.md index 0cdfd51751092276573c12404b5fc3ab1a2adbf0..2d6be92012b1c4fb9619d27bda0dd6fc2232d7b3 100644 --- a/doc/md/git-bug_webui.md +++ b/doc/md/git-bug_webui.md @@ -22,7 +22,7 @@ git-bug webui [flags] --no-open Prevent the automatic opening of the web UI in the default browser -p, --port int Port to listen to (default to random available port) --read-only Whether to run the web UI in read-only mode - --query string Set a custom query + -q, --query string The query to open in the web UI bug list -h, --help help for webui ``` diff --git a/go.sum b/go.sum index b13e190e94a8fb00d370a3a91fa441e9f92567ad..960409299663ba87d32e3532ce61d7a5f23397a5 100644 --- a/go.sum +++ b/go.sum @@ -436,8 +436,6 @@ github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasO github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= -github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4= -github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M= github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= @@ -474,8 +472,6 @@ github.com/vektah/gqlparser v1.3.1 h1:8b0IcD3qZKWJQHSzynbDlrtP3IxVydZ2DZepCGofqf github.com/vektah/gqlparser v1.3.1/go.mod h1:bkVf0FX+Stjg/MHnm8mEyubuaArhNEqfQhF+OTiAL74= github.com/willf/bitset v1.1.10 h1:NotGKqX0KwQ72NUzqrjZq5ipPNDQex9lo3WpaS8L2sc= github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= -github.com/xanzy/go-gitlab v0.40.1 h1:jHueLh5Inzv20TL5Yki+CaLmyvtw3Yq7blbWx7GmglQ= -github.com/xanzy/go-gitlab v0.40.1/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug= github.com/xanzy/go-gitlab v0.44.0 h1:cEiGhqu7EpFGuei2a2etAwB+x6403E5CvpLn35y+GPs= github.com/xanzy/go-gitlab v0.44.0/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= @@ -791,7 +787,6 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index 7c7cd975fa6b7a5a49cf5ffa46753643e4a2eabe..0bf62d9a1f4e2afd48892f6f19c33ee0a3fd452b 100644 --- a/misc/bash_completion/git-bug +++ b/misc/bash_completion/git-bug @@ -1349,8 +1349,10 @@ _git-bug_webui() local_nonpersistent_flags+=("--read-only") flags+=("--query=") two_word_flags+=("--query") + two_word_flags+=("-q") local_nonpersistent_flags+=("--query") local_nonpersistent_flags+=("--query=") + local_nonpersistent_flags+=("-q") must_have_one_flag=() must_have_one_noun=() diff --git a/repository/repo.go b/repository/repo.go index eb9296d4829704332960b586a0f54612fd992a3f..a1dc129edb7ca32aba7c0c70e481e0b541b4e7aa 100644 --- a/repository/repo.go +++ b/repository/repo.go @@ -11,7 +11,7 @@ import ( ) var ( - // ErrNotARepo is the error returned when the git repo root wan't be found + // ErrNotARepo is the error returned when the git repo root can't be found ErrNotARepo = errors.New("not a git repository") // ErrClockNotExist is the error returned when a clock can't be found ErrClockNotExist = errors.New("clock doesn't exist")