Skip to content

Commit d39e0dc

Browse files
committed
Add an option for muting GitHub merge queue internal operations
When using [GitHub merge queues](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-a-merge-queue), GitHub still sends `push` webhooks for the internal branches that are used, which can be quite spammy. Add an option for dropping these events on the floor, because they're spammy and not useful. Note that this also silences check suite results - this might not be desired, because it can be useful to know when the merge queue's check has failed since this will probably block the PR from merging.
1 parent d99dbd7 commit d39e0dc

5 files changed

Lines changed: 72 additions & 33 deletions

File tree

dispatcher/dispatcher.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import (
1010
// Take a string, parse out the recipients, and send to IRC.
1111
//
1212
// eg:
13-
// hello world [goes to default channel]
14-
// #test hello world [goes to #test, if joined]
15-
// #test,@alice hello world [goes to #test and alice]
16-
// #* hello world [goes to all channels bot is in]
13+
//
14+
// hello world [goes to default channel]
15+
// #test hello world [goes to #test, if joined]
16+
// #test,@alice hello world [goes to #test and alice]
17+
// #* hello world [goes to all channels bot is in]
1718
func Send(irc *irc.Connection, msg string, log loggo.Logger, origin string) {
1819
channels := viper.GetStringSlice("irc.channels")
1920

examples/irccat.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
},
1515
"grafana": "#channel",
1616
"github": {
17-
"secret": "my_secret",
18-
"default_channel": "#irccat-dev",
19-
"repositories": {
20-
"irccat": "#irccat-dev"
21-
}
22-
}
17+
"secret": "my_secret",
18+
"default_channel": "#irccat-dev",
19+
"mute_merge_queues": true,
20+
"repositories": {
21+
"irccat": "#irccat-dev"
22+
}
23+
}
2324
}
2425
},
2526
"irc": {
@@ -35,8 +36,12 @@
3536
"sasl_external": false,
3637
"sasl_login": "",
3738
"sasl_pass": "",
38-
"channels": ["#channel"],
39-
"keys": {"#channel": "join_key"}
39+
"channels": [
40+
"#channel"
41+
],
42+
"keys": {
43+
"#channel": "join_key"
44+
}
4045
},
4146
"commands": {
4247
"auth_channel": "#channel",

httplistener/generic_test.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,43 @@
77
//
88
// mismatch
99
//
10-
// $ echo "%BOLDhw" | curl -d @- http://localhost/send
11-
// 400 Bad Request
10+
// $ echo "%BOLDhw" | curl -d @- http://localhost/send
11+
// 400 Bad Request
1212
//
1313
// urlencoded
1414
//
15-
// $ echo "%BOLDhw" | curl --data-urlencode @- http://localhost/send
16-
// 200 OK
15+
// $ echo "%BOLDhw" | curl --data-urlencode @- http://localhost/send
16+
// 200 OK
1717
//
1818
// urlencoded non-printable
1919
//
20-
// $ printf "\x02hw" | curl --data-urlencode @- http://localhost/send
21-
// 200 OK
20+
// $ printf "\x02hw" | curl --data-urlencode @- http://localhost/send
21+
// 200 OK
2222
//
2323
// octetstream
2424
//
25-
// $ echo "%BOLDhw" | curl --data-binary @- \
26-
// -H 'Content-Type: application/octet-stream' http://localhost/send
27-
// 200 OK
25+
// $ echo "%BOLDhw" | curl --data-binary @- \
26+
// -H 'Content-Type: application/octet-stream' http://localhost/send
27+
// 200 OK
2828
//
2929
// multipart quoted-printable
3030
//
31-
// $ echo '%BOLDhw' | curl -F 'foo=@-;encoder=quoted-printable' \
32-
// http://localhost/send
33-
// 200 OK
31+
// $ echo '%BOLDhw' | curl -F 'foo=@-;encoder=quoted-printable' \
32+
// http://localhost/send
33+
// 200 OK
3434
//
3535
// multipart 8bit
3636
//
37-
// $ echo '%BOLDhw' | curl -F 'foo=@-;encoder=8bit' http://localhost/send
38-
// 200 OK
37+
// $ echo '%BOLDhw' | curl -F 'foo=@-;encoder=8bit' http://localhost/send
38+
// 200 OK
3939
//
4040
// multipart base64
4141
//
42-
// $ echo '%BOLDhw' | curl -F 'foo=@-;encoder=base64' http://localhost/send
43-
// 200 OK
42+
// $ echo '%BOLDhw' | curl -F 'foo=@-;encoder=base64' http://localhost/send
43+
// 200 OK
4444
//
4545
// The gist is that when strict mode is active, popular encodings will work
4646
// while mismatches won't, even though they may still appear to at times.
47-
//
4847
package httplistener
4948

5049
import (
@@ -72,7 +71,7 @@ func genericTestStartHTTPServer(t *testing.T, endpoint string) {
7271

7372
http.HandleFunc(endpoint, hl.genericHandler)
7473
go hl.http.ListenAndServe()
75-
t.Cleanup(func() {hl.http.Shutdown(context.Background());})
74+
t.Cleanup(func() { hl.http.Shutdown(context.Background()) })
7675
time.Sleep(time.Millisecond)
7776
}
7877

@@ -86,7 +85,7 @@ func genericTestSendOutput(message []byte) ([]byte, error) {
8685
return nil, err
8786
}
8887
b := make([]byte, 1024)
89-
_ , err = io.ReadAtLeast(conn, b, 24)
88+
_, err = io.ReadAtLeast(conn, b, 24)
9089
if err != nil {
9190
return nil, err
9291
}
@@ -99,7 +98,7 @@ func runGeneric(t *testing.T, reqFileName string) (string, string) {
9998
genericSender = func(_ *irc.Connection, m string, _ loggo.Logger, _ string) {
10099
message = m
101100
}
102-
t.Cleanup(func(){genericSender = origSender})
101+
t.Cleanup(func() { genericSender = origSender })
103102

104103
src, err := os.ReadFile(path.Join("testdata", reqFileName))
105104
if err != nil {
@@ -201,7 +200,7 @@ func TestGeneric(t *testing.T) {
201200
if err != nil {
202201
t.Error(err)
203202
}
204-
t.Cleanup(func() {loggo.DefaultContext().AddWriter("default", writer)})
203+
t.Cleanup(func() { loggo.DefaultContext().AddWriter("default", writer) })
205204
genericTestStartHTTPServer(t, "/send")
206205

207206
t.Run("Baseline", testGenericBaseline)

httplistener/github.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ func interestingIssueAction(action string) bool {
1616
return false
1717
}
1818

19+
func isMergeQueueBranch(ref string) bool {
20+
return strings.HasPrefix(ref, "gh-readonly-queue/") || strings.HasPrefix(ref, "refs/heads/gh-readonly-queue/")
21+
}
22+
1923
func (hl *HTTPListener) githubHandler(w http.ResponseWriter, request *http.Request) {
2024
if request.Method != "POST" {
2125
http.NotFound(w, request)
@@ -57,6 +61,9 @@ func (hl *HTTPListener) githubHandler(w http.ResponseWriter, request *http.Reque
5761
}
5862
case github.PushPayload:
5963
pl := payload.(github.PushPayload)
64+
if viper.GetBool("http.listeners.github.mute_merge_queues") && isMergeQueueBranch(pl.Ref) {
65+
return
66+
}
6067
send = true
6168
msgs, err = hl.renderTemplate("github.push", payload)
6269
repo = pl.Repository.Name
@@ -84,6 +91,9 @@ func (hl *HTTPListener) githubHandler(w http.ResponseWriter, request *http.Reque
8491
case github.CheckSuitePayload:
8592
pl := payload.(github.CheckSuitePayload)
8693
if pl.CheckSuite.Status == "completed" && pl.CheckSuite.Conclusion == "failure" {
94+
if viper.GetBool("http.listeners.github.mute_merge_queues") && isMergeQueueBranch(pl.CheckSuite.HeadBranch) {
95+
return
96+
}
8797
send = true
8898
msgs, err = hl.renderTemplate("github.checksuite", payload)
8999
repo = pl.Repository.Name

httplistener/github_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package httplistener
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestIsMergeQueueBranch(t *testing.T) {
8+
tests := []struct {
9+
ref string
10+
expected bool
11+
}{
12+
{"refs/heads/master", false},
13+
{"refs/heads/gh-readonly-queue/master/pr-1", true},
14+
{"gh-readonly-queue/master/pr-1", true},
15+
{"main", false},
16+
{"refs/tags/v1.0.0", false},
17+
}
18+
19+
for _, tc := range tests {
20+
if got := isMergeQueueBranch(tc.ref); got != tc.expected {
21+
t.Errorf("isMergeQueueBranch(%q) = %v; want %v", tc.ref, got, tc.expected)
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)