Skip to content

Commit

Permalink
Add rate limiting debug
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis <[email protected]>
  • Loading branch information
alexellis committed Oct 8, 2017
1 parent 2fe57ce commit 8b3efbe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions commentHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ func handleComment(req types.IssueCommentOuter) {

if allowed {
client, ctx := makeClient()
_, _, err := client.Issues.AddLabelsToIssue(ctx, req.Repository.Owner.Login, req.Repository.Name, req.Issue.Number, []string{command.Value})
_, res, err := client.Issues.AddLabelsToIssue(ctx, req.Repository.Owner.Login, req.Repository.Name, req.Issue.Number, []string{command.Value})
if err != nil {
log.Fatalln(err)
log.Fatalf("%s, limit: %d, remaining: %d", err, res.Limit, res.Remaining)
}

fmt.Println("Label added successfully or already existed.")
}
break
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ func main() {
handleComment(req)
break
default:
log.Fatalln("X_Github_Event want: ['pull_request', 'comment'], got: " + eventType)
log.Fatalln("X_Github_Event want: ['pull_request', 'issue_comment'], got: " + eventType)
}
}
10 changes: 6 additions & 4 deletions handler.go → pullRequestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func handlePullRequest(req types.PullRequestOuter) {

if hasNoDcoLabel(issue) == false {
fmt.Println("Applying label")
_, _, assignLabelErr := client.Issues.AddLabelsToIssue(ctx, req.Repository.Owner.Login, req.Repository.Name, req.PullRequest.Number, []string{"no-dco"})
_, res, assignLabelErr := client.Issues.AddLabelsToIssue(ctx, req.Repository.Owner.Login, req.Repository.Name, req.PullRequest.Number, []string{"no-dco"})
if assignLabelErr != nil {
log.Fatal(assignLabelErr)
log.Fatalf("%s limit: %d, remaining: %d", assignLabelErr, res.Limit, res.Remaining)
}

link := fmt.Sprintf("https://github.com/%s/%s/blob/master/CONTRIBUTING.md", req.Repository.Owner.Login, req.Repository.Name)
Expand All @@ -59,16 +59,18 @@ That's something we need before your Pull Request can be merged. Please see our

comment, resp, err := client.Issues.CreateComment(ctx, req.Repository.Owner.Login, req.Repository.Name, req.PullRequest.Number, comment)
if err != nil {
log.Fatalf("%s limit: %d, remaining: %d", assignLabelErr, resp.Limit, resp.Remaining)
log.Fatal(err)
}
fmt.Println(comment, resp.Rate)
}
} else {
fmt.Println("Things look OK right now.")
issue, _, labelErr := client.Issues.Get(ctx, req.Repository.Owner.Login, req.Repository.Name, req.PullRequest.Number)
issue, res, labelErr := client.Issues.Get(ctx, req.Repository.Owner.Login, req.Repository.Name, req.PullRequest.Number)

if labelErr != nil {
log.Fatalln(labelErr)
log.Fatalf("%s limit: %d, remaining: %d", labelErr, res.Limit, res.Remaining)
log.Fatalln()
}

if hasNoDcoLabel(issue) {
Expand Down

0 comments on commit 8b3efbe

Please sign in to comment.