@coda-console/review 2.7.1 → 2.8.1

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.
@@ -8,7 +8,7 @@
8
8
  它推了新提交、评审通过后按你的批准合并,不再问。
9
9
  删除分支:你勾选后,等 GitHub 确认合并,再删除仍指向该提交的远程源分支;本地分支与工作树保留。
10
10
  部署与发布:合并后按你勾选的,在合并提交上调用项目里声明为这一类的流程(coda:kind)。
11
- PR 在 GitHub 上合并或关闭,运行随之结束。也可以手动发起(传 PR 编号或地址),只评审一次。BPMN 2.0,由 Coda 执行(docs/workflows.md)。 -->
11
+ PR 在 GitHub 上合并或关闭,运行随之结束。也可以手动发起(传 GitHub 返回的 PR 地址),只评审一次。BPMN 2.0,由 Coda 执行(docs/workflows.md)。 -->
12
12
  <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:coda="https://coda.pub/schema/bpmn/1.0"
13
13
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="pull-request-definitions" targetNamespace="https://coda.pub/plugins/review">
14
14
  <message id="dispatch" name="workflow.dispatch" />
@@ -18,9 +18,11 @@
18
18
  <message id="edited" name="pull_request.edited" />
19
19
  <message id="closed" name="pull_request.closed" />
20
20
  <process id="pull-request" name="PR 生命流程" isExecutable="true"
21
- coda:title='PR {{if github.event.number = null then (if review.pr = null then inputs.pr else review.pr) else "#" + string(github.event.number) + " " + github.event.pull_request.title}}'>
21
+ coda:key='=lower case(if github.event.pull_request.html_url != null then github.event.pull_request.html_url
22
+ else if matches(inputs.pr, "^https://github[.]com/[a-z0-9_.-]+/[a-z0-9_.-]+/pull/[1-9][0-9]*$", "i") then inputs.pr else null)'
23
+ coda:title='PR {{if github.event.coda.heard = null then (if review.pr = null then inputs.pr else review.pr) else "#" + string(github.event.number) + " " + github.event.pull_request.title}}'>
22
24
  <extensionElements>
23
- <coda:input name="pr" label="PR" description="PR 编号或地址;不填就评审会话最近开的、这个仓库的 PR" />
25
+ <coda:input name="pr" label="PR 地址" required="true" description="GitHub 返回的完整 PR 地址,不带末尾斜线、查询参数或片段;编号先用 gh pr view 解析。已有未结束运行时复用它" />
24
26
  <coda:input name="focus" label="关注点" description="请评审方特别关注的内容" />
25
27
  </extensionElements>
26
28
  <startEvent id="new" name="PR 新建"><messageEventDefinition messageRef="opened" /></startEvent>
@@ -113,7 +115,7 @@ GitHub 上各项检查用 `gh pr checks {{github.event.pull_request.html_url}}`
113
115
  <conditionExpression xsi:type="tFormalExpression">=review.passed and review.head = github.event.pull_request.head.sha and review.base = github.event.pull_request.base.ref</conditionExpression>
114
116
  </sequenceFlow>
115
117
  <sequenceFlow id="at-limit" sourceRef="whether" targetRef="limit">
116
- <conditionExpression xsi:type="tFormalExpression">=github.event_name != "workflow_dispatch" and number(review.count) >= vars.review.maxReviews</conditionExpression>
118
+ <conditionExpression xsi:type="tFormalExpression">=github.event.coda.heard != null and number(review.count) >= vars.review.maxReviews</conditionExpression>
117
119
  </sequenceFlow>
118
120
  <sequenceFlow id="go" sourceRef="whether" targetRef="review" />
119
121
 
@@ -211,6 +213,9 @@ GitHub 上各项检查用 `gh pr checks {{github.event.pull_request.html_url}}`
211
213
  </endEvent>
212
214
  <endEvent id="fixing" name="等修改"><extensionElements><coda:output name="outcome" value="fixing" /></extensionElements></endEvent>
213
215
  </subProcess>
