Skip to content

Commit

Permalink
feat(git): Add git token command.
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveRuble committed May 7, 2019
1 parent fdaee95 commit ee4b564
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bosun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ appRefs: {}
apps:
- name: bosun
repo: naveego/bosun
version: 0.8.4
version: 0.8.5
images: []
scripts:
- name: publish
Expand Down
41 changes: 35 additions & 6 deletions cmd/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand All @@ -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),
Expand Down

0 comments on commit ee4b564

Please sign in to comment.