🐛 fix(spx): GITEA_TOKEN 只发给 tea 登录过的 host,origin 不在 tea 里时直接报错
This commit is contained in:
1 parent
e6d086d821
commit
9c7c9d8636
6 files changed
+43
-25
No files matched your search
@@ -51,8 +51,9 @@ func ghAuthToken(host string) (string, error) {
|
||||
|
||||
// Open connects to the repo at `o` on the forge its host names, picking credentials the way that forge expects.
|
||||
//
|
||||
// GitHub takes the token from `gh auth token`. Gitea takes the token of the tea login for the same host, and its
|
||||
// URL as the API root; with no such login, or one without a token, it falls back to `GITEA_TOKEN` and the origin's web root.
|
||||
// GitHub takes the token from `gh auth token`. Gitea needs a [tea.TeaLogin] for the same host and uses its URL as the API
|
||||
// root and its token; `GITEA_TOKEN` only fills in when that login has no token, so the variable never reaches a host the
|
||||
// user has not logged in to with tea.
|
||||
func Open(o repo.Origin, env Env) (Forge, error) {
|
||||
if KindForHost(o.Host) == KindGitHub {
|
||||
token, err := env.GitHubToken(o.Host)
|
||||
@@ -69,15 +70,15 @@ func Open(o repo.Origin, env Env) (Forge, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
baseURL, token := o.WebURL, ""
|
||||
if login != nil {
|
||||
baseURL, token = login.URL, login.Token
|
||||
if login == nil {
|
||||
return nil, fmt.Errorf("tea config 里没有 %s 的 login,spx 不会把 Gitea token 发给 tea 没登录过的 host;请先运行 `tea login add` 登录这个 host", o.Host)
|
||||
}
|
||||
token := login.Token
|
||||
if token == "" {
|
||||
token = env.Getenv("GITEA_TOKEN")
|
||||
}
|
||||
if token == "" {
|
||||
return nil, fmt.Errorf("没有 %s 的 Gitea token:tea config 里没有该 host 的 login 或其 token 为空,GITEA_TOKEN 也没设置;请运行 `tea login add` 或设置 GITEA_TOKEN", o.Host)
|
||||
return nil, fmt.Errorf("tea config 里 %s 的 login %q 没有 token,GITEA_TOKEN 也没设置;请重新运行 `tea login add` 或设置 GITEA_TOKEN", o.Host, login.Name)
|
||||
}
|
||||
return NewGitea(baseURL, token, o.Owner, o.Repo), nil
|
||||
return NewGitea(login.URL, token, o.Owner, o.Repo), nil
|
||||
}
|
||||
Reference in new issue
Block a user