Skip to content

Commit e7edd42

Browse files
committed
Add merge queue support
Supports pull request enqueue/dequeue subevents + ignore spammy events related to merge queue
1 parent 62d55ad commit e7edd42

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ disgit has the following optional environment variables that you can use to cust
1818
- `IGNORED_USERS` - A comma seperated list of users that should be ignored
1919
- `IGNORED_PAYLOADS` - A comma seperated list of webhook events that should be ignored
2020
- `DEBUG_PASTE` - Set to `true` to enable debug embeds.
21+
- `EXECUTE_MERGE_QUEUE_BRANCHES` - Set to `true` to unignore merge queue related branches.
2122

2223
## Supported Events
2324
The following webhook events are supported as of now;

src/env.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface Env {
1111

1212
DEBUG_PASTE: string;
1313
AWAIT_ERRORS: string;
14+
EXECUTE_MERGE_QUEUE_BRANCHES: string;
1415
}
1516

1617
/**
@@ -24,6 +25,7 @@ export class BoundEnv {
2425
readonly githubWebhookSecret: string;
2526
readonly debugPaste: boolean;
2627
readonly awaitErrors: boolean;
28+
readonly executeMergeQueueBranches: boolean;
2729

2830
constructor(env: Env) {
2931
if (typeof env.IGNORED_BRANCHES_REGEX !== 'undefined') {
@@ -35,13 +37,18 @@ export class BoundEnv {
3537
this.githubWebhookSecret = env.GITHUB_WEBHOOK_SECRET;
3638
this.debugPaste = env.DEBUG_PASTE == "true" || env.DEBUG_PASTE == "1";
3739
this.awaitErrors = env.AWAIT_ERRORS == "true" || env.AWAIT_ERRORS == "1";
40+
this.executeMergeQueueBranches = env.EXECUTE_MERGE_QUEUE_BRANCHES == "true" || env.EXECUTE_MERGE_QUEUE_BRANCHES == "1";
3841
}
3942

4043
/**
4144
* @param {String} branch
4245
* @return {boolean}
4346
*/
4447
isIgnoredBranch(branch: string): boolean {
48+
if (!this.executeMergeQueueBranches && branch.startsWith('gh-readonly-queue/')) {
49+
return true;
50+
}
51+
4552
return (this.ignoredBranchPattern && branch.match(this.ignoredBranchPattern) != null) || this.ignoredBranches.includes(branch);
4653
}
4754

src/index.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ function buildEmbed(json: any, event: string, env: BoundEnv): string | null {
148148
case "ready_for_review": {
149149
return buildPullReadyReview(json);
150150
}
151+
case "enqueued": {
152+
return buildPullEnqueue(json);
153+
}
154+
case "dequeued": {
155+
return buildPullDequeue(json);
156+
}
151157
default: {
152158
return null;
153159
}
@@ -308,6 +314,34 @@ function buildPush(json: any, env: BoundEnv): string | null {
308314
);
309315
}
310316

317+
function buildPullEnqueue(json: any): string {
318+
const { pull_request, repository, sender } = json;
319+
320+
const queueUrl = `${repository["html_url"]}/queue/${pull_request.base.ref}`;
321+
322+
return buildEmbedBody(
323+
`[${repository["full_name"]}] Pull request enqueued: #${pull_request.number} ${pull_request.title}`,
324+
pull_request["html_url"],
325+
sender,
326+
16752896,
327+
`[View \`${pull_request.base.ref}\` merge queue](${queueUrl})`
328+
);
329+
}
330+
331+
function buildPullDequeue(json: any): string {
332+
const { pull_request, repository, sender } = json;
333+
334+
const queueUrl = `${repository["html_url"]}/queue/${pull_request.base.ref}`;
335+
336+
return buildEmbedBody(
337+
`[${repository["full_name"]}] Pull request dequeued: #${pull_request.number} ${pull_request.title}`,
338+
pull_request["html_url"],
339+
sender,
340+
13584462,
341+
`[View \`${pull_request.base.ref}\` merge queue](${queueUrl})`
342+
);
343+
}
344+
311345
function buildPullReviewComment(json: any): string {
312346
const { pull_request, comment, repository, sender } = json;
313347

wrangler.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ IGNORED_BRANCHES=""
1010
IGNORED_USERS=""
1111
IGNORED_PAYLOADS=""
1212
DEBUG_PASTE=false
13+
EXECUTE_MERGE_QUEUE_BRANCHES=false
1314

1415
# Uses secrets:
1516
# - GITHUB_WEBHOOK_SECRET

0 commit comments

Comments
 (0)