Skip to content

Commit 1bb998d

Browse files
authored
Open LSIF upload page in browser after successful upload (#150)
1 parent 37ba97f commit 1bb998d

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

cmd/src/lsif_upload.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"github.com/kballard/go-shellquote"
2020
"github.com/mattn/go-isatty"
21+
"github.com/pkg/browser"
2122
)
2223

2324
func isFlagSet(fs *flag.FlagSet, name string) bool {
@@ -63,7 +64,8 @@ Examples:
6364
fileFlag = flagSet.String("file", "./dump.lsif", `The path to the LSIF dump file.`)
6465
githubTokenFlag = flagSet.String("github-token", "", `A GitHub access token with 'public_repo' scope that Sourcegraph uses to verify you have access to the repository.`)
6566
rootFlag = flagSet.String("root", "", `The path in the repository that matches the LSIF projectRoot (e.g. cmd/project1). Defaults to the empty string, which refers to the top level of the repository.`)
66-
indexerName = flagSet.String("indexerName", "", `The name of the indexer that generated the dump. This will override the 'toolInfo.name' field in the metadata vertex of the LSIF dump file. This must be supplied if the indexer does not set this field (in which case the upload will fail with an explicit message).`)
67+
indexerNameFlag = flagSet.String("indexerName", "", `The name of the indexer that generated the dump. This will override the 'toolInfo.name' field in the metadata vertex of the LSIF dump file. This must be supplied if the indexer does not set this field (in which case the upload will fail with an explicit message).`)
68+
openFlag = flagSet.Bool("open", false, `Open the LSIF upload page in your browser.`)
6769
apiFlags = newAPIFlags(flagSet)
6870
)
6971

@@ -153,8 +155,8 @@ Examples:
153155
if *rootFlag != "" {
154156
qs.Add("root", *rootFlag)
155157
}
156-
if *indexerName != "" {
157-
qs.Add("indexerName", *indexerName)
158+
if *indexerNameFlag != "" {
159+
qs.Add("indexerName", *indexerNameFlag)
158160
}
159161

160162
url, err := url.Parse(cfg.Endpoint + "/.api/lsif/upload")
@@ -244,10 +246,19 @@ Examples:
244246
return err
245247
}
246248

247-
jobURL := string(base64.URLEncoding.EncodeToString([]byte(fmt.Sprintf(`LSIFUpload:"%s"`, payload.ID))))
249+
uploadID := string(base64.URLEncoding.EncodeToString([]byte(fmt.Sprintf(`LSIFUpload:"%s"`, payload.ID))))
250+
uploadURL := fmt.Sprintf("%s/%s/-/settings/code-intelligence/lsif-uploads/%s", cfg.Endpoint, *repoFlag, uploadID)
251+
248252
fmt.Println("")
249-
fmt.Printf("LSIF dump successfully uploaded. It will be converted asynchronously.\n")
250-
fmt.Printf("To check the status, visit %s/site-admin/lsif-uploads/%s.\n", cfg.Endpoint, jobURL)
253+
fmt.Printf("LSIF dump successfully uploaded for processing.\n")
254+
fmt.Printf("View processing status at %s.\n", uploadURL)
255+
256+
if *openFlag {
257+
if err := browser.OpenURL(uploadURL); err != nil {
258+
return err
259+
}
260+
}
261+
251262
return nil
252263
}
253264

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
github.com/mattn/go-runewidth v0.0.8 // indirect
1515
github.com/neelance/parallel v0.0.0-20160708114440-4de9ce63d14c
1616
github.com/olekukonko/tablewriter v0.0.4 // indirect
17+
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
1718
github.com/pkg/errors v0.9.1
1819
github.com/sourcegraph/go-diff v0.5.1
1920
github.com/sourcegraph/jsonx v0.0.0-20190114210550-ba8cb36a8614

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ github.com/neelance/parallel v0.0.0-20160708114440-4de9ce63d14c h1:NZOii9TDGRAfC
3333
github.com/neelance/parallel v0.0.0-20160708114440-4de9ce63d14c/go.mod h1:eTBvSIlRgLo+CNFFQRQTwUGTZOEdvXIKeZS/xG+D2yU=
3434
github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8=
3535
github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA=
36+
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98=
37+
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
3638
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
3739
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
3840
github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e h1:MZM7FHLqUHYI0Y/mQAt3d2aYa0SiNms/hFqC9qJYolM=

0 commit comments

Comments
 (0)