mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 04:16:25 +00:00
refactor: unify monitor abort lifecycle handling
This commit is contained in:
80
scripts/pr
80
scripts/pr
@@ -664,6 +664,61 @@ validate_changelog_entry_for_pr() {
|
||||
echo "changelog validated: found PR #$pr (contributor handle unavailable, skipping thanks check)"
|
||||
}
|
||||
|
||||
changed_changelog_fragment_files() {
|
||||
git diff --name-only origin/main...HEAD -- changelog/fragments | rg '^changelog/fragments/.*\.md$' || true
|
||||
}
|
||||
|
||||
validate_changelog_fragments_for_pr() {
|
||||
local pr="$1"
|
||||
local contrib="$2"
|
||||
shift 2
|
||||
|
||||
if [ "$#" -lt 1 ]; then
|
||||
echo "No changelog fragments provided for validation."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local pr_pattern
|
||||
pr_pattern="(#$pr|openclaw#$pr)"
|
||||
|
||||
local added_lines
|
||||
local file
|
||||
local all_added_lines=""
|
||||
for file in "$@"; do
|
||||
added_lines=$(git diff --unified=0 origin/main...HEAD -- "$file" | awk '
|
||||
/^\+\+\+/ { next }
|
||||
/^\+/ { print substr($0, 2) }
|
||||
')
|
||||
|
||||
if [ -z "$added_lines" ]; then
|
||||
echo "$file is in diff but no added lines were detected."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
all_added_lines=$(printf '%s\n%s\n' "$all_added_lines" "$added_lines")
|
||||
done
|
||||
|
||||
local with_pr
|
||||
with_pr=$(printf '%s\n' "$all_added_lines" | rg -in "$pr_pattern" || true)
|
||||
if [ -z "$with_pr" ]; then
|
||||
echo "Changelog fragment update must reference PR #$pr (for example, (#$pr))."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -n "$contrib" ] && [ "$contrib" != "null" ]; then
|
||||
local with_pr_and_thanks
|
||||
with_pr_and_thanks=$(printf '%s\n' "$all_added_lines" | rg -in "$pr_pattern" | rg -i "thanks @$contrib" || true)
|
||||
if [ -z "$with_pr_and_thanks" ]; then
|
||||
echo "Changelog fragment update must include both PR #$pr and thanks @$contrib on the entry line."
|
||||
exit 1
|
||||
fi
|
||||
echo "changelog fragments validated: found PR #$pr + thanks @$contrib"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "changelog fragments validated: found PR #$pr (contributor handle unavailable, skipping thanks check)"
|
||||
}
|
||||
|
||||
prepare_gates() {
|
||||
local pr="$1"
|
||||
enter_worktree "$pr" false
|
||||
@@ -684,13 +739,30 @@ prepare_gates() {
|
||||
docs_only=true
|
||||
fi
|
||||
|
||||
# Enforce workflow policy: every prepared PR must include a changelog update.
|
||||
if ! printf '%s\n' "$changed_files" | rg -q '^CHANGELOG\.md$'; then
|
||||
echo "Missing CHANGELOG.md update in PR diff. This workflow requires a changelog entry."
|
||||
local has_changelog_update=false
|
||||
if printf '%s\n' "$changed_files" | rg -q '^CHANGELOG\.md$'; then
|
||||
has_changelog_update=true
|
||||
fi
|
||||
local fragment_files
|
||||
fragment_files=$(changed_changelog_fragment_files)
|
||||
local has_fragment_update=false
|
||||
if [ -n "$fragment_files" ]; then
|
||||
has_fragment_update=true
|
||||
fi
|
||||
# Enforce workflow policy: every prepared PR must include either CHANGELOG.md
|
||||
# or one or more changelog fragments.
|
||||
if [ "$has_changelog_update" = "false" ] && [ "$has_fragment_update" = "false" ]; then
|
||||
echo "Missing changelog update. Add CHANGELOG.md changes or changelog/fragments/*.md entry."
|
||||
exit 1
|
||||
fi
|
||||
local contrib="${PR_AUTHOR:-}"
|
||||
validate_changelog_entry_for_pr "$pr" "$contrib"
|
||||
if [ "$has_changelog_update" = "true" ]; then
|
||||
validate_changelog_entry_for_pr "$pr" "$contrib"
|
||||
fi
|
||||
if [ "$has_fragment_update" = "true" ]; then
|
||||
mapfile -t fragment_file_list <<<"$fragment_files"
|
||||
validate_changelog_fragments_for_pr "$pr" "$contrib" "${fragment_file_list[@]}"
|
||||
fi
|
||||
|
||||
run_quiet_logged "pnpm build" ".local/gates-build.log" pnpm build
|
||||
run_quiet_logged "pnpm check" ".local/gates-check.log" pnpm check
|
||||
|
||||
Reference in New Issue
Block a user