Skip to content

Commit

Permalink
Fix case-sensitive build flags and use last commit instead of first
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Matt committed Mar 17, 2018
1 parent 8df848c commit 02ae6c5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,16 @@ func webhook(w http.ResponseWriter, r *http.Request) {
}

// check PR title and body for [ci] or [ci skip] flag
if pr.Title != nil && strings.Contains(strings.ToLower(*pr.Title),
if pr.Title != nil && strings.Contains(pr.GetTitle(),
fmt.Sprintf("[%s]", buildFlag)) {
flagExists = true
} else if pr.Body != nil && strings.Contains(strings.ToLower(*pr.Body),
} else if pr.Body != nil && strings.Contains(pr.GetBody(),
fmt.Sprintf("[%s]", buildFlag)) {
flagExists = true
} else {
// check labels for build flag if we haven't already found it
for _, label := range pr.Labels {
if label.Name != nil && strings.Contains(
strings.ToLower(label.GetName()), buildFlag) {
if label.Name != nil && strings.Contains(label.GetName(), buildFlag) {
flagExists = true
break
}
Expand All @@ -106,14 +105,15 @@ func webhook(w http.ResponseWriter, r *http.Request) {
if !flagExists {
// last but not least check the commit message for flags
client := github.NewClient(nil)
commits, _, err := client.PullRequests.ListCommits(context.Background(),
commits, _, err := client.PullRequests.ListCommits(
context.Background(),
pr.GetHead().GetUser().GetLogin(),
pr.GetHead().GetRepo().GetName(),
pr.GetNumber(), &github.ListOptions{})

if err == nil && len(commits) > 0 {
// check only last commit since older ones are irrelevant
commitMsg := strings.ToLower(commits[0].GetCommit().GetMessage())
commitMsg := commits[len(commits)-1].GetCommit().GetMessage()
flagExists = strings.Contains(
commitMsg, fmt.Sprintf("[%s]", buildFlag))
} else {
Expand Down

0 comments on commit 02ae6c5

Please sign in to comment.