From ee4b564b664f9039b2684c1da4c797196d321677 Mon Sep 17 00:00:00 2001 From: SteveRuble Date: Tue, 7 May 2019 10:14:27 -0400 Subject: [PATCH] feat(git): Add git token command. --- bosun.yaml | 2 +- cmd/git.go | 41 +++++++++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/bosun.yaml b/bosun.yaml index c077b2d..4715d7a 100644 --- a/bosun.yaml +++ b/bosun.yaml @@ -6,7 +6,7 @@ appRefs: {} apps: - name: bosun repo: naveego/bosun - version: 0.8.4 + version: 0.8.5 images: [] scripts: - name: publish diff --git a/cmd/git.go b/cmd/git.go index 9c3c931..9841734 100644 --- a/cmd/git.go +++ b/cmd/git.go @@ -36,7 +36,7 @@ func init() { rootCmd.AddCommand(gitCmd) } -func mustGetGithubClient() *github.Client { +func getGithubToken() (string, error) { b := mustGetBosun() ws := b.GetWorkspace() ctx := b.NewContext().WithDir(ws.Path) @@ -49,29 +49,44 @@ func mustGetGithubClient() *github.Client { ws.GithubToken = &bosun.CommandValue{ Command: bosun.Command{ - Script:script, + Script: script, }, } _, err := ws.GithubToken.Resolve(ctx) if err != nil { - log.Fatalf("script failed: %s\nscript:\n%s", err, script) + return "", errors.Errorf("script failed: %s\nscript:\n%s", err, script) } err = b.Save() if err != nil { - log.Fatalf("save failed: %s", err) + return "", errors.Errorf("save failed: %s", err) } } token, err := ws.GithubToken.Resolve(ctx) if err != nil { - log.Fatal("") + return "", err + } + + err = os.Setenv("GITHUB_TOKEN", token) + if err != nil { + return "", err } token, ok := os.LookupEnv("GITHUB_TOKEN") if !ok { - log.Fatal("GITHUB_TOKEN must be set") + return "", errors.Errorf("GITHUB_TOKEN must be set") + } + + return token, nil +} + +func mustGetGithubClient() *github.Client { + + token, err := getGithubToken() + if err != nil { + log.Fatal(err) } ts := oauth2.StaticTokenSource( @@ -89,6 +104,20 @@ var gitDeployCmd = &cobra.Command{ Short: "Deploy-related commands.", } +var gitTokenCmd = addCommand(gitCmd, &cobra.Command{ + Use: "token", + Short: "Prints the github token.", + RunE: func(cmd *cobra.Command, args []string) error { + + token, err := getGithubToken() + if err != nil { + return err + } + fmt.Println(token) + return nil + }, +}) + var gitDeployStartCmd = &cobra.Command{ Use: "start {cluster}", Args: cobra.ExactArgs(1),