@rt-tools/agent-kit 0.30.1 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/checks/board.github.mjs +5 -1
- package/assets/defaults/project.sh +3 -0
- package/assets/hooks/git-guard-delivery-body.sh +51 -0
- package/assets/hooks/git-guard-delivery-merge.sh +32 -0
- package/assets/hooks/git-guard-delivery.sh +12 -26
- package/assets/patterns/git-workflow-pr-body.github.md +4 -1
- package/assets/patterns/git-workflow-pr-ready.md +9 -0
- package/package.json +1 -1
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { OfflineError, botToken, gh, ghJson, graphql } from './board-gh.mjs';
|
|
19
19
|
import { declaredEpicOf } from './board-epic-link.mjs';
|
|
20
|
+
import { verdictOnHead } from './board-runs.mjs';
|
|
20
21
|
export { numberFromTaskDir, taskDirs, unstampFolder } from './board-task-dirs.mjs';
|
|
21
22
|
import { CONFIG } from './rt-kit-checks.config.mjs';
|
|
22
23
|
|
|
@@ -186,7 +187,7 @@ export function pullState(ref, options) {
|
|
|
186
187
|
const target = ref === undefined || ref === null || `${ref}`.trim() === '' ? [] : [`${ref}`.trim()];
|
|
187
188
|
let pull;
|
|
188
189
|
try {
|
|
189
|
-
pull = ghJson(['pr', 'view', ...target, '--json', 'number,isDraft,reviewRequests,latestReviews,author,mergeable,headRefName'], options);
|
|
190
|
+
pull = ghJson(['pr', 'view', ...target, '--json', 'number,isDraft,reviewRequests,latestReviews,author,mergeable,headRefName,headRefOid'], options);
|
|
190
191
|
} catch (error) {
|
|
191
192
|
if (error instanceof OfflineError) {
|
|
192
193
|
throw error;
|
|
@@ -214,6 +215,9 @@ export function pullState(ref, options) {
|
|
|
214
215
|
// The head branch: the folder guard judges the branch of the named PR, not the checked-out
|
|
215
216
|
// one — the lower PR of a stack is lifted from the upper branch.
|
|
216
217
|
branch: pull.headRefName ?? null,
|
|
218
|
+
// The run on the tip: `success`, `failure`, `running` or `none`. The merge guard reads it —
|
|
219
|
+
// an epic went into main over a red image build, and the rollout fell after it.
|
|
220
|
+
run: pull.headRefOid ? verdictOnHead(pull.headRefOid, options) : 'none',
|
|
217
221
|
};
|
|
218
222
|
}
|
|
219
223
|
|
|
@@ -359,6 +359,9 @@ rt_pull_token_login() { :; }
|
|
|
359
359
|
# foreign words: a section not named by the tree is not judged at all.
|
|
360
360
|
RT_PULL_BODY_SECTION="${RT_PULL_BODY_SECTION:-}"
|
|
361
361
|
|
|
362
|
+
# The PR body line closing the branch's task (`{number}`); the keyword is the hosting's, so silent.
|
|
363
|
+
RT_PULL_CLOSES_LINE="${RT_PULL_CLOSES_LINE:-}"
|
|
364
|
+
|
|
362
365
|
# The command that moves a task between the columns of the work queue, and the name of the first
|
|
363
366
|
# column — the one the task leaves when it is taken into work. The name has no default: the tree
|
|
364
367
|
# names the columns in its own words, and an invented one would match nothing and silently turn off
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# The body of a PR being opened, for the delivery guard: the section about the remaining step and the
|
|
3
|
+
# line that closes the task.
|
|
4
|
+
#
|
|
5
|
+
# NOT a guard: it has no `rt-hook:` declaration and hooks into no agent event. The delivery guard
|
|
6
|
+
# sources it — one tier of its verdict, moved out when the guard reached its length limit. It uses
|
|
7
|
+
# the guard's own variables — the command, the task number of the branch, both samples — and the
|
|
8
|
+
# guard's `fault`.
|
|
9
|
+
|
|
10
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
11
|
+
|
|
12
|
+
rt_delivery_pull_body() {
|
|
13
|
+
# The body arrives either as an argument or as a file, both are read here; by the time of the
|
|
14
|
+
# parse the file is already written. Neither one nor the other — there is no requirement: a PR
|
|
15
|
+
# without a body is checked by the guard elsewhere. The flag is recognised only as a separate
|
|
16
|
+
# word: the tail `-b` of a branch name in the base argument read as the body flag, and the next
|
|
17
|
+
# word of the command became the body.
|
|
18
|
+
[ -z "$pull_body_section" ] && [ -z "$pull_closes_line" ] && return 0
|
|
19
|
+
command -v perl >/dev/null 2>&1 || return 0
|
|
20
|
+
|
|
21
|
+
local body body_file closes
|
|
22
|
+
body="$(printf '%s' "$cmd" | perl -0ne '
|
|
23
|
+
if (/(?:^|\s)(?:--body|-b)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
|
|
24
|
+
print defined $1 ? $1 : (defined $2 ? $2 : $3);
|
|
25
|
+
}
|
|
26
|
+
' 2>/dev/null)"
|
|
27
|
+
body_file="$(printf '%s' "$cmd" | perl -0ne '
|
|
28
|
+
if (/(?:^|\s)(?:--body-file|-F)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
|
|
29
|
+
print defined $1 ? $1 : (defined $2 ? $2 : $3);
|
|
30
|
+
}
|
|
31
|
+
' 2>/dev/null)"
|
|
32
|
+
[ -z "$body" ] && [ -n "$body_file" ] && [ -f "$body_file" ] && body="$(cat "$body_file" 2>/dev/null)"
|
|
33
|
+
[ -z "$body" ] && return 0
|
|
34
|
+
|
|
35
|
+
# The section about the remaining step: without it the owner merges the PR by the button while
|
|
36
|
+
# the run is still going.
|
|
37
|
+
if [ -n "$pull_body_section" ] && ! printf '%s' "$body" | grep -qE "$pull_body_section"; then
|
|
38
|
+
fault "the body of the request carries no section about the remaining step. The merge button is pressed by a person on the hosting, where there are no guards, and they merge as soon as they see green: all that holds the requirement there is what the owner read on the page. The section stands last and says exactly one thing — whether anything is left before the merge; it is rewritten by the same call that edits the body."
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
# The line that closes the task. Without it the merged task stays open on the board, and the
|
|
42
|
+
# work queue audit names that only after the merge — three PRs of one epic went out so, and the
|
|
43
|
+
# owner closed their tasks by hand. The number is the branch's, not the one the executor
|
|
44
|
+
# remembers.
|
|
45
|
+
if [ -n "$pull_closes_line" ] && [ -n "$number" ]; then
|
|
46
|
+
closes="${pull_closes_line//\{number\}/$number}"
|
|
47
|
+
printf '%s' "$body" | grep -qE "$closes" \
|
|
48
|
+
|| fault "the body of the request carries no line that closes the task #${number}. Without it the task stays open after the merge, and the board shows the merged work as not done. Write the line by the sample of the tree: ${closes}"
|
|
49
|
+
fi
|
|
50
|
+
return 0
|
|
51
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# The run on the tip of a PR being merged, for the delivery guard.
|
|
3
|
+
#
|
|
4
|
+
# NOT a guard: it has no `rt-hook:` declaration and hooks into no agent event. The delivery guard
|
|
5
|
+
# sources it and calls it on a merge command. It uses the guard's own variables — the command and
|
|
6
|
+
# the tree root — and the guard's `fault`.
|
|
7
|
+
|
|
8
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
9
|
+
|
|
10
|
+
rt_delivery_merge_run() {
|
|
11
|
+
# An epic went into main while the run on its tip was red on the image build: the rollout fell,
|
|
12
|
+
# and every next PR into main turned red. The red was on the PR page and was not read.
|
|
13
|
+
#
|
|
14
|
+
# A red and an unfinished run refuse. `none` passes: a PR into an epic branch gets no run at
|
|
15
|
+
# all, and refusing it would refuse every task of an epic. The tier is a network one — no answer
|
|
16
|
+
# from the work queue helper, no demand.
|
|
17
|
+
command -v rt_pull_state >/dev/null 2>&1 || return 0
|
|
18
|
+
local ref pull run name
|
|
19
|
+
ref="$(printf '%s' "$cmd" | sed -nE 's/.*(gh[[:space:]]+pr[[:space:]]+merge)[[:space:]]+([^[:space:];&|-][^[:space:];&|]*).*/\2/p' | head -1)"
|
|
20
|
+
pull="$(cd "$root" && rt_pull_state "$ref" 2>/dev/null)" || return 0
|
|
21
|
+
printf '%s' "$pull" | jq -e '.exists' >/dev/null 2>&1 || return 0
|
|
22
|
+
run="$(printf '%s' "$pull" | jq -r '.run // empty' 2>/dev/null)"
|
|
23
|
+
name="$(printf '%s' "$pull" | jq -r '.number // empty' 2>/dev/null)"
|
|
24
|
+
name="${name:-$ref}"
|
|
25
|
+
case "$run" in
|
|
26
|
+
failure)
|
|
27
|
+
fault "the run on the tip of the request${name:+ #${name}} is red. A merge over red carries the breakage into the branch, and every next request into it turns red. Read the run — gh run list --commit <tip> — fix it in the branch and repeat." ;;
|
|
28
|
+
running)
|
|
29
|
+
fault "the run on the tip of the request${name:+ #${name}} has not finished. A merge before its end carries what it has not checked yet. Wait for its end and read the result by a command." ;;
|
|
30
|
+
esac
|
|
31
|
+
return 0
|
|
32
|
+
}
|
|
@@ -117,6 +117,9 @@ pull_token_hint="${RT_PULL_TOKEN_HINT:-}"
|
|
|
117
117
|
# the pattern is named by the tree, not by the package: the package does not know someone else's
|
|
118
118
|
# words, and an invented default would match nothing.
|
|
119
119
|
pull_body_section="${RT_PULL_BODY_SECTION:-}"
|
|
120
|
+
# The line that closes the task on the merge, with `{number}` in place of the task number. Its keyword
|
|
121
|
+
# belongs to the hosting, so the sample is named by the tree, as the section above.
|
|
122
|
+
pull_closes_line="${RT_PULL_CLOSES_LINE:-}"
|
|
120
123
|
commit_email="${RT_COMMIT_EMAIL:-}"
|
|
121
124
|
tasks_dir="${RT_TASKS_DIR:-}"
|
|
122
125
|
archive_dir="${RT_ARCHIVE_DIR:-}"
|
|
@@ -332,6 +335,10 @@ command -v rt_delivery_draft_ready >/dev/null 2>&1 && rt_delivery_draft_ready
|
|
|
332
335
|
# quotes — that is how it fired on an edit of this very text. A quoted substring cannot be cut off
|
|
333
336
|
# entirely this way, but an accidental mention inside a word or a path no longer gets through.
|
|
334
337
|
if printf '%s' "$cmd" | grep -qE "${RT_CMD_BOUND}(gh[[:space:]]+pr[[:space:]]+merge|glab[[:space:]]+mr[[:space:]]+merge|az[[:space:]]+repos[[:space:]]+pr[[:space:]]+update)([[:space:]]|\$)"; then
|
|
338
|
+
# The run on the tip goes first: the folder tier below leaves the guard early on many paths.
|
|
339
|
+
[ -f "$rt_hooks_dir/git-guard-delivery-merge.sh" ] && . "$rt_hooks_dir/git-guard-delivery-merge.sh" 2>/dev/null
|
|
340
|
+
command -v rt_delivery_merge_run >/dev/null 2>&1 && rt_delivery_merge_run
|
|
341
|
+
deny_faults
|
|
335
342
|
rt_delivery_merge_folder
|
|
336
343
|
fi
|
|
337
344
|
|
|
@@ -457,32 +464,11 @@ elif [ -n "$pull_token_var" ] \
|
|
|
457
464
|
fault "who will open the request cannot be learned: the hosting was not asked, and the command carries no substitution of «${pull_token_var}». Opened by the logged-in account, the request may come out from the very person named as its reviewer, and that is fixed only by reopening.${pull_token_hint:+ Substitute the token: ${pull_token_hint} …}"
|
|
458
465
|
fi
|
|
459
466
|
|
|
460
|
-
# The
|
|
461
|
-
#
|
|
462
|
-
#
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
# argument read as the body flag, and the next word of the command became the body.
|
|
466
|
-
if [ -n "$pull_body_section" ]; then
|
|
467
|
-
body=''
|
|
468
|
-
if command -v perl >/dev/null 2>&1; then
|
|
469
|
-
body="$(printf '%s' "$cmd" | perl -0ne '
|
|
470
|
-
if (/(?:^|\s)(?:--body|-b)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
|
|
471
|
-
print defined $1 ? $1 : (defined $2 ? $2 : $3);
|
|
472
|
-
}
|
|
473
|
-
' 2>/dev/null)"
|
|
474
|
-
body_file="$(printf '%s' "$cmd" | perl -0ne '
|
|
475
|
-
if (/(?:^|\s)(?:--body-file|-F)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
|
|
476
|
-
print defined $1 ? $1 : (defined $2 ? $2 : $3);
|
|
477
|
-
}
|
|
478
|
-
' 2>/dev/null)"
|
|
479
|
-
[ -z "$body" ] && [ -n "$body_file" ] && [ -f "$body_file" ] && body="$(cat "$body_file" 2>/dev/null)"
|
|
480
|
-
fi
|
|
481
|
-
|
|
482
|
-
if [ -n "$body" ] && ! printf '%s' "$body" | grep -qE "$pull_body_section"; then
|
|
483
|
-
fault "the body of the request carries no section about the remaining step. The merge button is pressed by a person on the hosting, where there are no guards, and they merge as soon as they see green: all that holds the requirement there is what the owner read on the page. The section stands last and says exactly one thing — whether anything is left before the merge; it is rewritten by the same call that edits the body."
|
|
484
|
-
fi
|
|
485
|
-
fi
|
|
467
|
+
# The body of the request: the section about the remaining step and the line that closes the task.
|
|
468
|
+
# The subject lives in a helper next door — `git-guard-delivery-body.sh`, by the same technique as
|
|
469
|
+
# the draft above.
|
|
470
|
+
[ -f "$rt_hooks_dir/git-guard-delivery-body.sh" ] && . "$rt_hooks_dir/git-guard-delivery-body.sh" 2>/dev/null
|
|
471
|
+
command -v rt_delivery_pull_body >/dev/null 2>&1 && rt_delivery_pull_body
|
|
486
472
|
|
|
487
473
|
|
|
488
474
|
# The task folder is taken apart before the PR opens, not after the approval: the owner merges as
|
|
@@ -21,7 +21,10 @@ Pattern of the rule `git-workflow`. What must be true — the law
|
|
|
21
21
|
|
|
22
22
|
## The PR is attached to the task
|
|
23
23
|
|
|
24
|
-
The body starts with the link line — by it the board fills the linked PRs field
|
|
24
|
+
The body starts with the link line — by it the board fills the linked PRs field, and by it the task
|
|
25
|
+
closes on the merge. The number in it is the branch's, copied rather than recalled; a tree that
|
|
26
|
+
named the sample of the line in its profile, `RT_PULL_CLOSES_LINE`, gets the opening refused by the
|
|
27
|
+
delivery guard without it. Reviewer,
|
|
25
28
|
assignee and labels are set by the same command, and a PR does not open without them:
|
|
26
29
|
|
|
27
30
|
```bash
|
|
@@ -34,6 +34,15 @@ gh pr ready <номер>
|
|
|
34
34
|
Lifting the draft is the last step of handing the work over, not a separate matter. Until it is
|
|
35
35
|
done, the work is not handed over, however many commits lie in the branch.
|
|
36
36
|
|
|
37
|
+
**A merge the executor was told to make goes after the run on the tip is read by a command.** The
|
|
38
|
+
merge command is refused by the delivery guard on a red or unfinished run; a click on the host's
|
|
39
|
+
button no guard sees, so before it the run is read the same way. An epic went into main over a red
|
|
40
|
+
image build, and the rollout fell after it.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
gh run list --commit "$(gh pr view <номер> --json headRefOid --jq .headRefOid)"
|
|
44
|
+
```
|
|
45
|
+
|
|
37
46
|
## Finish the handed-over first, then take new work
|
|
38
47
|
|
|
39
48
|
An open PR is work in flight: its run ages, its branch lags behind main, its body describes the
|
package/package.json
CHANGED