创建仓库前先探测是否已存在,避开二次限流
由 dsh-go 自动上传 · 2026/11/17 13:11:35
This commit is contained in:
1 parent
c7a76fa856
commit
db876f4c9c
1 file changed
+10
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user