feat/issue-extract-contract/main #22
@@ -14,6 +14,7 @@ import {
|
||||
expectOk,
|
||||
giteaRequest,
|
||||
main,
|
||||
pages,
|
||||
parseFlags,
|
||||
parseRepo,
|
||||
preflight,
|
||||
@@ -92,16 +93,20 @@ async function fetchIssue(login, repo, index, path) {
|
||||
*
|
||||
* 已整併的留言會被打上 `+1` reaction(由 sdlc-sync 負責標記),而 Gitea 的留言物件
|
||||
* 不含 reaction,所以只能逐則再查一次。留言多時請求數會跟著長,但這個數字要準
|
||||
* ——它決定下游會不會拿著過期的描述做事。
|
||||
* ——它決定下游會不會拿著過期的描述做事,所以留言也要逐頁讀完,讀不完寧可報錯。
|
||||
*/
|
||||
async function countUnmergedComments(login, repo, commentsPath) {
|
||||
const comments = expectOk(await giteaRequest(login, 'GET', commentsPath), `GET ${commentsPath}`) ?? [];
|
||||
|
||||
let unmerged = 0;
|
||||
for (const comment of comments) {
|
||||
const path = `/repos/${repo}/issues/comments/${comment.id}/reactions`;
|
||||
const reactions = expectOk(await giteaRequest(login, 'GET', path), `GET ${path}`) ?? [];
|
||||
if (!reactions.some((reaction) => reaction.content === '+1')) unmerged += 1;
|
||||
|
||||
for await (const comments of pages(login, commentsPath, {
|
||||
limitCode: 'COMMENT_LIMIT',
|
||||
limitHint: `${commentsPath} 的留言太多,數不完未整併的則數`,
|
||||
})) {
|
||||
for (const comment of comments) {
|
||||
const path = `/repos/${repo}/issues/comments/${comment.id}/reactions`;
|
||||
const reactions = expectOk(await giteaRequest(login, 'GET', path), `GET ${path}`) ?? [];
|
||||
if (!reactions.some((reaction) => reaction.content === '+1')) unmerged += 1;
|
||||
}
|
||||
}
|
||||
return unmerged;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user