Skip to content

feat: support self-hosted Gitea teams and PR imports - #1208

Closed
alheart wants to merge 10 commits into
Tencent:mainfrom
alheart:gitea-provider
Closed

alheart wants to merge 10 commits into
Tencent:mainfrom
alheart:gitea-provider

Conversation

@alheart

@alheart alheart commented Oct 19, 2026

Copy link
Copy Markdown

Adds a self-hosted Gitea provider for team init, HTTP/SSH clone and push, PR creation/recovery, and merged-PR import. Main can also import review bodies, inline comments and ordinary comments while preserving source IDs and unknown resolution state.

Uses a full GITEA_URL and PAT from GITEA_TOKEN or netrc. Validates HTTP instance boundaries before attaching credentials, preserves SSH transport/port, bounds requests, paginates lists, matches duplicate PRs by repositories/head/base, and handles reviewer failures independently.

Includes registry/schema/help/doctor/clone/import wiring, bilingual user docs, all README locales, generated command reference, and an English design listing shared-state readers/writers. The core push algorithm stays unchanged.

Validation

  • Main runtime 4a047e8: typecheck, lint, build and full unit suite passed, 11,077 tests passed / 25 skipped. Head 8106be0 changes only validation documentation. Separate v0.27.0 backport 30eb00f: same checks passed, 8,208 tests passed / 19 skipped.
  • Actual current packaged CLI against Gitea 1.27.3: interactive init, hidden input and netrc permissions; valid environment-token init; missing-token rejection without a TTY; instance detection; HTTP push creating a PR with a reviewer; changed-resource repeat push updating the same branch and PR, confirmed by reading remote content.
  • Actual packaged CLI: dedicated test SSH identity, nondefault port clone/push, origin preserved and PR created.
  • Actual packaged import --from-mr --all --output against a merged test PR, followed by a real Claude invocation: CLI and model exited 0, nonempty draft produced. Main's prompt contained review, inline and conversation evidence. No credentials were present in the model input.
  • Current-source live modules: anonymous public clone/fetch with known SHA/file and private denial; merged-PR metadata/commits/diff; unique discussion sources; 70 commits and 140 distinct review/comment bodies; exact same-head/different-base PR recovery; valid/invalid reviewer handling; cross-instance rejection; PAT revocation/rotation, explicit HTTP-origin update and independent SSH credentials.
  • Empty-repo bootstrap followed by protected-main member registration passed. A pre-protected empty repository retained no skeleton; this check uses remote state because existing init can warn and exit 0 on a rejected bootstrap push.
  • Doctor's two Gitea configuration checks and missing-instance fix passed. Missing agent hooks in the test environment keep overall doctor nonzero; it is not claimed fully green.
  • Separate Forgejo 15.0.10 fixtures: current packages passed init, push/reviewer and actual CLI/real-model merged-PR import. Main also passed repeated PR reuse and discussion-source checks. Compatibility is limited to that subset/version.
  • URL diagnostic regression: focused tests and actual packaged rejection cases verified that synthetic userinfo/query/fragment markers do not appear in errors. Useful host/path context remains.

Focused Gitea coverage: statements/lines 97.62%, branches 84.41%, functions 89.36%. Extra provider/agent combinations are left to CI. Generated learning files remain drafts requiring content review; successful extraction does not guarantee factual accuracy.

Copilot AI balanced review requested due to automatic review settings October 19, 2026 01:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Credential-file preservation and Gitea source and organization handling have confirmed defects that need correction.

5 open issues
What changed in this PR

Adds self-hosted Gitea support to TeamAI’s provider layer for team setup, sharing and PR imports.

Changes:

  • Adds instance validation, authentication, Git transport and PR operations.
  • Integrates Gitea with discovery, diagnostics and discussion-aware imports.
  • Adds regression tests, opt-in live coverage and setup documentation.
