Skip to content

feat(git): support generic private repository hosts - #301

Merged
jeff-r2026 merged 4 commits into
Tencent:mainfrom
YogeLiu:feat/generic-git-provider
Aug 24, 2026
Merged

jeff-r2026 merged 4 commits into
Tencent:mainfrom
YogeLiu:feat/generic-git-provider

Conversation

@YogeLiu

@YogeLiu YogeLiu commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a transport-only git provider for unknown full HTTPS and SSH repository URLs
  • preserve nested namespaces and delegate private-repository authentication to system Git credential helpers or SSH agents
  • support clone, pull, and push while explicitly falling back to manual MR/PR creation for host-specific API operations
  • extend provider configuration, remote import parsing, tests, and documentation

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Test Plan

  • npm run typecheck passes
  • npm test passes (1991 tests)
  • npm run build passes
  • Added/updated tests for provider detection, URL parsing, clone behavior, schema compatibility, and unsupported host API operations

Related Issues

Closes #300

Notes for Reviewers

Generic hosts intentionally do not attempt platform authentication, repository creation, or MR/PR APIs. Git remains the credential boundary, embedded HTTPS credentials are rejected, and branch push succeeds before the existing manual-PR fallback is shown.

@jeff-r2026
jeff-r2026 requested a review from m0Nst3r873 August 20, 2026 03:27
@YogeLiu
YogeLiu marked this pull request as ready for review August 20, 2026 06:18

@m0Nst3r873 m0Nst3r873 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! A couple of functional notes below (non-blocking). Format/commit-convention items are out of scope for this review.

Comment thread src/providers/git/index.ts Resolved
Comment thread src/providers/git/index.ts Resolved
@MyNameisPI

Copy link
Copy Markdown

Windows bug: PR #301 assumes process.env.HOME is always defined.

On a normal Windows PowerShell session:

teamai init git@xxx

fails with:

Local config saved to undefined/.teamai/config.yaml
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined

Please fall back to USERPROFILE or os.homedir() when HOME is missing.

@jeff-r2026
jeff-r2026 merged commit b8f5585 into Tencent:main Aug 24, 2026
7 checks passed
jeff-r2026 added a commit to ityoung/teamai-cli that referenced this pull request Aug 24, 2026
Review fixes on top of the GitLab provider, rebased onto the generic `git`
provider from Tencent#301. Detection order is now known host -> self-hosted GitLab
-> `git` transport fallback, so a self-hosted instance keeps the platform
features (create repo/MR, fetch MR, list group repos) that the generic
provider does not implement.

