From ea329aed6909cac85680dbae37f6f4dcca134f8b Mon Sep 17 00:00:00 2001 From: Sascha Date: Sun, 28 Feb 2021 16:27:14 +0100 Subject: Add option to specify host address '--host'-cmdline-option is added to the webui command. Previously, the WebUI couldn't be hosted inside of a container. As the WebUI-server only listend per default to localhost and there was no option to change the address, the server should listend to. This means, that the WebUI was only reachable from localhost. So only from inside of the container but never from outside. The '--host'-option allows to set the IP address or a hostname which the WebUI-server should listen to. E.g. by setting 0.0.0.0 or :: as address. Update documentation for new option. Update shell completion for new option. Compilation seems to add another go-gitlab version. --- commands/webui.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'commands/webui.go') diff --git a/commands/webui.go b/commands/webui.go index 7e5fc752..d910a703 100644 --- a/commands/webui.go +++ b/commands/webui.go @@ -4,9 +4,11 @@ import ( "context" "fmt" "log" + "net" "net/http" "os" "os/signal" + "strconv" "time" "github.com/99designs/gqlgen/graphql/playground" @@ -27,6 +29,7 @@ import ( const webUIOpenConfigKey = "git-bug.webui.open" type webUIOptions struct { + host string port int open bool noOpen bool @@ -54,9 +57,10 @@ Available git config: flags := cmd.Flags() flags.SortFlags = false + flags.StringVar(&options.host, "host", "127.0.0.1", "Network address or hostname to listen to (default to 127.0.0.1)") flags.BoolVar(&options.open, "open", false, "Automatically open the web UI in the default browser") 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 is random)") + 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") return cmd @@ -71,7 +75,7 @@ func runWebUI(env *Env, opts webUIOptions, args []string) error { } } - addr := fmt.Sprintf("127.0.0.1:%d", opts.port) + addr := net.JoinHostPort(opts.host, strconv.Itoa(opts.port)) webUiAddr := fmt.Sprintf("http://%s", addr) router := mux.NewRouter() -- cgit v1.2.3 From 626ec9835b4450fb2994ec931357279700437b6b Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sun, 7 Mar 2021 14:09:15 +0100 Subject: 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(-) (limited to 'commands/webui.go') diff --git a/commands/webui.go b/commands/webui.go index d910a703..3857e968 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 6e4622be..6bed9143 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 ccfaff9a..0cdfd517 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 8f2a0f8f..7c7cd975 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=() -- cgit v1.2.3 From 3a819525d7811dcfb01d928af0e243de4388c456 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 7 Mar 2021 21:44:48 +0100 Subject: 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(-) (limited to 'commands/webui.go') diff --git a/commands/webui.go b/commands/webui.go index 3857e968..2f80bcd0 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 6bed9143..782cba56 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 0cdfd517..2d6be920 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 b13e190e..96040929 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 7c7cd975..0bf62d9a 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 eb9296d4..a1dc129e 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") -- cgit v1.2.3