feat(timer): 碼錶移出領取,等工作樹建成之後才起

原本的順序是「放行 → 設 assignee 與標籤 → 起錶 → 處理分支」,而工作樹建立
失敗會中止整個領取——錶已經起了才失敗,使用者會被計一段什麼都沒做的時間,
而工時要準正是工時報表的立足點。

claim 只留領取鎖的兩件事(assignee 與標籤),起錶交給新的 timer.js,由流程
正本排在 branch-prep 之後。timer 已經跑在這顆議題上時什麼都不做:中斷後重跑
是它最常見的處境,重新起錶會把已經累積的時間切成兩段;跑在別顆上則照舊擋下,
不代勞停錶。

三支腳本讀碼錶的那段各留一份,趁這次收進 lib。

議題 #40

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-17 16:27:43 +08:00
co-authored by Claude Opus 5
parent 5b740c236b
commit 74b4ca130e
5 changed files with 248 additions and 30 deletions
+3 -8
View File
@@ -14,9 +14,8 @@
import {
UNMERGED_COMMENT_NOTE,
countUnmergedComments,
expectOk,
fetchIssue,
giteaRequest,
listStopwatches,
main,
pages,
parseFlags,
@@ -24,6 +23,7 @@ import {
parseRepo,
preflight,
resolveLogin,
stopwatchOnIssue,
} from './lib.js';
import {
checklistInSection,
@@ -118,10 +118,5 @@ async function fetchLinked(login, path, kind) {
* ——領取鎖看的是 assignee。
*/
async function hasRunningStopwatch(login, repo, index) {
const path = '/user/stopwatches';
const watches = expectOk(await giteaRequest(login, 'GET', path), `GET ${path}`) ?? [];
return watches.some(
(watch) => `${watch.repo_owner_name}/${watch.repo_name}` === repo && watch.issue_index === index,
);
return stopwatchOnIssue(await listStopwatches(login), repo, index) !== null;
}