Host handling:
- Clone URLs derive from the instance base URL instead of being reassembled
  from GITLAB_HOST, so scheme (http:// internal deployments), port and
  relative-URL-root prefixes survive.
- fetchGitLabMR queries the host named by the MR URL rather than the
  configured instance, which previously sent a self-hosted PAT to gitlab.com
  and read whichever project shared that path.
- GITLAB_URL is validated; a scheme-less value used to leave GITLAB_HOST on
  gitlab.com while every API call threw "Failed to parse URL" from undici.
  Base URL resolution is lazy so an invalid value fails the GitLab operation
  instead of crashing every module that imports this one.
- Self-hosted host matching tolerates a configured port, since the ssh:// and
  scp-style URL forms never carry one.

Wiring that was implemented but unreachable:
- import --from-mr now routes /-/merge_requests/ URLs to the GitLab fetcher
  (previously "Unsupported MR URL"), and infers the repo URL for the
  incremental update.
- import --from-org resolves the provider through detectProvider instead of
  a hardcoded `woa.com ? tgit : github`, which sent every GitLab org to the
  GitHub API.
- shallowClone injects GITLAB_TOKEN via http.extraHeader instead of falling
  through to an anonymous clone, so private repos work; the token stays out
  of the URL.
- teamai doctor checks the GitLab token when provider is gitlab.

Correctness:
- parseGitLabRepoInput strips GitLab's /-/ route separator, so a URL copied
  from the browser resolves to the project instead of yielding
  owner="org/repo/-/tree", repo="main".
- createRepo resolves the group by exact path and fails when it cannot,
  rather than silently creating the project in the personal namespace and
  reporting success at the wrong location.
- listOrgRepos passes include_subgroups=true; GitLab defaults it to false,
  silently dropping every project nested under a subgroup.
- Blank/whitespace tokens read as absent, so isAuthenticated no longer
  disagrees with the rest of the provider, and a trailing newline from
  $(cat token) cannot produce an invalid header value.
- API error message is English, per the repo output-language rule.

Tests: regression coverage for each fix above, plus the first coverage for
org.ts and mr-fetch.ts.

Co-Authored-By: Shin Yang <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
jeff-r2026 pushed a commit that referenced this pull request Aug 24, 2026
…#307)

Adds a GitLab provider (REST API v4, no external CLI) supporting gitlab.com
and self-hosted / enterprise instances: clone, create repo, create MR with
reviewer resolution, fetch MR data, and list group repos.

Detection order is known host -> self-hosted GitLab (GITLAB_URL /
TEAMAI_GITLAB_HOST) -> the generic `git` transport provider, across HTTPS,
ssh:// and scp-style URLs. This complements the generic provider from #301,
which is transport-only and cannot create repos or merge requests.

Includes review fixes: clone and MR URLs honour the instance scheme, port and
path prefix; GITLAB_URL is validated and resolved lazily; the MR fetcher
queries the host named by the URL; `/-/` route paths are stripped when parsing
repo input; group namespaces resolve by exact path and fail rather than
falling back to the personal namespace; group listing includes subgroups;
blank tokens read as absent. Wires GitLab into the MR-import dispatcher, the
org-import provider resolution, shallowClone token injection, and doctor.

Co-Authored-By: Shin Yang <[email protected]>
jeff-r2026 added a commit that referenced this pull request Aug 24, 2026
…ut (#308)

Two follow-up fixes for the generic Git provider (#301):

- parseGenericGitRepoInput accepted scp-style URLs whose user field
  carried credentials (e.g. "oauth2:token@host:group/repo.git"),
  returning them verbatim while the HTTPS path already rejected embedded
  credentials. A colon in the SSH user field is a credential, never a
  real login, so reject it. Normal "git@host:..." logins are unaffected.
- Clone timeout was 120s, shorter than the 180s default used by the
  shallow-clone path in clone.ts. Large self-hosted repos over slow/VPN
  links could time out where the equivalent path would not. Align to 180s.

Co-authored-by: Claude Fable 5 <[email protected]>
@jeff-r2026

Copy link
Copy Markdown
Collaborator

Thanks for the clear repro, @MyNameisPI — confirmed and fixed in #309.

Root cause: #301 added getUserHome() (HOME → USERPROFILE → os.homedir()) but only wired it into types.ts. Every other module still read a bare process.env.HOME, which is undefined on a normal Windows session — hence the undefined/.teamai/... path and the ERR_INVALID_ARG_TYPE crash you saw.

#309 routes all remaining home lookups through getUserHome() and adds a guard test that fails if any source file reads process.env.HOME directly, so this can't regress. Verified end-to-end with HOME unset and only USERPROFILE set.

jeff-r2026 added a commit that referenced this pull request Aug 24, 2026
PR #301 introduced getUserHome() (HOME → USERPROFILE → os.homedir) but only
wired it into types.ts. The rest of the codebase still read a bare
`process.env.HOME`, so on a normal Windows session (where only USERPROFILE is
set) `teamai init` printed "Local config saved to undefined/..." and then
crashed with ERR_INVALID_ARG_TYPE — the exact failure reported on #301.

Route every remaining home lookup through getUserHome(). Because it now always
returns a non-empty path, drop the dead `if (!home)` guards it made
unreachable (including one in uninstall.ts that used to abort the whole command
when HOME was unset — i.e. uninstall was fully broken on Windows). Fix
getVotesLocalDir(), the import/recall/search-index paths and the debug-log path
to build with path.join instead of a hardcoded "/" separator.

Harden getUserHome() with a final os.tmpdir() fallback: os.homedir() is
documented to return '' when the home can't be resolved, which would make every
derived path cwd-relative; the guarantee of a non-empty absolute path is what
lets the callers above drop their guards safely.

Add a guard test that fails if any source file outside utils/home.ts reads
process.env.HOME directly, plus USERPROFILE- and tmpdir-fallback regression
tests.

Co-Authored-By: Claude Fable 5 <[email protected]>
jeff-r2026 added a commit that referenced this pull request Aug 24, 2026
…309)

PR #301 introduced getUserHome() (HOME → USERPROFILE → os.homedir) but only
wired it into types.ts. The rest of the codebase still read a bare
`process.env.HOME`, so on a normal Windows session (where only USERPROFILE is
set) `teamai init` printed "Local config saved to undefined/..." and then
crashed with ERR_INVALID_ARG_TYPE — the exact failure reported on #301.

Route every remaining home lookup through getUserHome(). Because it now always
returns a non-empty path, drop the dead `if (!home)` guards it made
unreachable (including one in uninstall.ts that used to abort the whole command
when HOME was unset — i.e. uninstall was fully broken on Windows). Fix
getVotesLocalDir(), the import/recall/search-index paths and the debug-log path
to build with path.join instead of a hardcoded "/" separator.

Harden getUserHome() with a final os.tmpdir() fallback: os.homedir() is
documented to return '' when the home can't be resolved, which would make every
derived path cwd-relative; the guarantee of a non-empty absolute path is what
lets the callers above drop their guards safely.

Add a guard test that fails if any source file outside utils/home.ts reads
process.env.HOME directly, plus USERPROFILE- and tmpdir-fallback regression
tests.

Co-authored-by: Claude Fable 5 <[email protected]>
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
* feat(git): support generic private repository hosts

* fix(git): address generic provider review comments

* fix(git): harden generic provider portability

---------

Co-authored-by: liuyuanchuang <[email protected]>
Co-authored-by: yoge <[email protected]>
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…Tencent#307)

Adds a GitLab provider (REST API v4, no external CLI) supporting gitlab.com
and self-hosted / enterprise instances: clone, create repo, create MR with
reviewer resolution, fetch MR data, and list group repos.

Detection order is known host -> self-hosted GitLab (GITLAB_URL /
TEAMAI_GITLAB_HOST) -> the generic `git` transport provider, across HTTPS,
ssh:// and scp-style URLs. This complements the generic provider from Tencent#301,
which is transport-only and cannot create repos or merge requests.

Includes review fixes: clone and MR URLs honour the instance scheme, port and
path prefix; GITLAB_URL is validated and resolved lazily; the MR fetcher
queries the host named by the URL; `/-/` route paths are stripped when parsing
repo input; group namespaces resolve by exact path and fail rather than
falling back to the personal namespace; group listing includes subgroups;
blank tokens read as absent. Wires GitLab into the MR-import dispatcher, the
org-import provider resolution, shallowClone token injection, and doctor.

Co-Authored-By: Shin Yang <[email protected]>
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…ut (Tencent#308)

Two follow-up fixes for the generic Git provider (Tencent#301):

- parseGenericGitRepoInput accepted scp-style URLs whose user field
  carried credentials (e.g. "oauth2:token@host:group/repo.git"),
  returning them verbatim while the HTTPS path already rejected embedded
  credentials. A colon in the SSH user field is a credential, never a
  real login, so reject it. Normal "git@host:..." logins are unaffected.
- Clone timeout was 120s, shorter than the 180s default used by the
  shallow-clone path in clone.ts. Large self-hosted repos over slow/VPN
  links could time out where the equivalent path would not. Align to 180s.

Co-authored-by: Claude Fable 5 <[email protected]>
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…encent#309)

PR Tencent#301 introduced getUserHome() (HOME → USERPROFILE → os.homedir) but only
wired it into types.ts. The rest of the codebase still read a bare
`process.env.HOME`, so on a normal Windows session (where only USERPROFILE is
set) `teamai init` printed "Local config saved to undefined/..." and then
crashed with ERR_INVALID_ARG_TYPE — the exact failure reported on Tencent#301.

Route every remaining home lookup through getUserHome(). Because it now always
returns a non-empty path, drop the dead `if (!home)` guards it made
unreachable (including one in uninstall.ts that used to abort the whole command
when HOME was unset — i.e. uninstall was fully broken on Windows). Fix
getVotesLocalDir(), the import/recall/search-index paths and the debug-log path
to build with path.join instead of a hardcoded "/" separator.

Harden getUserHome() with a final os.tmpdir() fallback: os.homedir() is
documented to return '' when the home can't be resolved, which would make every
derived path cwd-relative; the guarantee of a non-empty absolute path is what
lets the callers above drop their guards safely.

Add a guard test that fails if any source file outside utils/home.ts reads
process.env.HOME directly, plus USERPROFILE- and tmpdir-fallback regression
tests.

Co-authored-by: Claude Fable 5 <[email protected]>
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.

feat: support self-hosted private Git repositories via a generic provider

5 participants