SuperAPI AI 工具集

github-auth

通用与其它

查看项目

更新于 10-16 07:15

技能介绍

用途:为智能体配置 GitHub 认证,使其能够操作仓库、拉取请求(PR)、Issue 与 CI。

检测流程:先运行检查确认可用工具与登录状态。

git --version gh --version 2>/dev/null || echo "gh not installed" gh auth status 2>/dev/null || echo "gh not authenticated" git config --global credential.helper 2>/dev/null || echo "no git credential helper"

决策:若 gh 已认证则全部走 gh;若 gh 已安装但未认证,使用 gh 登录;若未安装 gh,则使用仅 git 方案(无需 sudo)。

方法一 仅 git 认证:可选 HTTPS 个人访问令牌或 SSH 密钥。HTTPS 方式先在 https://github.com/settings/tokens 生成 classic token,选择 repo、workflow、必要时 read:org 范围并设置过期时间;随后配置存储: git config --global credential.helper store git ls-remote https://github.com/<their-username>/<any-repo>.git 也可用 cache 方式: git config --global credential.helper 'cache --timeout=28800' 或把令牌写入远程 URL。最后配置身份并验证: git config --global user.name "Their Name" git config --global user.email "their-email@example.com"

SSH 方式:检查或生成密钥: ssh-keygen -t ed25519 -C "their-email@example.com" -f ~/.ssh/id_ed25519 -N "" 把公钥添加到 https://github.com/settings/keys,用 ssh -T git@github.com 测试,并可选配置 URL 重写。

方法二 gh CLI:交互式 gh auth login,或在无界面环境用 echo "<THEIR_TOKEN>" | gh auth login --with-token,再执行 gh auth setup-git,最后 gh auth status 验证。

无 gh 时仍可用 curl 调用 API:export GITHUB_TOKEN="<token>",随后 curl -s -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/user。也可从 ~/.git-credentials 或 HERMES_HOME 的 .env 中提取令牌。技能提供了一段检测认证方式的脚本,依次尝试 gh、环境变量、凭证文件。

常见问题:push 要求密码时改用令牌或 SSH;权限被拒时检查 scope;认证失败可清缓存重试;22 端口不通可用 443;凭证不持久需检查 credential.helper;多账号用 SSH 别名或按仓库配置。

限制:需用户自行生成令牌或在 GitHub 添加密钥;资料未提供收费、平台与效果信息。