Skip to content

Commit

Permalink
Merge pull request #145 from mboersma/github-access-token
Browse files Browse the repository at this point in the history
fix(main.go): require `GITHUB_ACCESS_TOKEN` to be set
  • Loading branch information
mboersma authored Oct 27, 2016
2 parents 769f926 + ce12d8d commit e1f9e77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ workflowManager v2.2.0 -> v2.2.0 (clean)

It's also possible to output the report in json using the `-o json` argument for easier machine parsing.

Github has a very low ratelimit for unauthenticated api requests. A personal oauth token can be used to bypass this restriction. Create an oauth token with no permission and set it to `$GH_TOKEN` and deisrel will
Github has a very low ratelimit for unauthenticated api requests. A "[personal access token][]" can be used to bypass this restriction. Create a GitHub token with "repo" permission and set it to `$GITHUB_ACCESS_TOKEN`. `deisrel` will
use it when making requests.

# Development
Expand All @@ -122,5 +122,6 @@ Unless required by applicable law or agreed to in writing, software distributed


[issues]: https://github.com/deis/deisrel/issues
[personal access token]: https://github.com/settings/tokens
[prs]: https://github.com/deis/deisrel/pulls
[workflow]: https://github.com/deis/workflow
19 changes: 11 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ import (
var version = "0.0.0" // replaced when building

func main() {
ghclient := github.NewClient(nil)
app := cli.NewApp()

if token, ok := os.LookupEnv("GH_TOKEN"); ok {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
ghclient = github.NewClient(oauth2.NewClient(oauth2.NoContext, ts))
token, ok := os.LookupEnv("GITHUB_ACCESS_TOKEN")
if !ok {
fmt.Println("\"GITHUB_ACCESS_TOKEN\" must be set to a valid GitHub access token.")
os.Exit(1)
}

app := cli.NewApp()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
ghclient := github.NewClient(oauth2.NewClient(oauth2.NoContext, ts))

app.Name = "deisrel"
app.Usage = "Manage deis workflow releases. If you need to bypass the github ratelimit, add set github oauth token (no permissions required) to $GH_TOKEN"
app.Usage = "Manage deis workflow releases."
app.UsageText = "deisrel [options] <chart versions> <repo map>"
app.Version = version
app.Flags = []cli.Flag{
Expand Down

0 comments on commit e1f9e77

Please sign in to comment.