test(留言分頁): 改用 timeline 分頁讀取留言
Gitea 議題留言端點無法可靠處理分頁;改由 timeline 逐頁篩選 comment 事件並去重,讓抽取、整併與 PR 留言流程取得完整集合。
This commit is contained in:
@@ -55,9 +55,9 @@ function routes(overrides = {}, { body = BODY, comments = [101, 102] } = {}) {
|
|||||||
status: 200,
|
status: 200,
|
||||||
body: { number: INDEX, ...req.body, html_url: `https://x/${INDEX}` },
|
body: { number: INDEX, ...req.body, html_url: `https://x/${INDEX}` },
|
||||||
}),
|
}),
|
||||||
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/comments`]: {
|
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/timeline`]: {
|
||||||
status: 200,
|
status: 200,
|
||||||
body: comments.map((id) => ({ id, body: `留言 ${id}`, user: { login: 'someone' } })),
|
body: comments.map((id) => ({ id, type: 'comment', body: `留言 ${id}`, user: { login: 'someone' } })),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
for (const id of comments) {
|
for (const id of comments) {
|
||||||
|
|||||||
+28
-11
@@ -75,9 +75,9 @@ function routes(overrides = {}, { body = FULL_BODY, comments = [] } = {}) {
|
|||||||
labels: [{ id: 55, name: 'ready-for-agent' }],
|
labels: [{ id: 55, name: 'ready-for-agent' }],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/comments`]: {
|
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/timeline`]: {
|
||||||
status: 200,
|
status: 200,
|
||||||
body: comments.map((c, i) => ({ id: 100 + i, body: c.body })),
|
body: comments.map((c, i) => ({ id: 100 + i, type: 'comment', body: c.body })),
|
||||||
},
|
},
|
||||||
...overrides,
|
...overrides,
|
||||||
});
|
});
|
||||||
@@ -340,7 +340,7 @@ test('--dry-run 印出將發出的請求,且不碰 Gitea', async (t) => {
|
|||||||
json.data.requests.map((r) => `${r.method} ${r.path}`),
|
json.data.requests.map((r) => `${r.method} ${r.path}`),
|
||||||
[
|
[
|
||||||
`GET /repos/${REPO}/issues/${INDEX}`,
|
`GET /repos/${REPO}/issues/${INDEX}`,
|
||||||
`GET /repos/${REPO}/issues/${INDEX}/comments`,
|
`GET /repos/${REPO}/issues/${INDEX}/timeline`,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
assert.match(
|
assert.match(
|
||||||
@@ -422,17 +422,20 @@ test('巢狀清單一律攤平,不無聲吃掉內容', async (t) => {
|
|||||||
assert.deepEqual(json.data.驗收標準, ['上層項目', '巢狀項目']);
|
assert.deepEqual(json.data.驗收標準, ['上層項目', '巢狀項目']);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('留言逐頁讀完,不是只讀第一頁', async (t) => {
|
test('留言 timeline 逐頁讀完並去除重複事件', async (t) => {
|
||||||
// 第一頁滿 50 筆就得再翻一頁;第二頁不滿才收手
|
// 第一頁滿 50 筆就得再翻一頁;第二頁包含重複事件,仍只算一次
|
||||||
const page1 = Array.from({ length: 50 }, (_, i) => ({ id: 200 + i }));
|
const page1 = Array.from({ length: 50 }, (_, i) => ({ id: 200 + i, type: 'comment' }));
|
||||||
const page2 = Array.from({ length: 20 }, (_, i) => ({ id: 300 + i }));
|
const page2 = [
|
||||||
|
page1.at(-1),
|
||||||
|
...Array.from({ length: 20 }, (_, i) => ({ id: 300 + i, type: 'comment' })),
|
||||||
|
];
|
||||||
const reactions = {};
|
const reactions = {};
|
||||||
for (const { id } of [...page1, ...page2]) {
|
for (const { id } of [...page1, ...page2]) {
|
||||||
reactions[`GET /api/v1/repos/${REPO}/issues/comments/${id}/reactions`] = { status: 200, body: [] };
|
reactions[`GET /api/v1/repos/${REPO}/issues/comments/${id}/reactions`] = { status: 200, body: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const stub = await withStub(t, {
|
const stub = await withStub(t, {
|
||||||
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/comments`]: (req) => ({
|
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/timeline`]: (req) => ({
|
||||||
status: 200,
|
status: 200,
|
||||||
body: req.query.page === '1' ? page1 : page2,
|
body: req.query.page === '1' ? page1 : page2,
|
||||||
}),
|
}),
|
||||||
@@ -441,7 +444,21 @@ test('留言逐頁讀完,不是只讀第一頁', async (t) => {
|
|||||||
|
|
||||||
const { json } = await run([], stub);
|
const { json } = await run([], stub);
|
||||||
|
|
||||||
const commentPages = stub.requests.filter((r) => r.path.endsWith(`/issues/${INDEX}/comments`));
|
const timelinePages = stub.requests.filter((r) => r.path.endsWith(`/issues/${INDEX}/timeline`));
|
||||||
assert.deepEqual(commentPages.map((r) => r.query.page), ['1', '2']);
|
assert.deepEqual(timelinePages.map((r) => r.query.page), ['1', '2']);
|
||||||
assert.equal(json.data.未處理留言數, 70, '第二頁的留言也要算進來');
|
assert.equal(json.data.未處理留言數, 70, '重複事件不應重複計入');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('timeline 讀取失敗時回傳可區分的錯誤', async (t) => {
|
||||||
|
const stub = await withStub(t, {
|
||||||
|
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/timeline`]: {
|
||||||
|
status: 502,
|
||||||
|
body: { message: 'upstream unavailable' },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { json } = await run([], stub);
|
||||||
|
|
||||||
|
assert.equal(json.error.code, 'HTTP_ERROR');
|
||||||
|
assert.match(json.error.message, /502/);
|
||||||
});
|
});
|
||||||
|
|||||||
+21
-17
@@ -33,13 +33,23 @@ function routes(overrides = {}, options = {}) {
|
|||||||
status: 200,
|
status: 200,
|
||||||
body: { ...pull, ...(isPull ? { pull_request: { merged: false } } : {}) },
|
body: { ...pull, ...(isPull ? { pull_request: { merged: false } } : {}) },
|
||||||
},
|
},
|
||||||
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/comments`]: {
|
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/timeline`]: {
|
||||||
status: 200,
|
status: 200,
|
||||||
body: general.map((c, i) => ({
|
body: [
|
||||||
|
...general.map((c, i) => ({
|
||||||
id: 100 + i,
|
id: 100 + i,
|
||||||
|
type: 'comment',
|
||||||
body: c.body,
|
body: c.body,
|
||||||
user: { login: c.user ?? 'reviewer' },
|
user: { login: c.user ?? 'reviewer' },
|
||||||
})),
|
})),
|
||||||
|
...reviews.map((r, i) => ({
|
||||||
|
id: 400 + i,
|
||||||
|
type: 'review',
|
||||||
|
review_id: 200 + i,
|
||||||
|
body: r.body ?? '',
|
||||||
|
user: { login: r.user ?? 'reviewer' },
|
||||||
|
})),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
[`GET /api/v1/repos/${REPO}/pulls/${INDEX}/reviews`]: {
|
[`GET /api/v1/repos/${REPO}/pulls/${INDEX}/reviews`]: {
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -50,17 +60,6 @@ function routes(overrides = {}, options = {}) {
|
|||||||
user: { login: r.user ?? 'reviewer' },
|
user: { login: r.user ?? 'reviewer' },
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
// 總評在 issue comment 表裡也有一份,timeline 給得出它的 id 與 review_id
|
|
||||||
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/timeline`]: {
|
|
||||||
status: 200,
|
|
||||||
body: reviews.map((r, i) => ({
|
|
||||||
id: 400 + i,
|
|
||||||
type: 'review',
|
|
||||||
review_id: 200 + i,
|
|
||||||
body: r.body ?? '',
|
|
||||||
user: { login: r.user ?? 'reviewer' },
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
general.forEach((c, i) => {
|
general.forEach((c, i) => {
|
||||||
@@ -416,7 +415,7 @@ test('--dry-run 印出將發出的請求,且不碰 Gitea', async (t) => {
|
|||||||
json.data.requests.map((r) => `${r.method} ${r.path}`),
|
json.data.requests.map((r) => `${r.method} ${r.path}`),
|
||||||
[
|
[
|
||||||
`GET /repos/${REPO}/issues/${INDEX}`,
|
`GET /repos/${REPO}/issues/${INDEX}`,
|
||||||
`GET /repos/${REPO}/issues/${INDEX}/comments`,
|
`GET /repos/${REPO}/issues/${INDEX}/timeline`,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
assert.match(json.data.note, /reaction|review/);
|
assert.match(json.data.note, /reaction|review/);
|
||||||
@@ -426,15 +425,20 @@ test('--dry-run 印出將發出的請求,且不碰 Gitea', async (t) => {
|
|||||||
// ── 分頁 ───────────────────────────────────────────────────────────
|
// ── 分頁 ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
test('留言逐頁讀完,不是只讀第一頁', async (t) => {
|
test('留言逐頁讀完,不是只讀第一頁', async (t) => {
|
||||||
const page1 = Array.from({ length: 50 }, (_, i) => ({ id: 500 + i, body: `第 ${i} 則`, user: { login: 'r' } }));
|
const page1 = Array.from({ length: 50 }, (_, i) => ({
|
||||||
const page2 = [{ id: 999, body: '最後一則', user: { login: 'r' } }];
|
id: 500 + i,
|
||||||
|
type: 'comment',
|
||||||
|
body: `第 ${i} 則`,
|
||||||
|
user: { login: 'r' },
|
||||||
|
}));
|
||||||
|
const page2 = [{ id: 999, type: 'comment', body: '最後一則', user: { login: 'r' } }];
|
||||||
const reactions = {};
|
const reactions = {};
|
||||||
for (const c of [...page1, ...page2]) {
|
for (const c of [...page1, ...page2]) {
|
||||||
reactions[`GET /api/v1/repos/${REPO}/issues/comments/${c.id}/reactions`] = { status: 200, body: [] };
|
reactions[`GET /api/v1/repos/${REPO}/issues/comments/${c.id}/reactions`] = { status: 200, body: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const stub = await withStub(t, {
|
const stub = await withStub(t, {
|
||||||
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/comments`]: (req) => ({
|
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/timeline`]: (req) => ({
|
||||||
status: 200,
|
status: 200,
|
||||||
body: req.query.page === '1' ? page1 : page2,
|
body: req.query.page === '1' ? page1 : page2,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -43,13 +43,12 @@ function routes(overrides = {}) {
|
|||||||
},
|
},
|
||||||
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/timeline`]: {
|
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/timeline`]: {
|
||||||
status: 200,
|
status: 200,
|
||||||
body: [{ id: REVIEW.commentId, type: 'review', review_id: REVIEW.id, body: REVIEW.body }],
|
body: [
|
||||||
|
{ id: REVIEW.commentId, type: 'review', review_id: REVIEW.id, body: REVIEW.body },
|
||||||
|
{ id: GENERAL.id, type: 'comment', body: GENERAL.body, user: { login: 'r' } },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
[`POST /api/v1/repos/${REPO}/issues/comments/${REVIEW.commentId}/reactions`]: { status: 201, body: {} },
|
[`POST /api/v1/repos/${REPO}/issues/comments/${REVIEW.commentId}/reactions`]: { status: 201, body: {} },
|
||||||
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/comments`]: {
|
|
||||||
status: 200,
|
|
||||||
body: [{ id: GENERAL.id, body: GENERAL.body, user: { login: 'r' } }],
|
|
||||||
},
|
|
||||||
[`POST /api/v1/repos/${REPO}/issues/${INDEX}/comments`]: { status: 201, body: { id: 900 } },
|
[`POST /api/v1/repos/${REPO}/issues/${INDEX}/comments`]: { status: 201, body: { id: 900 } },
|
||||||
[`POST /api/v1/repos/${REPO}/issues/comments/${GENERAL.id}/reactions`]: { status: 201, body: {} },
|
[`POST /api/v1/repos/${REPO}/issues/comments/${GENERAL.id}/reactions`]: { status: 201, body: {} },
|
||||||
[`POST /api/v1/repos/${REPO}/pulls/${INDEX}/reviews`]: { status: 200, body: { id: 901 } },
|
[`POST /api/v1/repos/${REPO}/pulls/${INDEX}/reviews`]: { status: 200, body: { id: 901 } },
|
||||||
|
|||||||
@@ -44,12 +44,16 @@ function routes({ state = 'open', merged = false, draft = false, general = [], h
|
|||||||
head: head ?? { ref: BRANCH, label: BRANCH },
|
head: head ?? { ref: BRANCH, label: BRANCH },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/comments`]: {
|
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/timeline`]: {
|
||||||
status: 200,
|
status: 200,
|
||||||
body: general.map((c, i) => ({ id: 100 + i, body: c.body, user: { login: 'reviewer' } })),
|
body: general.map((c, i) => ({
|
||||||
|
id: 100 + i,
|
||||||
|
type: 'comment',
|
||||||
|
body: c.body,
|
||||||
|
user: { login: 'reviewer' },
|
||||||
|
})),
|
||||||
},
|
},
|
||||||
[`GET /api/v1/repos/${REPO}/pulls/${INDEX}/reviews`]: { status: 200, body: [] },
|
[`GET /api/v1/repos/${REPO}/pulls/${INDEX}/reviews`]: { status: 200, body: [] },
|
||||||
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/timeline`]: { status: 200, body: [] },
|
|
||||||
});
|
});
|
||||||
general.forEach((c, i) => {
|
general.forEach((c, i) => {
|
||||||
base[`GET /api/v1/repos/${REPO}/issues/comments/${100 + i}/reactions`] = {
|
base[`GET /api/v1/repos/${REPO}/issues/comments/${100 + i}/reactions`] = {
|
||||||
|
|||||||
Reference in New Issue
Block a user