|
|
|
@@ -43,6 +43,20 @@ function extractOutputText(response) {
|
|
|
|
|
return parts.join("\n").trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resolveGiteaApiUrl(event) {
|
|
|
|
|
if (process.env.GITEA_API_URL) return process.env.GITEA_API_URL;
|
|
|
|
|
|
|
|
|
|
const repositoryApiUrl = event.repository?.url;
|
|
|
|
|
const reposMarker = "/repos/";
|
|
|
|
|
const markerIndex = repositoryApiUrl?.indexOf(reposMarker) ?? -1;
|
|
|
|
|
if (markerIndex > 0) return repositoryApiUrl.slice(0, markerIndex);
|
|
|
|
|
|
|
|
|
|
const serverUrl = process.env.GITEA_SERVER_URL;
|
|
|
|
|
if (serverUrl) return `${serverUrl.replace(/\/$/, "")}/api/v1`;
|
|
|
|
|
|
|
|
|
|
throw new Error("Cannot determine the Gitea API URL from the environment or event payload");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function upsertComment({ apiUrl, token, owner, repo, number, body }) {
|
|
|
|
|
const headers = {
|
|
|
|
|
Accept: "application/json",
|
|
|
|
@@ -98,7 +112,7 @@ async function main() {
|
|
|
|
|
const diff = runGit(["diff", "--no-ext-diff", "--unified=30", `${baseSha}...${headSha}`]);
|
|
|
|
|
const number = pull.number || event.number;
|
|
|
|
|
const commentContext = {
|
|
|
|
|
apiUrl: required("GITEA_API_URL"),
|
|
|
|
|
apiUrl: resolveGiteaApiUrl(event),
|
|
|
|
|
token: required("GITEA_TOKEN"),
|
|
|
|
|
owner,
|
|
|
|
|
repo,
|
|
|
|
|