@windyroad/risk-scorer 0.18.20 → 0.19.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.
@@ -310,5 +310,5 @@
310
310
  }
311
311
  },
312
312
  "name": "wr-risk-scorer",
313
- "version": "0.18.20"
313
+ "version": "0.19.0"
314
314
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wr-risk-scorer",
3
- "version": "0.18.20",
3
+ "version": "0.19.0",
4
4
  "description": "Pipeline risk scoring, commit/push gates, and secret leak detection",
5
5
  "author": {
6
6
  "name": "Windy Road Technology",
@@ -4,7 +4,8 @@
4
4
  # - Gates `npm run push:watch` on push risk score (TTL + drift + threshold).
5
5
  # - Gates `npx changeset` / `npm run changeset` on release + push risk (back-pressure).
6
6
  # - Gates `npm run release:watch` on release risk score (TTL + drift + threshold).
7
- # - Blocks `gh pr merge` and directs to npm run release:watch.
7
+ # - Blocks `gh pr merge` of the changeset release PR and directs to
8
+ # npm run release:watch. Ordinary feature-branch PRs merge normally.
8
9
 
9
10
  set -euo pipefail
10
11
 
@@ -160,8 +161,57 @@ if echo "$COMMAND" | grep -qE '(^|;|&&|\|\|)\s*npm run release:watch(\s|$)'; the
160
161
  exit 0
161
162
  fi
162
163
 
163
- # Match gh pr merge. Should go via npm run release:watch instead.
164
+ # Match gh pr merge. The changeset release PR should go via
165
+ # npm run release:watch instead -- merging it flips the publish boundary,
166
+ # and release:watch is what watches the pipeline afterwards. An ordinary
167
+ # feature or worktree branch PR merging into main is not that, so it
168
+ # merges normally.
169
+ #
170
+ # The head branch decides which one this is. Resolving it needs the
171
+ # network, so the lookup is bounded and fails closed: any failure (no gh,
172
+ # no auth, no repo, timeout, unexpected output) falls through to the
173
+ # release-PR deny rather than waving a merge through unchecked.
164
174
  if echo "$COMMAND" | grep -qE '(^|;|&&|\|\|)\s*gh pr merge(\s|$)'; then
175
+ # `gh pr merge` takes a number, URL, or branch -- or nothing at all,
176
+ # in which case it resolves the current branch's PR. Flags can come
177
+ # in any order, so the selector is the first non-flag token after
178
+ # `merge`, and no selector is a valid (and common) shape.
179
+ PR_SELECTOR=$(echo "$COMMAND" \
180
+ | sed -E 's/.*gh pr merge//' \
181
+ | tr ' ' '\n' \
182
+ | grep -vE '^(-.*)?$' \
183
+ | head -1) || true
184
+
185
+ # The exit status is captured so a failure lands on the fail-closed
186
+ # branch below rather than on errexit / the err trap -- same shape as
187
+ # check_ci_status in lib/risk-gate.sh. The bound is not: stock macOS
188
+ # ships no GNU `timeout`, and that is the common adopter path, so an
189
+ # unreachable network would stall the merge indefinitely there.
190
+ # perl's alarm is the portable fallback -- perl ships with git.
191
+ HEAD_REF=""
192
+ GH_EXIT=0
193
+ if command -v timeout >/dev/null 2>&1; then
194
+ HEAD_REF=$(timeout 10s gh pr view ${PR_SELECTOR:+"$PR_SELECTOR"} \
195
+ --json headRefName -q .headRefName 2>/dev/null) || GH_EXIT=$?
196
+ elif command -v perl >/dev/null 2>&1; then
197
+ HEAD_REF=$(perl -e 'alarm 10; exec @ARGV' \
198
+ gh pr view ${PR_SELECTOR:+"$PR_SELECTOR"} \
199
+ --json headRefName -q .headRefName 2>/dev/null) || GH_EXIT=$?
200
+ else
201
+ HEAD_REF=$(gh pr view ${PR_SELECTOR:+"$PR_SELECTOR"} \
202
+ --json headRefName -q .headRefName 2>/dev/null) || GH_EXIT=$?
203
+ fi
204
+
205
+ # The changesets action lets adopters name the release branch, so the
206
+ # prefix is overridable rather than assumed. Prefix-anchored, so a
207
+ # branch merely named like it (wip-changeset-release/x) is not swept
208
+ # into the deny.
209
+ RELEASE_BRANCH_PREFIX="${WR_RELEASE_BRANCH_PREFIX:-changeset-release/}"
210
+ if [ "$GH_EXIT" = "0" ] && [ -n "$HEAD_REF" ] \
211
+ && [ "${HEAD_REF#"$RELEASE_BRANCH_PREFIX"}" = "$HEAD_REF" ]; then
212
+ exit 0
213
+ fi
214
+
165
215
  # Check if the project has a release:watch script
166
216
  if [ -f "package.json" ] && python3 -c "
167
217
  import json, sys
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windyroad/risk-scorer",
3
- "version": "0.18.20",
3
+ "version": "0.19.0",
4
4
  "description": "Pipeline risk scoring, commit/push gates, and secret leak detection",
5
5
  "scripts": {
6
6
  "prepack": "node scripts/sync-codex-skills.mjs --pack",