Skip to content

fix(tgit): authenticate git-over-HTTPS clone with a PAT (private: user)#212

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
m0Nst3r873:fix/tgit-pat-git-clone
Jul 21, 2026
Merged

fix(tgit): authenticate git-over-HTTPS clone with a PAT (private: user)#212
jeff-r2026 merged 1 commit into
Tencent:mainfrom
m0Nst3r873:fix/tgit-pat-git-clone

Conversation

@m0Nst3r873

Copy link
Copy Markdown
Collaborator

Problem

Follow-up to #210 (merged). With the REST-auth fix in place, the MR knowledge-extract pipeline still failed at teamai init:

ℹ Repo teamai/teamai-dev-repo does not exist   ← it DOES exist
- Creating repo teamai/teamai-dev-repo...
✖ Failed to create repo: 400 {"message":"...Path has already been taken"}

Root cause (verified live against git.woa.com): a git-over-HTTPS credential's username depends on token type:

git URL username OAuth token PAT (TGIT_TOKEN)
oauth2:<token>@ ❌ auth fails
private:<token>@

The CLI hardcoded oauth2:, and two-segment repos routed to gf 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 via git clone https://<user>:<token>@… with the scheme-derived username; fall back to gf repo clone only when no token (interactive path, unchanged). Sanitizer redacts both oauth2: and private:.
  • clone.ts: scheme-based username instead of hardcoded oauth2:.
  • init.ts: a "repo already exists" create error is no longer fatal — retries the clone.
  • CI example: netrc login private, clone via private:${TGIT_TOKEN}@.
  • Unit tests for tgitGitUser / tryGetTGitToken.

Test Plan

  • npx tsc --noEmit clean · npm run build · npx vitest run → 1786 passed
  • Real E2E with a CI PAT (TGIT_TOKEN): gfRepoClone('teamai/teamai-dev-repo') clones via private: path; teamai init reaches ✔ Team repo cloned (previously the 400).

gf's auth login / gf commands are unchanged — they remain the no-token interactive fallback.

🤖 Generated with Claude Code

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
m0Nst3r873 force-pushed the fix/tgit-pat-git-clone branch from 0a8492e to b44d6d5 Compare July 20, 2026 12:29
@jeff-r2026
jeff-r2026 merged commit 93c903b into Tencent:main Jul 21, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants