fix(tgit): authenticate git-over-HTTPS clone with a PAT (private: user)#212
Merged
Merged
Conversation
Follow-up to Tencent#210. The MR-extract pipeline still failed at `teamai init`: a git.woa.com Personal Access Token authenticates git-over-HTTPS only with the username `private:` (an OAuth token uses `oauth2:`). The CLI hardcoded `oauth2:` and routed two-segment repos to `gf repo clone`, whose own API lookup can't use a PAT — so the existing knowledge repo was misread as "does not exist", then create failed with 400 "Path has already been taken". Verified live against git.woa.com. Changes: - rest-auth.ts: add tgitGitUser(scheme) (PAT→'private', OAuth→'oauth2') and tryGetTGitToken() (non-throwing token resolver). - gf-cli.ts gfRepoClone: when a token is available, clone every repo via `git clone https://<user>:<token>@…` with the scheme-derived username; fall back to `gf repo clone` only when no token exists (interactive path, unchanged). Sanitizer redacts both oauth2: and private:. - clone.ts: use the scheme-based username instead of hardcoded oauth2:. - init.ts: a "repo already exists" create error is no longer fatal — it falls through to retry the clone. - Tests for tgitGitUser and tryGetTGitToken. CI example (examples/ci/coding-ci-mr-extract.yaml), validated end-to-end against a live ZhiYan pipeline: - comment stage no longer runs `teamai init` (comment mode only fetches the MR and posts via REST — no team-repo clone, and init's member registration needs an interactive TTY unavailable in CI). - post-merge stage drops the redundant manual git config/commit/push block: `teamai ci extract-mr --write-mode direct` already commits and pushes with the git identity derived from TGIT_TOKEN's account (REST /user), which satisfies TGit's committer-check. The hardcoded `teamai-ci` committer was rejected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
m0Nst3r873
force-pushed
the
fix/tgit-pat-git-clone
branch
from
July 20, 2026 12:29
0a8492e to
b44d6d5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Follow-up to #210 (merged). With the REST-auth fix in place, the MR knowledge-extract pipeline still failed at
teamai init:Root cause (verified live against git.woa.com): a git-over-HTTPS credential's username depends on token type:
TGIT_TOKEN)oauth2:<token>@private:<token>@The CLI hardcoded
oauth2:, and two-segment repos routed togf repo clone, whose own API lookup can't authenticate with a PAT (prints未在工蜂找到→ misread as "not found" → misfired create → 400).Changes
rest-auth.ts:tgitGitUser(scheme)(PAT→private, OAuth→oauth2) +tryGetTGitToken()(non-throwing resolver).gfRepoClone: when a token exists, clone every repo viagit clone https://<user>:<token>@…with the scheme-derived username; fall back togf repo cloneonly when no token (interactive path, unchanged). Sanitizer redacts bothoauth2:andprivate:.clone.ts: scheme-based username instead of hardcodedoauth2:.init.ts: a "repo already exists" create error is no longer fatal — retries the clone.login private, clone viaprivate:${TGIT_TOKEN}@.tgitGitUser/tryGetTGitToken.Test Plan
npx tsc --noEmitclean ·npm run build·npx vitest run→ 1786 passedTGIT_TOKEN):gfRepoClone('teamai/teamai-dev-repo')clones viaprivate:path;teamai initreaches✔ Team repo cloned(previously the 400).🤖 Generated with Claude Code