✨ feat(vscode): 新增 GitHub provider,凭据借 gh 登录,删工单走 GraphQL、依赖按内部 id 换算

This commit is contained in:
cruldra committed 2026-10-19 08:18:27 +11:00
1 parent 451bc91a6b
commit 7351b6247f
12 files changed
+1010 -47

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
/**
* GitHub 的凭据直接借 GitHub CLI(`gh`)的登录:每次要用时现取 `gh auth token`,插件自己不存 GitHub token。
*/
import { execFile } from 'node:child_process'
import { findExecutable } from '../../shared/executable'
/** 没取到 gh 登录凭据时给人看的提示。 */
export const GH_LOGIN_HINT = '未登录 GitHub CLI,请在终端运行 `gh auth login` 登录后重试'
/** gh 登录已失效(GitHub 回 401)时给人看的提示。 */
export const GH_RELOGIN_HINT = 'GitHub CLI 的登录已失效,请在终端运行 `gh auth login` 重新登录后重试'
/** PATH 里找不到 gh 时再试的安装位置:Homebrew(Apple 芯片、Intel)和系统包管理器。 */
const GH_FALLBACKS = ['/opt/homebrew/bin/gh', '/usr/local/bin/gh', '/usr/bin/gh']
/** 取 gh 在 github.com 上登录的 token;gh 没装、没登录、执行失败或输出为空都返回 `undefined`。 */
export function readGhToken(): Promise<string | undefined> {
const gh = findExecutable('gh', GH_FALLBACKS) ?? 'gh'
return new Promise((resolve) => {
execFile(gh, ['auth', 'token', '--hostname', 'github.com'], { timeout: 10_000, encoding: 'utf8' }, (err, stdout) => {
const token = err ? '' : String(stdout).trim()
resolve(token || undefined)
})
})
}