216
+ <!-- 先手动发起,随后观察到 PR:在同一条运行里接上 PR 的完整流程。 -->
217
+ <boundaryEvent id="opened-while-reviewing" name="观察到 PR" attachedToRef="reviewing"><messageEventDefinition messageRef="opened" /></boundaryEvent>
218
+ <sequenceFlow id="review-opened" sourceRef="opened-while-reviewing" targetRef="opening" />
214
219
  <boundaryEvent id="pushed-while-reviewing" name="新提交" attachedToRef="reviewing"><messageEventDefinition messageRef="synchronize" /></boundaryEvent>
215
220
  <sequenceFlow id="review-pushed" sourceRef="pushed-while-reviewing" targetRef="opening" />
216
221
  <boundaryEvent id="closed-while-reviewing" name="PR 关闭" attachedToRef="reviewing"><messageEventDefinition messageRef="closed" /></boundaryEvent>
@@ -218,7 +223,7 @@ GitHub 上各项检查用 `gh pr checks {{github.event.pull_request.html_url}}`
218
223
  <sequenceFlow id="to-next" sourceRef="reviewing" targetRef="after-reviewing" />
219
224
  <exclusiveGateway id="after-reviewing" name="接下来" default="to-based" />
220
225
  <sequenceFlow id="by-hand" sourceRef="after-reviewing" targetRef="reviewed-by-hand">
221
- <conditionExpression xsi:type="tFormalExpression">=github.event_name = "workflow_dispatch"</conditionExpression>
226
+ <conditionExpression xsi:type="tFormalExpression">=github.event.coda.heard = null</conditionExpression>
222
227
  </sequenceFlow>
223
228
  <sequenceFlow id="to-waiting" sourceRef="after-reviewing" targetRef="waiting">
224
229
  <conditionExpression xsi:type="tFormalExpression">=reviewing.outcome = "fixing"</conditionExpression>
@@ -320,10 +325,20 @@ GitHub 上各项检查用 `gh pr checks {{github.event.pull_request.html_url}}`
320
325
  <boundaryEvent id="not-handled" name="做不了" attachedToRef="handed"><errorEventDefinition /></boundaryEvent>
321
326
  <sequenceFlow id="back-to-approve" sourceRef="not-handled" targetRef="approve" />
322
327
 
323
- <!-- 记下你批准的时刻:之后评审再要求修改(review.changesAt 更晚)这次批准才作废。 -->
328
+ <!-- 记下你批准的时刻和合并后要做的事:之后评审再要求修改(review.changesAt 更晚)这次批准才作废;
329
+ 合并后的删分支、部署、发布与通知都照这里,不论 Coda 先从合并步骤还是先从 GitHub 得知合并了。 -->
324
330
  <scriptTask id="approval" name="记下批准" coda:timeout="5" coda:checkout="false" scriptFormat="bash">
325
- <extensionElements><coda:output name="at" /></extensionElements>
326
- <script>echo "at=$(node -p 'Date.now()')" >> "$GITHUB_OUTPUT"</script>
331
+ <extensionElements>
332
+ <coda:env name="APPROVED" value="=approve" />
333
+ <coda:output name="at" />
334
+ <coda:output name="deleteBranch" />
335
+ <coda:output name="deploy" />
336
+ <coda:output name="release" />
337
+ <coda:output name="releaseKinds" />
338
+ <coda:output name="notify" />
339
+ <coda:output name="what" />
340
+ </extensionElements>
341
+ <script>node "${CODA_PLUGIN_PATH}/scripts/approval.mjs"</script>
327
342
  </scriptTask>
328
343
  <sequenceFlow id="to-premerge" sourceRef="approval" targetRef="premerge" />
329
344
 
@@ -335,7 +350,17 @@ GitHub 上各项检查用 `gh pr checks {{github.event.pull_request.html_url}}`
335
350
  <coda:param name="commit" value="=reviewing.head" />
336
351
  </extensionElements>
337
352
  </serviceTask>
338
- <sequenceFlow id="premerged" sourceRef="premerge" targetRef="merge" />
353
+ <sequenceFlow id="premerged" sourceRef="premerge" targetRef="handing" />
354
+ <!-- 记下交给 GitHub 的是哪个提交:合并期间送到的关闭,合进去的是它才是这条运行交出去的合并(「是批准的合并吗」)。
355
+ 合并前检查没过、还在等人处理时,这一步没跑过。 -->
356
+ <scriptTask id="handing" name="交给 GitHub" coda:timeout="5" coda:checkout="false" scriptFormat="bash">
357
+ <extensionElements>
358
+ <coda:env name="HEAD" value="=reviewing.head" />
359
+ <coda:output name="head" />
360
+ </extensionElements>
361
+ <script>echo "head=$HEAD" >> "$GITHUB_OUTPUT"</script>
362
+ </scriptTask>
363
+ <sequenceFlow id="handed-over" sourceRef="handing" targetRef="merge" />
339
364
  <boundaryEvent id="premerge-broke" name="没通过" attachedToRef="premerge"><errorEventDefinition /></boundaryEvent>
