diff --git a/scripts/release_handoff.py b/scripts/release_handoff.py index d1df9a4..e1cff39 100644 --- a/scripts/release_handoff.py +++ b/scripts/release_handoff.py @@ -70,7 +70,7 @@ def resolve(task, event): return sha, sha -def frozen_approval(task_id): +def frozen_approval(task_id, comment_id=None): """An owner reply to the specific, unedited scope preview authorizes this immutable local plan.""" path = DIRECTORY / (task_id + '.preview.json') if not path.exists(): @@ -81,8 +81,11 @@ def frozen_approval(task_id): cd.require(parent.get('content') == saved['content'], 'scope preview has changed') replies = [r for r in rows if r.get('parentId') == saved['comment'] and author(r) == cd.RELEASE_OWNER and (r.get('author') or {}).get('type') == 'human' and not r.get('runId')] - if replies and max(replies, key=lambda r: r['createdAt'])['content'].strip() == '确认范围': - return saved['plan'] + if replies: + latest = max(replies, key=lambda r: r['createdAt']) + if ((comment_id is None or latest['id'] == comment_id) + and latest['content'].strip() in ('确认范围', '「确认范围」')): + return saved['plan'] return None @@ -172,7 +175,7 @@ def main(): if args.action == 'preflight': return preflight(task, args.comment) if args.action == 'scope': - cd.require(author(row) == cd.RELEASE_OWNER and row['content'].strip() == '确认范围' and frozen_approval(task['id']), + cd.require(frozen_approval(task['id'], row['id']), 'require the release owner reply on the exact scope preview') return coordinator.queue(task['id']) return qa(task, row) diff --git a/scripts/test_release_handoff.py b/scripts/test_release_handoff.py index 7d17c15..8b629fa 100644 --- a/scripts/test_release_handoff.py +++ b/scripts/test_release_handoff.py @@ -31,6 +31,10 @@ class ReleaseHandoffTest(unittest.TestCase): 'author': {'id': h.cd.RELEASE_OWNER, 'type': 'human'}} with patch.object(h, 'comments', return_value=[parent, reply]): self.assertEqual(h.frozen_approval('task'), saved['plan']) + quoted = dict(reply, content='「确认范围」') + with patch.object(h, 'comments', return_value=[parent, quoted]): + self.assertEqual(h.frozen_approval('task', 'ok'), saved['plan']) + self.assertIsNone(h.frozen_approval('task', 'other')) for bad in (dict(reply, parentId=None), dict(reply, runId='agent-run'), dict(reply, content='先不确认范围')): with patch.object(h, 'comments', return_value=[parent, bad]): self.assertIsNone(h.frozen_approval('task'))