Skip to content

Commit

Permalink
Only check GITHUB_TOKEN once (#5)
Browse files Browse the repository at this point in the history
Only check GITHUB_TOKEN once
  • Loading branch information
Crazybus authored Aug 1, 2019
2 parents c35bd40 + 0cb6177 commit ef393cc
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pratus.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ import (
"golang.org/x/oauth2"
)

func getPRState(owner string, repo string, number int) (state string, statuses []github.RepoStatus, err error) {
func getPRState(owner string, repo string, number int, token string) (state string, statuses []github.RepoStatus, err error) {

ctx := context.Background()
token := os.Getenv("GITHUB_TOKEN")
if token == "" {
fmt.Println("GITHUB_TOKEN must be set, aborting.")
os.Exit(1)
}
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
Expand Down Expand Up @@ -72,6 +67,12 @@ func parseGitHubURL(baseURL string, URL string) (owner string, repo string, numb

func main() {

token := os.Getenv("GITHUB_TOKEN")
if token == "" {
fmt.Println("GITHUB_TOKEN must be set, aborting.")
os.Exit(1)
}

URL := os.Args[1]
gitHubBaseURL := "https://github.com/"

Expand All @@ -89,7 +90,7 @@ func main() {

for {

state, statuses, err := getPRState(owner, repo, number)
state, statuses, err := getPRState(owner, repo, number, token)
if err != nil {
print(err)
continue
Expand Down

0 comments on commit ef393cc

Please sign in to comment.