340
365
  <sequenceFlow id="premerge-to-fix" sourceRef="premerge-broke" targetRef="fix-premerge" />
341
366
  <userTask id="fix-premerge" name="合并前检查没通过:处理后答复" coda:status="合并前检查没通过:开 PR 的会话处理中" coda:completeLabel="已处理,再跑检查" coda:rejectLabel="处理不了">
@@ -365,15 +390,10 @@ GitHub 上各项检查用 `gh pr checks {{github.event.pull_request.html_url}}`
365
390
  <coda:env name="URL" value="=github.event.pull_request.html_url" />
366
391
  <coda:env name="HEAD" value="=reviewing.head" />
367
392
  <coda:env name="METHOD" value="=vars.review.mergeMethod" />
368
- <coda:env name="APPROVED" value="=approve" />
393
+ <coda:env name="WHAT" value="=approval.what" />
369
394
  <coda:output name="merged" />
370
395
  <coda:output name="refused" />
371
396
  <coda:output name="reason" />
372
- <coda:output name="deleteBranch" />
373
- <coda:output name="deploy" />
374
- <coda:output name="release" />
375
- <coda:output name="releaseKinds" />
376
- <coda:output name="notify" />
377
397
  </extensionElements>
378
398
  <script>node "${CODA_PLUGIN_PATH}/scripts/merge.mjs"</script>
379
399
  </scriptTask>
@@ -423,7 +443,14 @@ GitHub 上各项检查用 `gh pr checks {{github.event.pull_request.html_url}}`
423
443
  <boundaryEvent id="rebased-while-merging" name="base 变了" attachedToRef="merging"><messageEventDefinition messageRef="edited" /></boundaryEvent>
424
444
  <sequenceFlow id="merging-rebased" sourceRef="rebased-while-merging" targetRef="opening" />
425
445
  <boundaryEvent id="closed-while-merging" name="PR 关闭" attachedToRef="merging"><messageEventDefinition messageRef="closed" /></boundaryEvent>
426
- <sequenceFlow id="merging-ended" sourceRef="closed-while-merging" targetRef="ended" />
446
+ <sequenceFlow id="merging-ended" sourceRef="closed-while-merging" targetRef="approved-merged" />
447
+ <!-- 合并步骤把 PR 交给 GitHub 后,GitHub 的关闭可能先于这一步结束送到:合进去的正是「交给 GitHub」记下的那个提交,
448
+ 就是你批准、也过了合并前检查的合并,照你的选择接着删分支、部署、发布;否则是别处合并或关闭的。 -->
449
+ <exclusiveGateway id="approved-merged" name="是批准的合并吗" default="not-approved" />
450
+ <sequenceFlow id="as-approved-merged" sourceRef="approved-merged" targetRef="deleting-or-not">
451
+ <conditionExpression xsi:type="tFormalExpression">=github.event.pull_request.merged and github.event.pull_request.head.sha = handing.head</conditionExpression>
452
+ </sequenceFlow>
453
+ <sequenceFlow id="not-approved" sourceRef="approved-merged" targetRef="ended" />
427
454
  <sequenceFlow id="to-after-merging" sourceRef="merging" targetRef="after-merging" />
428
455
  <exclusiveGateway id="after-merging" name="接下来" default="to-confirming" />
429
456
  <sequenceFlow id="merged-to-waiting" sourceRef="after-merging" targetRef="waiting">
@@ -460,7 +487,7 @@ GitHub 上各项检查用 `gh pr checks {{github.event.pull_request.html_url}}`
460
487
 
461
488
  <exclusiveGateway id="deleting-or-not" name="删除远程分支吗" default="keep-branch" />
462
489
  <sequenceFlow id="to-delete-branch" sourceRef="deleting-or-not" targetRef="delete-branch">
