Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .github/workflows/pull-request-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,19 @@ jobs:
# veryfront-api#45", a /pull/ link). Ordinary prose such as "depends on
# zod" or "waits for the worker" is not one.
ref='(pr |pull request )?(https://github\.com/)?(([a-z0-9_.-]+/)?[a-z0-9_.-]+)?(#|/pull/)[0-9]+'
hold="(do not|don.t) (merge|queue)|merge order|required pair|on hold|hold (until|off|for now)|^[[:space:]]*hold[.!:]?[[:space:]]*$"
hold="(do not|don.t) (merge|queue)|merge order|required pair|on hold|please hold|hold (until|off|for|it|this|the (pr|pull request|change))\b|merge[sd]? first|^[[:space:]]*hold[.!:]?[[:space:]]*$"
Comment thread
kojiwakayama marked this conversation as resolved.
Resolved
dependency="(merged?|merges|lands?|landed) (after|before|with)|blocked (by|on)|depends on|dependent on|wait(s|ing)? (for|on|until)"
# Punctuation, Markdown, a dash or a line break may sit between the
# phrase and the reference ("Depends on: #12", "Blocked by [#12](...)",
# "Depends on `#12`", "Merges after — #12"). Each byte of an en or em
# dash is in the set, so it matches in a UTF-8 or a C locale.
sep='[[:space:]:*_([>"`–—-]*'
body="$(jq -r '.body // ""' "$RUNNER_TEMP/pr.json")"
held_by_body=false
if jq -r '.body // ""' "$RUNNER_TEMP/pr.json" \
| grep -qiE "($hold)|($dependency) $ref"; then
# Here-strings, not pipes: under pipefail an early grep -q exit could
# fail the writer and skip a hold.
if grep -qiE "$hold" <<< "$body" \
|| grep -qiE "($dependency)$sep$ref" <<< "${body//[$'\r\n']/ }"; then
held_by_body=true
fi

Expand Down
19 changes: 18 additions & 1 deletion tests/integration/ci/pull-request-auto-merge-workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface PullRequestFixture {
state?: string;
isDraft?: boolean;
baseRefName?: string;
labels?: string[];
labels?: readonly string[];
body?: string;
armed?: boolean;
inMergeQueue?: boolean;
Expand Down Expand Up @@ -179,11 +179,26 @@ describe("pull request auto-merge workflow", () => {
["a do-not-merge note in the description", { body: "Do not merge yet." }],
["a cross-repository dependency", { body: "Depends on veryfront/veryfront-api#8005." }],
["a dependency on a sibling repository", { body: "Merges after veryfront-api#8005." }],
["a dependency after a colon", { body: "Depends on: #42" }],
["a markdown link dependency", {
body: "Depends on [#123](https://github.com/veryfront/veryfront-api/pull/123)",
}],
["a wrapped dependency", { body: "This depends on\r\n#123 landing." }],
["a merge-first note", { body: "This must merge first." }],
[
"a dependency given as a link",
{ body: "Blocked by https://github.com/veryfront/veryfront-api/pull/8005" },
],
["a wait on a pull request", { body: "Waits for PR #42 to land." }],
["a hold for the release", { body: "Hold for the release." }],
["a request to hold this pull request", { body: "Please hold this PR until Friday." }],
["a please-hold note", { body: "Ready, but please hold." }],
["a hold-it note", { body: "Hold it until the API ships." }],
["an inline-code dependency", { body: "Depends on `#123`" }],
["an inline-code cross-repository dependency", { body: "Blocked by `veryfront-api#45`." }],
["an em dash dependency", { body: "Depends on — #123" }],
["an en dash dependency", { body: "Merges after – veryfront-api#45" }],
["a quoted dependency", { body: 'Waits for "#123" to deploy.' }],
] as const
) {
it(`holds and dequeues a pull request with ${reason}`, async () => {
Expand All @@ -200,6 +215,8 @@ describe("pull request auto-merge workflow", () => {
"The adapter waits for the worker before it replies.",
"Holds: drafts stay out of the queue.",
"Hold the lock while the cache refreshes.",
"The queue holds the job until it finishes.",
"Keep a hold on the handle for the request.",
"Fixes #123 and lands the retry after the timeout change.",
]
) {
Expand Down
Loading