diff --git a/lib/github.js b/lib/github.js index 43acbfb..cbbe714 100644 --- a/lib/github.js +++ b/lib/github.js @@ -58,6 +58,16 @@ export async function getLogin(token) { /** 保证仓库存在;已存在就复用。返回 { url, cloneUrl, created }。 */ export async function ensureRepo({ token, login, name, privateRepo = true, description = '' }) { + // 先问一下仓库在不在:已经推过一次的项目不必每次都调创建接口, + // 也避开 GitHub 对「内容创建」的二次限流(那个档位下 POST 会被 403)。 + try { + const existing = await request(`/repos/${login}/${name}`, { token }) + if (existing && existing.html_url) { + return { url: existing.html_url, cloneUrl: existing.clone_url, created: false } + } + } catch (error) { + if (!(error instanceof GitHubError) || error.status !== 404) throw error + } try { const repo = await request('/user/repos', { token,