@coda-console/review 2.7.1 → 2.8.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.
@@ -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>
package/README.md CHANGED
@@ -2,10 +2,11 @@
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 流程本身
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.0",
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": {
@@ -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}`); }