463
- <conditionExpression xsi:type="tFormalExpression">=merge.deleteBranch</conditionExpression>
490
+ <conditionExpression xsi:type="tFormalExpression">=approval.deleteBranch</conditionExpression>
464
491
  </sequenceFlow>
465
492
  <sequenceFlow id="keep-branch" sourceRef="deleting-or-not" targetRef="delivering-or-not" />
466
493
  <scriptTask id="delete-branch" name="删除远程分支" coda:timeout="5" coda:checkout="false" coda:status="已合并:删除远程分支" scriptFormat="bash">
@@ -474,10 +501,10 @@ GitHub 上各项检查用 `gh pr checks {{github.event.pull_request.html_url}}`
474
501
 
475
502
  <exclusiveGateway id="delivering-or-not" name="部署或发布吗" default="merged-only" />
476
503
  <sequenceFlow id="to-delivering" sourceRef="delivering-or-not" targetRef="delivering">
477
- <conditionExpression xsi:type="tFormalExpression">=merge.deploy or merge.release</conditionExpression>
504
+ <conditionExpression xsi:type="tFormalExpression">=approval.deploy or approval.release</conditionExpression>
478
505
  </sequenceFlow>
479
506
  <sequenceFlow id="merged-only" sourceRef="delivering-or-not" targetRef="merged-here" />
480
- <endEvent id="merged-here" coda:status="已合并" coda:notify="=merge.notify" />
507
+ <endEvent id="merged-here" coda:status="已合并" coda:notify="=approval.notify" />
481
508
 
482
509
  <!-- 部署与发布:项目自己声明哪些流程是部署(coda:kind="deploy")、预览发布(preview)、正式发布(release),这里在合并提交上调用它们;
483
510
  项目没有这一类的流程,这一步直接过去。先部署,再请开 PR 的会话写更新说明、发布。失败时运行失败,交回开 PR 的会话。 -->
@@ -486,7 +513,7 @@ GitHub 上各项检查用 `gh pr checks {{github.event.pull_request.html_url}}`
486
513
  <sequenceFlow id="dl-in" sourceRef="delivering-in" targetRef="deploying" />
487
514
  <exclusiveGateway id="deploying" name="部署吗" default="not-deploying" />
488
515
  <sequenceFlow id="to-deploy" sourceRef="deploying" targetRef="deploy">
489
- <conditionExpression xsi:type="tFormalExpression">=merge.deploy</conditionExpression>
516
+ <conditionExpression xsi:type="tFormalExpression">=approval.deploy</conditionExpression>
490
517
  </sequenceFlow>
491
518
  <sequenceFlow id="not-deploying" sourceRef="deploying" targetRef="releasing" />
492
519
  <serviceTask id="deploy" name="部署" coda:action="run-workflows" coda:status="部署中">
@@ -498,7 +525,7 @@ GitHub 上各项检查用 `gh pr checks {{github.event.pull_request.html_url}}`
498
525
  <sequenceFlow id="deployed" sourceRef="deploy" targetRef="releasing" />
499
526
  <exclusiveGateway id="releasing" name="发布吗" default="deploy-only" />
500
527
  <sequenceFlow id="to-notes" sourceRef="releasing" targetRef="notes">
501
- <conditionExpression xsi:type="tFormalExpression">=merge.release</conditionExpression>
528
+ <conditionExpression xsi:type="tFormalExpression">=approval.release</conditionExpression>
502
529
  </sequenceFlow>
503
530
  <sequenceFlow id="deploy-only" sourceRef="releasing" targetRef="delivered" />
504
531
  <endEvent id="delivered" coda:status="已合并并部署" />
@@ -532,7 +559,7 @@ GitHub 上各项检查用 `gh pr checks {{github.event.pull_request.html_url}}`
532
559
  <sequenceFlow id="to-publish" sourceRef="publishing" targetRef="publish" />
533
560
  <serviceTask id="publish" name="发布" coda:action="run-workflows" coda:status="发布中">
534
561
  <extensionElements>
535
- <coda:param name="kind" value="=merge.releaseKinds" />
562
+ <coda:param name="kind" value="=approval.releaseKinds" />
536
563
  <coda:param name="commit" value="=github.event.pull_request.merge_commit_sha" />
537
564
  <coda:param name="inputs" value="=publishing.inputs" />