File Description
src/​types.ts Adds Gitea provider schema value.
src/​providers/​registry.ts Registers Gitea and instance detection.
src/​providers/​index.ts Exports Gitea provider.
src/​providers/​gitea/​repo-url.ts Validates instance and repository URLs.
src/​providers/​gitea/​probe.ts Probes instances anonymously.
src/​providers/​gitea/​org.ts Implements organization operations.
src/​providers/​gitea/​mr-fetch.ts Fetches PR evidence and discussions.
src/​providers/​gitea/​index.ts Implements provider interface.
src/​providers/​gitea/​gitea-api.ts Adds authentication, transport and API operations.
src/​init.ts Preserves Gitea clone transport.
src/​index.ts Updates provider option help.
src/​import.ts Sanitizes batch URL diagnostics.
src/​import-mr.ts Routes Gitea imports and clarifies evidence guidance.
src/​doctor.ts Checks Gitea configuration.
src/​clone.ts Integrates Gitea clone/fetch authentication.
src/​__tests__/​provider-fallback.test.ts Tests Gitea default selection.
src/​__tests__/​init.test.ts Tests accepted provider names.
src/​__tests__/​import-mr.test.ts Tests routing and diagnostic redaction.
src/​__tests__/​import-mr-threads.test.ts Tests unknown-resolution guidance.
src/​__tests__/​import-mr-learnings-checkout.test.ts Preserves real diagnostic helper exports.
src/​__tests__/​gitlab-probe.test.ts Accounts for additional discovery probe.
src/​__tests__/​gitea-provider.test.ts Tests Gitea provider behavior.
src/​__tests__/​e2e/​gitea-provider-live.test.ts Adds opt-in live integration coverage.
skill-data/​setup/​references/​setup-admin.md Adds Gitea onboarding guidance.
skill-data/​core/​references/​commands.md Updates generated provider help.
README.zh-CN.md Lists Gitea support.
README.th.md Lists Gitea support.
README.md Lists Gitea support.
README.ko.md Lists Gitea support.
README.ja.md Lists Gitea support.
docs/​usage-guide.zh-CN.md Links Gitea setup guidance.
docs/​usage-guide.md Links Gitea setup guidance.
docs/​guide/​zh-CN/​providers.md Documents Gitea setup and limitations.
docs/​guide/​providers.md Documents Gitea setup and limitations.
docs/​designs/​README.md Indexes Gitea design.
docs/​designs/​gitea-provider.md Records architecture and validation.

Review effort: Balanced

Comment on lines +66 to +67
const retained = previous.replace(/\bmachine\s+(\S+)[\s\S]*?(?=\bmachine\s+|\bdefault\b|\bmacdef\b|$)/g,
(entry, name: string) => name.toLowerCase() === host ? '' : entry).trimEnd();
}

function orgName(org: string): string {
return parseGiteaRepoInput(`${org}/validation`).owner;
Comment thread src/providers/registry.ts
*/
function resolveHostProvider(host: string): string {
return HOST_MAP[host] ?? detectSelfHostedGitLabHost(host) ?? 'git';
return HOST_MAP[host] ?? detectSelfHostedGitLabHost(host) ?? (isConfiguredGiteaHost(host) ? 'gitea' : 'git');
Comment on lines +38 to +39
if (tokens[i] === 'machine') machine = tokens[++i]?.toLowerCase() ?? '';
else if (tokens[i] === 'default' || tokens[i] === 'macdef') machine = '';
// Swagger declares since/before for issue comments and no pagination for
// review comments. Only the reviews collection accepts page/limit.
try {
const comments = await giteaJson<GiteaComment[]>(route.replace('/pulls/', '/issues/') + '/comments');
@jeff-r2026 jeff-r2026 self-assigned this Oct 19, 2026
@github-actions

Copy link
Copy Markdown
  • [P2 non-blocking] src/providers/gitea/mr-fetch.ts:80 — route.replace('/pulls/', '/issues/') replaces the first match, which can be the owner or repository name. For org/pulls, it requests /repos/org/issues/pulls/N/comments instead of /repos/org/pulls/issues/N/comments; ordinary PR comments are then omitted with a warning. Build the issues endpoint explicitly or replace only the terminal PR segment.

The PR description documents sufficient built-CLI end-to-end verification. Extra provider/agent coverage is explicitly deferred to CI; no testing-record finding.

Reviewed only the specified diff. No PR code was run, built, or installed.

@SaulMoro

Copy link
Copy Markdown
Collaborator

@alheart Copilot and Codex flagged a few issues in review. Mind taking a look?

@SaulMoro SaulMoro 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.

This was generated by AI during triage.

@alheart The branch at 8106be02 conflicts with main in src/init.ts, which has changed since your base (#1207, #1226, #1245, #1221, #1272, #1268). Please rebase onto current main and resolve the conflict. We'll review the rebased head. The points from our earlier comment still apply.

@jeff-r2026 jeff-r2026 closed this Oct 24, 2026
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.

4 participants