Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a -w option to view uploaded package in web browser" #390

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/base64"
"fmt"
"strings"

"github.com/pkg/browser"
)

func GenerateGraphQLID(prefix, uuid string) string {
Expand All @@ -14,3 +16,14 @@ func GenerateGraphQLID(prefix, uuid string) string {

return graphqlID.String()
}

func OpenInWebBrowser(openInWeb bool, webUrl string) error {
if openInWeb {
err := browser.OpenURL(webUrl)
if err != nil {
fmt.Println("Error opening browser: ", err)
return err
}
}
return nil
}
14 changes: 0 additions & 14 deletions pkg/cmd/build/build.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package build

import (
"fmt"

"github.com/MakeNowJust/heredoc"
"github.com/buildkite/cli/v3/pkg/cmd/factory"
"github.com/buildkite/cli/v3/pkg/cmd/validation"
"github.com/charmbracelet/lipgloss"
"github.com/pkg/browser"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -40,17 +37,6 @@ func NewCmdBuild(f *factory.Factory) *cobra.Command {
return &cmd
}

func openBuildInBrowser(openInWeb bool, webUrl string) error {
if openInWeb {
err := browser.OpenURL(webUrl)
if err != nil {
fmt.Println("Error opening browser: ", err)
return err
}
}
return nil
}

func renderResult(result string) string {
return lipgloss.JoinVertical(lipgloss.Top,
lipgloss.NewStyle().Padding(0, 0).Render(result))
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/build/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
buildResolver "github.com/buildkite/cli/v3/internal/build/resolver"
"github.com/buildkite/cli/v3/internal/io"
pipelineResolver "github.com/buildkite/cli/v3/internal/pipeline/resolver"
"github.com/buildkite/cli/v3/internal/util"
"github.com/buildkite/cli/v3/pkg/cmd/factory"
"github.com/buildkite/go-buildkite/v4"
"github.com/charmbracelet/huh/spinner"
Expand Down Expand Up @@ -84,5 +85,5 @@ func cancelBuild(ctx context.Context, org string, pipeline string, buildId strin

fmt.Printf("%s\n", renderResult(fmt.Sprintf("Build canceled: %s", build.WebURL)))

return openBuildInBrowser(web, build.WebURL)
return util.OpenInWebBrowser(web, build.WebURL)
}
3 changes: 2 additions & 1 deletion pkg/cmd/build/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/MakeNowJust/heredoc"
"github.com/buildkite/cli/v3/internal/io"
"github.com/buildkite/cli/v3/internal/pipeline/resolver"
"github.com/buildkite/cli/v3/internal/util"
"github.com/buildkite/cli/v3/pkg/cmd/factory"
"github.com/buildkite/go-buildkite/v4"
"github.com/charmbracelet/huh/spinner"
Expand Down Expand Up @@ -142,5 +143,5 @@ func newBuild(ctx context.Context, org string, pipeline string, f *factory.Facto

fmt.Printf("%s\n", renderResult(fmt.Sprintf("Build created: %s", build.WebURL)))

return openBuildInBrowser(web, build.WebURL)
return util.OpenInWebBrowser(web, build.WebURL)
}
3 changes: 2 additions & 1 deletion pkg/cmd/build/rebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
buildResolver "github.com/buildkite/cli/v3/internal/build/resolver"
"github.com/buildkite/cli/v3/internal/build/resolver/options"
pipelineResolver "github.com/buildkite/cli/v3/internal/pipeline/resolver"
"github.com/buildkite/cli/v3/internal/util"
"github.com/buildkite/cli/v3/pkg/cmd/factory"
"github.com/buildkite/go-buildkite/v4"
"github.com/charmbracelet/huh/spinner"
Expand Down Expand Up @@ -102,5 +103,5 @@ func rebuild(ctx context.Context, org string, pipeline string, buildId string, w

fmt.Printf("%s\n", renderResult(fmt.Sprintf("Build created: %s", build.WebURL)))

return openBuildInBrowser(web, build.WebURL)
return util.OpenInWebBrowser(web, build.WebURL)
}
12 changes: 11 additions & 1 deletion pkg/cmd/pkg/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"

"github.com/MakeNowJust/heredoc"
"github.com/buildkite/cli/v3/internal/util"
"github.com/buildkite/cli/v3/pkg/cmd/factory"
"github.com/buildkite/go-buildkite/v4"
"github.com/charmbracelet/huh/spinner"
Expand All @@ -23,6 +24,8 @@ type pushPackageConfig struct {
const stdinFileNameFlag = "stdin-file-name"

func NewCmdPackagePush(f *factory.Factory) *cobra.Command {
var web bool

cmd := cobra.Command{
Use: "push registry-name {path/to/file | --stdin-file-name filename -}",
Short: "Push a new package to Buildkite Packages",
Expand All @@ -31,8 +34,14 @@ func NewCmdPackagePush(f *factory.Factory) *cobra.Command {
or via stdin. If passed via stdin, the filename must be provided with the --stdin-file-name flag, as Buildkite
Packages requires a filename for the package.`),
Example: heredoc.Doc(`
Push a package to a Buildkite registry
The web URL of the uploaded package will be printed to stdout.

$ bk package push my-registry my-package.tar.gz
$ cat my-package.tar.gz | bk package push my-registry --stdin-file-name my-package.tar.gz - # Pass package via stdin, note hyphen as the argument

# add -w to open the build in your web browser
$ bk package push my-registry my-package.tar.gz -w
`),
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := loadAndValidateConfig(cmd.Flags(), args)
Expand Down Expand Up @@ -83,11 +92,12 @@ func NewCmdPackagePush(f *factory.Factory) *cobra.Command {

fmt.Fprintf(cmd.OutOrStdout(), "Created package: %s\n", pkg.Name)
fmt.Fprintf(cmd.OutOrStdout(), "View it on the web at: %s\n", pkg.WebURL)
return nil
return util.OpenInWebBrowser(web, pkg.WebURL)
},
}

cmd.Flags().StringP(stdinFileNameFlag, "n", "", "The filename to use for the package, if it's passed via stdin. Invalid otherwise.")
cmd.Flags().BoolVarP(&web, "web", "w", false, "Open in a web browser the package information after it has been uploaded.")

return &cmd
}
Expand Down