mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 19:21:50 +00:00
pr-auditor: change token, improve diagnostics and filtering (#31273)
This commit is contained in:
parent
624575aadf
commit
cb4896646a
2
.github/workflows/pr-auditor.yml
vendored
2
.github/workflows/pr-auditor.yml
vendored
@ -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 }}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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"`
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user