feat/gitea-comment-pagination/main #78
@@ -31,16 +31,15 @@ main(async () => {
|
|||||||
const repo = parseRepo(flags.repo);
|
const repo = parseRepo(flags.repo);
|
||||||
const index = parseIndex(flags.index);
|
const index = parseIndex(flags.index);
|
||||||
const issuePath = `/repos/${repo}/issues/${index}`;
|
const issuePath = `/repos/${repo}/issues/${index}`;
|
||||||
const commentsPath = `${issuePath}/comments`;
|
const timelinePath = `${issuePath}/timeline`;
|
||||||
|
|
||||||
if (flags['dry-run']) {
|
if (flags['dry-run']) {
|
||||||
return {
|
return {
|
||||||
dryRun: true,
|
dryRun: true,
|
||||||
repo,
|
repo,
|
||||||
index,
|
|
||||||
requests: [
|
requests: [
|
||||||
{ method: 'GET', path: issuePath },
|
{ method: 'GET', path: issuePath },
|
||||||
{ method: 'GET', path: commentsPath },
|
{ method: 'GET', path: timelinePath },
|
||||||
],
|
],
|
||||||
note: UNMERGED_COMMENT_NOTE,
|
note: UNMERGED_COMMENT_NOTE,
|
||||||
};
|
};
|
||||||
|
|||||||
+11
-5
@@ -974,16 +974,22 @@ export async function countUnmergedComments(login, repo, index, me) {
|
|||||||
/**
|
/**
|
||||||
* 逐頁走過一顆議題(或 PR)的一般留言。
|
* 逐頁走過一顆議題(或 PR)的一般留言。
|
||||||
* 三支腳本都要做這件事:數未整併的則數、列出留言內容、核對 --merged 的 id。
|
* 三支腳本都要做這件事:數未整併的則數、列出留言內容、核對 --merged 的 id。
|
||||||
|
* Gitea 的 comments 端點固定只回第一批,完整清單改從 timeline 取得。
|
||||||
* @returns {AsyncGenerator<object>} 一則一則交出去
|
* @returns {AsyncGenerator<object>} 一則一則交出去
|
||||||
*/
|
*/
|
||||||
export async function* listIssueComments(login, repo, index) {
|
export async function* listIssueComments(login, repo, index) {
|
||||||
const path = `/repos/${repo}/issues/${index}/comments`;
|
const path = `/repos/${repo}/issues/${index}/timeline`;
|
||||||
|
const seen = new Set();
|
||||||
|
|
||||||
for await (const comments of pages(login, path, {
|
for await (const entries of pages(login, path, {
|
||||||
limitCode: 'COMMENT_LIMIT',
|
limitCode: 'TIMELINE_LIMIT',
|
||||||
limitHint: `${path} 的留言太多,讀不完整份清單`,
|
limitHint: `${path} 的 timeline 太多,讀不完整份留言清單`,
|
||||||
})) {
|
})) {
|
||||||
for (const comment of comments) yield comment;
|
for (const entry of entries) {
|
||||||
|
if (entry.type !== 'comment' || seen.has(entry.id)) continue;
|
||||||
|
seen.add(entry.id);
|
||||||
|
yield entry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-8
@@ -24,6 +24,7 @@ import {
|
|||||||
ScriptError,
|
ScriptError,
|
||||||
expectOk,
|
expectOk,
|
||||||
giteaRequest,
|
giteaRequest,
|
||||||
|
listIssueComments,
|
||||||
main,
|
main,
|
||||||
pages,
|
pages,
|
||||||
parseFlags,
|
parseFlags,
|
||||||
@@ -205,14 +206,8 @@ async function findInline(login, repo, index, commentId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function findGeneral(login, repo, index, commentId) {
|
async function findGeneral(login, repo, index, commentId) {
|
||||||
const path = `/repos/${repo}/issues/${index}/comments`;
|
for await (const comment of listIssueComments(login, repo, index)) {
|
||||||
|
if (comment.id === commentId) return comment;
|
||||||
for await (const comments of pages(login, path, {
|
|
||||||
limitCode: 'COMMENT_LIMIT',
|
|
||||||
limitHint: `${path} 的留言太多,找不完`,
|
|
||||||
})) {
|
|
||||||
const hit = comments.find((comment) => comment.id === commentId);
|
|
||||||
if (hit) return hit;
|
|
||||||
}
|
}
|
||||||
throw notFound(index, '一般留言', commentId);
|
throw notFound(index, '一般留言', commentId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export function plannedRequests(repo, index) {
|
|||||||
return [
|
return [
|
||||||
{ method: 'GET', path: '/user' },
|
{ method: 'GET', path: '/user' },
|
||||||
{ method: 'GET', path: pullPath },
|
{ method: 'GET', path: pullPath },
|
||||||
{ method: 'GET', path: `/repos/${repo}/issues/${index}/comments` },
|
{ method: 'GET', path: `/repos/${repo}/issues/${index}/timeline` },
|
||||||
{ method: 'GET', path: `${pullPath}/reviews` },
|
{ method: 'GET', path: `${pullPath}/reviews` },
|
||||||
{ method: 'GET', path: `/repos/${repo}/issues/${index}/timeline` },
|
{ method: 'GET', path: `/repos/${repo}/issues/${index}/timeline` },
|
||||||
];
|
];
|
||||||
@@ -65,7 +65,7 @@ export function plannedRequests(repo, index) {
|
|||||||
export function commonRequests(repo, index) {
|
export function commonRequests(repo, index) {
|
||||||
return [
|
return [
|
||||||
{ method: 'GET', path: `/repos/${repo}/issues/${index}` },
|
{ method: 'GET', path: `/repos/${repo}/issues/${index}` },
|
||||||
{ method: 'GET', path: `/repos/${repo}/issues/${index}/comments` },
|
{ method: 'GET', path: `/repos/${repo}/issues/${index}/timeline` },
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ main(async () => {
|
|||||||
{ method: 'GET', path: issuePath },
|
{ method: 'GET', path: issuePath },
|
||||||
{ method: 'GET', path: `${issuePath}/dependencies` },
|
{ method: 'GET', path: `${issuePath}/dependencies` },
|
||||||
{ method: 'GET', path: `${issuePath}/blocks` },
|
{ method: 'GET', path: `${issuePath}/blocks` },
|
||||||
{ method: 'GET', path: `${issuePath}/comments` },
|
{ method: 'GET', path: `${issuePath}/timeline` },
|
||||||
],
|
],
|
||||||
note: UNMERGED_COMMENT_NOTE,
|
note: UNMERGED_COMMENT_NOTE,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user