🔥 refactor(vscode): 删掉没人调用的 createWebhook 和 listAllRepoComments

This commit is contained in:
cruldra committed 2026-10-19 07:30:21 +11:00
1 parent a23c88e812
commit fa7b32d205
2 files changed
-93

No files matched your search

-89
View File
@@ -125,38 +125,6 @@ export async function listIssuesByFilter(opts: {
return out
}
/**
* Fetches the firehose `/repos/{owner}/{repo}/issues/comments` endpoint, which
* returns every comment in the repo across all issues. Paginated until a short
* page is returned.
*/
export async function listAllRepoComments(opts: {
host: string
token: string
owner: string
repo: string
}): Promise<GiteaComment[]> {
const out: GiteaComment[] = []
let page = 1
while (true) {
const url = new URL(`${baseUrl(opts.host)}/repos/${opts.owner}/${opts.repo}/issues/comments`)
url.searchParams.set('limit', String(PAGE_SIZE))
url.searchParams.set('page', String(page))
const res = await fetch(url.toString(), { headers: authHeaders(opts.token) })
await ensureOk(res)
const batch = await res.json() as GiteaComment[]
if (!Array.isArray(batch) || batch.length === 0)
break
out.push(...batch)
if (batch.length < PAGE_SIZE)
break
page += 1
}
return out
}
/**
* 单个工单的评论接口一次返回全部评论,只支持 since / before 时间筛选。
*/
@@ -452,63 +420,6 @@ export async function removeDependency(opts: {
await ensureOk(res)
}
// no longer auto-invoked by the implement flow; kept for future manual ops
export async function createWebhook(opts: {
host: string
token: string
owner: string
repo: string
url: string
branchFilter: string
}): Promise<{ id: number }> {
const res = await fetch(
`${baseUrl(opts.host)}/repos/${opts.owner}/${opts.repo}/hooks`,
{
method: 'POST',
headers: {
...authHeaders(opts.token),
'Content-Type': 'application/json',
},
body: JSON.stringify({
type: 'gitea',
active: true,
events: ['pull_request'],
branch_filter: opts.branchFilter,
config: {
url: opts.url,
content_type: 'json',
},
}),
},
)
if (!res.ok) {
const body = await res.text().catch(() => '')
logger.add({
level: 'error',
source: 'gitea',
message: `createWebhook 失败 status=${res.status}`,
details: (body || res.statusText).slice(0, 500),
})
throw new GiteaApiError(res.status, body || res.statusText)
}
const data = (await res.json()) as { id?: unknown }
const id = typeof data.id === 'number' ? data.id : Number(data.id)
if (!Number.isFinite(id)) {
logger.add({
level: 'error',
source: 'gitea',
message: 'createWebhook: 响应缺少 id',
})
throw new GiteaApiError(500, 'createWebhook: response missing id')
}
logger.add({
level: 'info',
source: 'gitea',
message: `已创建 hookId=${id} url=${opts.url} branch_filter=${opts.branchFilter}`,
})
return { id }
}
// no longer auto-invoked by the implement flow; kept for future manual ops
export async function deleteWebhook(opts: {
host: string
-4
View File
@@ -3,7 +3,6 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
const getCurrentUser = vi.fn()
const listIssuesByFilter = vi.fn()
const listAllRepoComments = vi.fn()
const getDependencies = vi.fn()
const getPullRequest = vi.fn()
const postIssueComment = vi.fn()
@@ -14,7 +13,6 @@ vi.mock('./api', () => ({
PAGE_SIZE: 50,
getCurrentUser,
listIssuesByFilter,
listAllRepoComments,
getDependencies,
getPullRequest,
postIssueComment,
@@ -98,7 +96,6 @@ describe('loadIssues', () => {
getCurrentUser.mockReset()
listIssuesByFilter.mockReset()
listIssueComments.mockReset()
listAllRepoComments.mockReset()
getDependencies.mockReset()
getPullRequest.mockReset()
postIssueComment.mockReset()
@@ -125,7 +122,6 @@ describe('loadIssues', () => {
})
expect(me).toBe('me')
expect(listAllRepoComments).not.toHaveBeenCalled()
expect(listIssueComments).toHaveBeenCalledWith(expect.objectContaining({ index: 7 }))
expect(issues).toHaveLength(1)
expect(issues[0].column).toBe('todo')