Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
42 changes: 33 additions & 9 deletions .github/workflows/pull-request-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,40 @@ jobs:
draft="$(jq -r .isDraft "$RUNNER_TEMP/pr.json")"
blocked="$(jq -r '[.labels[].name] | index("blocked") != null' "$RUNNER_TEMP/pr.json")"
armed="$(jq -r '.autoMergeRequest != null' "$RUNNER_TEMP/pr.json")"
# A hold is an explicit instruction, or a merge order or dependency that
# names another pull request ("depends on #123", "merges after
# 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:]]*$"
dependency="(merged?|merges|lands?|landed) (after|before|with)|blocked (by|on)|depends on|dependent on|wait(s|ing)? (for|on|until)"
# A hold is the word "hold" or an explicit instruction, or a merge order
# or dependency that names another pull request ("depends on #123",
# "merge after veryfront-api#45", "blocked by PR 123", a /pull/ link).
# Ordinary prose such as "depends on zod", "waits for the worker" or "the
# reducer merges after each step" is not one.
ref='((pr|pull[[:space:]-]?request)[[:space:]:]*#?[0-9]+|(https://github\.com/)?(([a-z0-9_.-]+/)?[a-z0-9_.-]+)?(#|/pull/)[0-9]+)'
Comment thread
kojiwakayama marked this conversation as resolved.
Resolved
hold="\bhold\b|(do not|don.t) (merge|queue)|merge order|required pair|\bmerge[sd]? first"
Comment thread
kojiwakayama marked this conversation as resolved.
Resolved
Comment thread
kojiwakayama marked this conversation as resolved.
Resolved
# A merge order is an instruction: a present-tense verb or "be/get
# merged", up to two words ("merge right after", "merge this PR after"),
# then the order and directly the pull request. Past tense ("was merged
# with #12") is history.
order="(\b(merge|merges|merging|land|lands|landing)\b|\b(be|get|gets|getting|being) (merged|landed)\b)([[:space:]]+[^[:space:]]+){0,2}[[:space:]]+(after|before|with)|\bafter"
Comment thread
kojiwakayama marked this conversation as resolved.
Resolved
dependency="blocked (by|on)|depends on|dependent on|wait(s|ing)? (for|on|until)"
# A colon, a dash or a line break may sit between a phrase and the
# reference ("Depends on: #12", "Merges after — #12"); a dependency may
# also describe it in up to three words ("blocked by the upstream PR
# #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:]:_–—-]*'
described="$sep([^[:space:]]+[[:space:]]+){0,3}"
named="($order)$sep$ref|($dependency)$described$ref"
Comment thread
kojiwakayama marked this conversation as resolved.
Resolved
body="$(jq -r '.body // ""' "$RUNNER_TEMP/pr.json")"
# Markdown decoration (emphasis, inline code, quotes, <autolinks>, link
# brackets) reads as spaces, so "**Hold.**", "- Hold." and "Depends on
# `#12`" read as written. A link is read twice: by its label, for
# "[#12](...)", and by its target, for "Depends on [API PR](.../pull/12)".
plain="$(sed -E 's/[][*`"<>()~|]/ /g' <<< "$body")"
Comment thread
kojiwakayama marked this conversation as resolved.
Resolved
Comment thread
kojiwakayama marked this conversation as resolved.
Resolved
targets="$(sed -E 's/\[[^]]*\]\(([^)]*)\)/\1/g; s/[][*`"<>()~|]/ /g' <<< "$body")"
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" <<< "$plain" \
|| grep -qiE "$named" <<< "${plain//[$'\r\n']/ }" \
|| grep -qiE "$named" <<< "${targets//[$'\r\n']/ }"; then
held_by_body=true
fi

Expand Down
41 changes: 39 additions & 2 deletions 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,41 @@ 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.' }],
["a list-item hold", { body: "Notes:\n- Hold.\n" }],
["a bold hold", { body: "**Hold.**" }],
["a heading hold", { body: "## Hold\n\nAdds a flag." }],
["a hold on the lock", { body: "Hold the lock on this one." }],
["an autolink dependency", {
body: "Depends on <https://github.com/veryfront/veryfront-api/pull/123>",
}],
["a described link dependency", {
body: "Depends on [API PR](https://github.com/veryfront/veryfront-api/pull/123)",
}],
["a labelled bare number", { body: "Depends on PR 123" }],
["a described dependency", { body: "Blocked by upstream PR #45." }],
["a merge order with words between", { body: "Merge this PR after veryfront-api#45." }],
["a bare after-number order", { body: "Ship after #123." }],
["a get-merged order", { body: "This should get merged after #123." }],
] as const
) {
it(`holds and dequeues a pull request with ${reason}`, async () => {
Expand All @@ -199,7 +229,14 @@ describe("pull request auto-merge workflow", () => {
"This component depends on zod for parsing.",
"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.",
"This behavior emerges first in staging.",
"The sanitizer must withhold it until validation.",
"Increase the timeout threshold for batch imports.",
"The upstream fix was merged with #123.",
"See [the design](https://github.com/veryfront/veryfront-api/pull/7) for context.",
"Raises the PR 123 timeout limit.",
"The reducer merges the lists after sorting them; fixes #123.",
"Fixes #123 and lands the retry after the timeout change.",
]
) {
Expand Down
Loading