Files
Tom Moor 9aad5a4bb7 feat: Add Gitea / Forgejo integration (#14336)
* feat: Add Gitea integration for issue, pull request, and repository previews

* fix: Gitea repository previews and request deadlines

Refresh the token before repository discovery, keep repository previews when
the issue tracker is disabled, and keep the request timeout active while the
response body is read.

* chore: Use the shared fetch timeout for Gitea requests

* chore: Mention Forgejo in Gitea copy and reuse the callback URL helper

* Remove service specific getters in IntegrationsStore
2026-10-25 18:04:04 -04:00

69 lines
1.9 KiB
TypeScript

import { toError } from "@shared/utils/error";
import type { IssueSource } from "@shared/schema";
import { IntegrationService, type IntegrationType } from "@shared/types";
import Logger from "@server/logging/Logger";
import type { Integration } from "@server/models";
import { IntegrationAuthentication } from "@server/models";
import { BaseIssueProvider } from "@server/utils/BaseIssueProvider";
import { Gitea } from "./gitea";
export class GiteaIssueProvider extends BaseIssueProvider {
constructor() {
super(IntegrationService.Gitea);
}
async fetchSources(
integration: Integration<IntegrationType.Embed>
): Promise<IssueSource[]> {
await integration.reload({
include: [
{
model: IntegrationAuthentication,
as: "authentication",
required: true,
},
],
});
const baseUrl = integration.settings?.gitea?.url;
if (!integration.authentication || !baseUrl) {
Logger.warn("Gitea integration without authentication");
return [];
}
try {
const { authentication } = integration;
const accessToken = await authentication.refreshTokenIfNeeded(
async (refreshToken: string) =>
Gitea.refreshToken({
baseUrl,
refreshToken,
clientId: authentication.clientId,
clientSecret: authentication.clientSecret,
})
);
const repositories = await Gitea.getRepositories({
baseUrl,
accessToken,
});
return repositories.map<IssueSource>((repo) => ({
id: String(repo.id),
name: repo.name,
owner: {
id: String(repo.owner.id),
name: repo.owner.login,
},
service: IntegrationService.Gitea,
}));
} catch (err) {
Logger.warn("Failed to fetch repositories from Gitea", toError(err));
return [];
}
}
async handleWebhook() {
// Gitea has no application level webhooks to subscribe to.
}
}