Add Gitea as a git provider for harness workspace repositories
Some checks failed
CI / lint-and-test (push) Successful in 30s
CI / build (push) Has been cancelled
Deploy Production / deploy (push) Has been cancelled

Support Gitea alongside GitHub/GitLab for repo search, authenticated
cloning, and pull request creation via Gitea API. Tasks can specify
gitProvider and gitBaseUrl in their spec (defaults to github for
backwards compat). Auto-discovers GITEA_TOKEN from env on boot.
This commit is contained in:
Julia McGhee
2026-03-21 20:33:24 +00:00
parent 11192da432
commit a687652bcd
6 changed files with 106 additions and 10 deletions

View File

@@ -1,7 +1,7 @@
import { getRawCredentialsByProvider } from "./credentials";
export interface RepoResult {
provider: "github" | "gitlab";
provider: "github" | "gitlab" | "gitea";
fullName: string;
url: string;
description: string;
@@ -15,6 +15,7 @@ export async function searchRepos(query: string): Promise<RepoResult[]> {
const results = await Promise.allSettled([
searchGitHub(query),
searchGitLab(query),
searchGitea(query),
]);
return results.flatMap(r => r.status === "fulfilled" ? r.value : []);
@@ -98,3 +99,42 @@ async function searchGitLab(query: string): Promise<RepoResult[]> {
return results;
}
async function searchGitea(query: string): Promise<RepoResult[]> {
const creds = await getRawCredentialsByProvider("gitea");
if (creds.length === 0) return [];
const results: RepoResult[] = [];
for (const cred of creds) {
const baseUrl = cred.baseUrl || "https://gitea.coreworlds.io";
try {
const res = await fetch(
`${baseUrl}/api/v1/repos/search?q=${encodeURIComponent(query)}&limit=10&sort=updated`,
{
headers: {
Authorization: `token ${cred.token}`,
},
}
);
if (!res.ok) continue;
const data = await res.json();
for (const repo of data.data || []) {
results.push({
provider: "gitea",
fullName: repo.full_name,
url: repo.html_url,
description: repo.description || "",
defaultBranch: repo.default_branch || "main",
private: repo.private,
});
}
} catch {
// skip failed credential
}
}
return results;
}