538
565
  </extensionElements>
@@ -541,6 +568,6 @@ GitHub 上各项检查用 `gh pr checks {{github.event.pull_request.html_url}}`
541
568
  <endEvent id="released-end" coda:status="已发布" />
542
569
  </subProcess>
543
570
  <sequenceFlow id="to-delivered" sourceRef="delivering" targetRef="delivering-done" />
544
- <endEvent id="delivering-done" coda:notify="=merge.notify" />
571
+ <endEvent id="delivering-done" coda:notify="=approval.notify" />
545
572
  </process>
546
573
  </definitions>
package/README.md CHANGED
@@ -2,16 +2,18 @@
2
2
 
3
3
  `review`:会话开的 PR 从开出来起由流程 `pull-request` 跟着走,一个 PR 一条运行,到合并或关闭才结束。
4
4
  它只用 Coda 流程的公开原语(PR 事件、Agent 步骤、人工任务、调用其他流程),也是写 PR 流程的样例:要不一样的流程,照着它改一份(见文末「改成自己的」)。
5
- 它依赖内置的 GitHub 插件(`extensionDependencies`):PR 事件由 GitHub 插件的「PR 观察」发布,`github-reported-pr` 也是它的命令;装 review 时先装 GitHub 插件,卸载 GitHub 插件时 review 一起卸载。
6
- 运行的标题是「PR #号 标题」(手动发起的是参数 `pr`,留空时评审查出 PR 后是「PR #号(地址)」),卡片上有「检查」「评审」「合并」三段;草稿、叠放的 PR 另有「草稿」「叠放」,选了部署或发布的,合并后再有「部署与发布」。
7
- 也可以 `workflow_run pull-request` 手动发起(参数 `pr`、可选 `focus`):只评审一次、不计次数,不进入合并(手动发起的运行不挂在 PR 上,收不到它的新提交和关闭)。
8
- `pr` 不填时评审会话最近开的、这个仓库的 PR,由 GitHub 插件的命令 `github-reported-pr` 查出(项目里停用了 GitHub 插件就要填)。
5
+ 它依赖内置的 GitHub 插件(`extensionDependencies`):PR 事件由 GitHub 插件的「PR 观察」发布;装 review 时先装 GitHub 插件,卸载 GitHub 插件时 review 一起卸载。
6
+ 运行的标题是「PR #号 标题」(手动发起的是参数 `pr`,评审查出 PR 后是「PR #号(地址)」),卡片上有「检查」「评审」「合并」三段;草稿、叠放的 PR 另有「草稿」「叠放」,选了部署或发布的,合并后再有「部署与发布」。
7
+ 流程通过 `coda:key` 声明 PR 地址为主键:在同一项目中,自动、手动发起共享一条未结束的运行,包括排队、等答复和取消收尾。地址不区分大小写。结束后新请求可再发起;旧请求重试仍返回原运行。
8
+ 也可以 `workflow_run pull-request` 手动发起(必填 `pr`:GitHub 返回的完整 PR 地址,可选 `focus`)。已有运行时返回它,沿用原进度、关注点和结果接收会话;草稿中的运行也照旧等标记为可评审。没有运行时只评审一次、不计次数、不进入合并;如果随后 PR 观察发来事件,在同一条运行里接上完整流程。是否接入完整流程按 `github.event.coda.heard` 判断:手动运行尚未收到事件时为空。
9
+ `pr` 须在创建运行前明确。编号、旧仓库地址或带后缀的链接先用 `gh pr view <编号或链接> --json url --jq .url` 取得 GitHub 返回的地址,再传入;流程不从 origin 猜仓库身份。需要查最近开的 PR 时先用 GitHub 插件的 `github-reported-pr` 找到它,再用 `gh pr view` 确认当前地址。输入不接受编号、末尾斜线、查询参数或片段,避免不同拼写创建不同主键。此版本需要支持 `coda:key` 的 Coda 流程引擎。
9
10
 
