pr-auditor: change token, improve diagnostics and filtering (#31273)

This commit is contained in:
Robert Lin 2022-02-16 08:41:18 -08:00 committed by GitHub
parent 624575aadf
commit cb4896646a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

View File

@ -15,5 +15,5 @@ jobs:
- run: ./dev/pr-auditor/check-pr.sh
env:
GITHUB_EVENT_PATH: ${{ env.GITHUB_EVENT_PATH }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
GITHUB_RUN_URL: https://github.com/sourcegraph/sourcegraph/actions/runs/${{ github.run_id }}

View File

@ -49,13 +49,21 @@ func main() {
if err := json.Unmarshal(payloadData, &payload); err != nil {
log.Fatal("Unmarshal: ", err)
}
log.Printf("got event for pull request %s, full payload: %+v\n", payload.PullRequest.URL, payload)
log.Printf("handling event for pull request %s, payload: %+v\n", payload.PullRequest.URL, payload.Dump())
// Discard unwanted events
if payload.PullRequest.Base.Ref != "main" {
log.Printf("unknown pull request base %q - discarding\n", payload.PullRequest.Base.Ref)
return
}
if payload.PullRequest.Draft {
log.Printf("skipping event on draft PR")
return
}
if payload.Action == "closed" && !payload.PullRequest.Merged {
log.Println("ignoring closure of un-merged pull request")
return
}
if payload.Action == "edited" && payload.PullRequest.Merged {
log.Println("ignoring edit of already-merged pull request")
return

View File

@ -1,6 +1,9 @@
package main
import "strings"
import (
"fmt"
"strings"
)
// EventPayload describes the payload of the pull_request event we subscribe to:
// https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request
@ -10,10 +13,16 @@ type EventPayload struct {
Repository RepositoryPayload `json:"repository"`
}
func (p EventPayload) Dump() string {
return fmt.Sprintf(`Action: %s, PullRequest: { Merged: %v, MergedBy: %+v, Head: %+v }, Repository: %s`,
p.Action, p.PullRequest.Merged, p.PullRequest.MergedBy, p.PullRequest.Head, p.Repository.FullName)
}
type PullRequestPayload struct {
Number int `json:"number"`
Title string `json:"title"`
Body string `json:"body"`
Draft bool `json:"draft"`
ReviewComments int `json:"review_comments"`