Add Gitea as a git provider for harness workspace repositories
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user