10
11
  ```
11
12
  .coda/workflows/pull-request.bpmn 流程本身
12
13
  scripts/checks.mjs 等 GitHub 检查
13
14
  scripts/review.mjs 交叉评审:选评审方、开会话、读结论、写 PR 评论
14
15
  scripts/base.mjs 看 base(叠放)
16
+ scripts/approval.mjs 记下批准:时刻与合并后要做的事
15
17
  scripts/merge.mjs 合并
16
18
  scripts/delete-branch.mjs 合并确认后删除远程源分支
17
19
  scripts/notes.mjs 发布流程的参数(更新说明与 publish)
@@ -78,7 +80,7 @@ prompts/principles/ 评审重点,一项一段,按设置取
78
80
  卡片之前的「看项目有哪些部署、发布」(`workflow-kinds`)查项目在这个提交上有哪几类流程,部署和发布选项只给项目有的那几类(`coda:shown`);
79
81
  比如只有部署流程的项目,面板里有「合并后删除远程分支」「部署」和「全部完成后通知 Agent」。没给的那几项按不勾算。需要 Coda 745f85c 及之后。
80
82
  另有「让 Agent 处理评审意见」:连同你的备注交给开 PR 的会话「处理你交付的评审意见」,它推送后重新评审、再请你批准,它做不了就回到批准卡;以及「关闭 PR」(`gh pr close`)。
81
- - 「合并前检查」:你选了合并后,先「记下批准」的时刻,再在评审通过的提交上调用项目声明的合并前检查(`coda:kind="premerge"`)并等它们结束;
83
+ - 「合并前检查」:你选了合并后,先「记下批准」(`approval.mjs`):批准的时刻,和你勾的删分支、部署、发布、通知(合并后都照它做),再在评审通过的提交上调用项目声明的合并前检查(`coda:kind="premerge"`)并等它们结束;
82
84
  项目没有就直接过去。有一个没通过就交给开 PR 的会话「合并前检查没通过:处理后答复」:改动导致的就推送新提交,照常检查、评审,通过后按你这次的选择合并,不再问;
83
85
  检查本身出了问题就处理好后答复,再跑一遍。它做不了交给你「合并前检查没通过:等你处理」。合并没成功后重试合并不再跑合并前检查(同一个提交已经通过)。
84
86
  需要认识 `premerge` 这一类的 Coda。
@@ -90,6 +92,8 @@ prompts/principles/ 评审重点,一项一段,按设置取
90
92
  - 批准在评审再要求修改时作废:「交叉评审」逐次接力输出最近一次要求修改的时刻 `changesAt`,「记下批准」输出你批准的时刻 `at`,
91
93
  「按原批准合并吗」只在 `at` 晚于 `changesAt` 时不再问你。
92
94
  - 交给 GitHub 后在「等 GitHub 确认」等关闭事件,它带来合并提交;期间有新提交(被移出了合并队列)就从头再来。
95
+ 关闭事件也可能在「合并」这一步结束前就到(合并要几秒,GitHub 先说了):合并前,「交给 GitHub」记下要交出去的提交;合进去的正是它,就照你的勾选接着做,和等到确认的一样。
96
+ 合并前检查没过、还在等人处理时被别处合并,不算这条运行的合并。
93
97
  - 勾选「合并后删除远程分支」时,确认合并后、部署与发布前运行「删除远程分支」(`delete-branch.mjs`)。它从 PR 读取源仓库(包括 fork)与源分支,
94
98
  只删除仍指向这次批准合并的提交的远程分支;本地分支与会话工作树保留。分支或源仓库已删除就跳过,有了其他提交、是默认分支或合并目标分支则保留,原因记在步骤摘要。
95
99
  删除用 Git 的 `--force-with-lease=<ref>:<sha>`,推送期间分支变动也不会误删。读取或删除失败会让运行失败,处理后可从失败处继续,之后再部署与发布。
@@ -99,7 +103,7 @@ prompts/principles/ 评审重点,一项一段,按设置取
99
103
  参数 `notes`(更新说明)与 `publish`(`"true"`)。没声明某个参数的流程不会拿到它;项目没有这一类的流程,这一步直接过去。
100
104
  部署或发布失败时运行失败,结果交回开 PR 的会话,由它查明后手动重跑对应的流程。
101
105
 
102
- - PR 在 GitHub 网页上合并或关闭(不经这条运行的「等 GitHub 确认」),运行随之结束,交出去的任务和卡片撤回,不删除分支、不部署、不发布。
106
+ - PR 在 GitHub 网页上合并或关闭(不经这条运行的「等 GitHub 确认」,也不是上面那种你批准的版本在合并时先送到的关闭),运行随之结束,交出去的任务和卡片撤回,不删除分支、不部署、不发布。
103
107
  - 正常结束只更新运行与卡片、结清等待,不唤醒 Agent;勾选「全部完成后通知 Agent」则在合并及所选删除分支、部署、发布都结束后回传一次。未处理的失败照常回传;手动发起的评审交回结论。
104
108
  - 流程只按检查、评审结果、PR 状态与你的批准推进,不读取作者会话的忙闲、后台任务或其他运行;合并前要先完成的验证写成检查(第 2 步)或合并前检查(第 5 步)。
105
109
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "id": "review",
4
4
  "displayName": "PR 生命流程",
5
5
  "description": "会话开的 PR 从开出来起一条流程:每个新版本先跑项目声明的检查,再请另一家 Agent 评审,要求修改时交给开 PR 的会话处理、有分歧时交给你仲裁;通过后请你批准合并,跑过项目的合并前检查再合并,合并后按你的选择删除远程分支、调用项目的部署和发布流程,PR 合并或关闭时结束。",
6
- "version": "2.7.1",
6
+ "version": "2.8.1",
7
7
  "categories": ["工作流程"],
8
8
  "extensionDependencies": [
9
9
  "github"
@@ -120,7 +120,7 @@
120
120
  }
121
121
  }
122
122
  },
123
- "instructions": "gh pr create 开出即评审,可与验证并行;合并要等别的 PR、升锁或发布的开草稿(-R 写在 --draft 前),说明写明前提,满足后 gh pr ready。只合并进默认分支,叠放的不合。合并前的验证写成流程步骤或 GitHub 必需检查。正常结束只更新状态,任务与失败送到本会话,不要轮询 PR;提前评审用 workflow_run 发起 pull-request,结论交回会话。"
123
+ "instructions": "gh pr create 开出即评审;等其他 PR、升锁或发布的开草稿(-R 在 --draft 前),满足后 gh pr ready。只合并进默认分支;合并前验证声明为流程步骤或 GitHub 必需检查。正常结束只更新状态,任务与失败回本会话,不轮询。手动用 workflow_run 发起 pull-request 前用 gh pr view 取得完整地址传 pr;同 PR 复用未结束运行。"
124
124
  },
125
125
  "license": "MIT",
126
126
  "repository": {
@@ -0,0 +1,16 @@
1
+ // Records the user's approval to merge (../.coda/workflows/pull-request.bpmn「记下批准」): when (`at`: a review asking for
2
+ // changes later voids it), and what they chose to follow the merge (`deleteBranch`, `deploy`, `release`, `releaseKinds`,
3
+ // `notify`, and `what`, the choice as the merge step says it). Put out here, not by the merge step, so that the process
4
+ // follows the choice however it hears of the merge: after the merge step, or from GitHub while that step still runs.
5
+ import { json, output } from './step.mjs';
6
+
7
+ const options = (json('APPROVED', {}) ?? {}).options ?? {};
8
+ const chosen = id => options[id] === true;
9
+ output('at', Date.now());
10
+ output('deleteBranch', chosen('deleteBranch'));
11
+ output('deploy', chosen('deploy'));
12
+ output('release', chosen('preview') || chosen('release'));
13
+ output('releaseKinds', ['preview', 'release'].filter(chosen).join(','));
14
+ output('notify', chosen('notify'));
15
+ output('what', ['合并', ...[['deleteBranch', '合并后删除远程分支'], ['deploy', '部署'], ['preview', '发布预览版'], ['release', '发布正式版'], ['notify', '全部完成后通知 Agent']]
16
+ .filter(([id]) => chosen(id)).map(([, name]) => name)].join(' · '));
package/scripts/merge.mjs CHANGED
@@ -4,23 +4,15 @@
4
4
  // merge a version pushed later. Only into the repository's default branch, as GitHub has the base now: Coda hears that a
5
5
  // base changed only when it next looks, which may be after the user approved. Not merged (based elsewhere, a conflict, a
6
6
  // draft, checks not passed) is no failure of the step: it is put out (`refused`, and the `reason`) for the session that
7
- // opened the pull request to deal with. What the user chose
8
- // to follow the merge is put out for the process (`deleteBranch`, `deploy`, `release`, `releaseKinds`, `notify`).
7
+ // opened the pull request to deal with. What the user chose to follow the merge is put out when they approved
8
+ // (approval.mjs); here it is only said (`WHAT`).
9
9
  import { spawnSync } from 'node:child_process';
10
- import { baseOf, json, output, summary } from './step.mjs';
10
+ import { baseOf, output, summary } from './step.mjs';
11
11
 
12
- const approved = json('APPROVED', {}) ?? {};
13
- const options = approved.options ?? {};
14
- const chosen = id => options[id] === true;
15
12
  const url = process.env.URL, head = process.env.HEAD, method = ['merge', 'rebase', 'squash'].includes(process.env.METHOD) ? process.env.METHOD : 'squash';
16
13
  const number = /\/pull\/(\d+)/.exec(url ?? '')?.[1];
17
14
  if (!number || !/^[0-9a-f]{40,64}$/.test(head ?? '')) { console.error('不知道要合并哪个 PR 的哪个提交'); process.exit(1); }
18
- output('deleteBranch', chosen('deleteBranch'));
19
- output('deploy', chosen('deploy'));
20
- output('release', chosen('preview') || chosen('release'));
21
- output('releaseKinds', ['preview', 'release'].filter(chosen).join(','));
22
- output('notify', chosen('notify'));
23
- const what = ['合并', ...[['deleteBranch', '合并后删除远程分支'], ['deploy', '部署'], ['preview', '发布预览版'], ['release', '发布正式版'], ['notify', '全部完成后通知 Agent']].filter(([id]) => chosen(id)).map(([, name]) => name)].join(' · ');
15
+ const what = process.env.WHAT;
24
16
 
25
17
  const based = await baseOf(url);
26
18
  const elsewhere = based.error ?? (based.base !== based.main ? `base 是 ${based.base},不是默认分支 ${based.main};Coda 得知 base 变了后从头再看` : null);
@@ -27,23 +27,12 @@ const row = Object.keys(reviewers).filter(key => {
27
27
  if (!row) fail(`评审组合里没有适用于${session?.agent ? `「${[session.agent, session.model, session.effort].filter(Boolean).join(' · ')}」` : '这个会话'}的一行`);
28
28
  const reviewer = reviewers[row];
29
29
 
30
- // What is reviewed: the event's pull request, or the one asked for by hand, read with the project's own gh; none asked
31
- // for, the one the session opened last of this repository, as the GitHub plugin knows it (its command github-reported-pr,
32
- // where that plugin applies).
30
+ // What is reviewed: the event's pull request, or the explicit PR used to key this manual run before it started.
33
31
  const event = json('PULL_REQUEST', null), automatic = !!event?.head?.sha;
34
32
  let pr = event;
35
33
  if (!automatic) {
36
- // What it says when it finds none, or cannot look, is why none is reviewed.
37
- const reported = () => {
38
- const found = spawnSync('github-reported-pr', [], { encoding: 'utf8', timeout: 60_000 });
39
- if (found.error) fail(`没有指明要评审的 PR,也没能查会话最近开的 PR:${found.error.code === 'ENOENT'
40
- ? '没有 GitHub 插件的 github-reported-pr(项目里停用了 GitHub 插件时要填 PR)' : `github-reported-pr ${found.error.message}`}`);
41
- if (found.status !== 0) fail(`没有指明要评审的 PR,也没查到会话最近开的 PR:${found.stderr.trim().split('\n').at(-1)
42
- || `github-reported-pr 以 ${found.status ?? found.signal} 退出`}`);
43
- return found.stdout.trim();
44
- };
45
- const asked = (process.env.PR ?? '').trim() || reported();
46
- if (!asked) fail('没有指明要评审的 PR,github-reported-pr 也没有给出');
34
+ const asked = (process.env.PR ?? '').trim();
35
+ if (!asked) fail('请填写 GitHub 返回的完整 PR 地址');
47
36
  let view;
48
37
  try { view = JSON.parse(execFileSync('gh', ['pr', 'view', asked, '--json', 'number,url,title,body,headRefOid,headRefName,baseRefOid,baseRefName'], { encoding: 'utf8' })); }
49
38
  catch (e) { fail(`读不到 PR ${asked}:${e.stderr?.toString().trim() || e.message}`); }