getCommitDiff function.
Testing / prettier (push) Failing after 2m17s
Testing / unit-test (20.x) (push) Failing after 3m45s
Testing / e2e-test (20.x) (push) Failing after 5m13s

This commit is contained in:
2026-01-04 13:20:10 -05:00
parent df41cb291a
commit 8a8989e92a
2 changed files with 55 additions and 36 deletions
+30 -18
View File
@@ -19,8 +19,9 @@ if (PLATFORM === 'gitea' || PLATFORM === 'forgejo') {
// Dynamically import the Gitea client
try {
const GiteaClient = require('@go-gitea/sdk.js').Gitea;
giteaClient = new GiteaClient(GITEA_URL, {
token: GITHUB_TOKEN
giteaClient = new GiteaClient({
baseUrl: GITEA_URL,
auth: GITHUB_TOKEN,
});
} catch (error) {
core.error(`Failed to import Gitea client: ${error}`);
@@ -40,27 +41,38 @@ type Diff = string;
async function getCommitDiff(commitSha: string): Promise<{ sha: SHA; diff: Diff }> {
if (PLATFORM === 'gitea' || PLATFORM === 'forgejo') {
try {
const commit = await giteaClient.getCommit(owner, repo, commitSha);
const diffResponse = await giteaClient.getRepoCommitDiff(owner, repo, commitSha);
return { sha: commitSha, diff: diffResponse.data };
const diffResponse =
await giteaClient.repository.repoDownloadCommitDiffOrPatch({
owner,
repo,
sha: commitSha,
diffType: 'diff',
});
return {
sha: commitSha,
diff: diffResponse.data,
};
} catch (error) {
core.error(`Failed to fetch Gitea/Forgejo commit diff: ${error}`);
throw error;
}
} else {
const diffResponse = await octokit.request<string>(
'GET /repos/{owner}/{repo}/commits/{ref}',
{
owner,
repo,
ref: commitSha,
headers: {
Accept: 'application/vnd.github.v3.diff'
}
}
);
return { sha: commitSha, diff: diffResponse.data };
}
// GitHub fallback remains correct
const diffResponse = await octokit.request<string>(
'GET /repos/{owner}/{repo}/commits/{ref}',
{
owner,
repo,
ref: commitSha,
headers: {
Accept: 'application/vnd.github.v3.diff',
},
}
);
return { sha: commitSha, diff: diffResponse.data };
}
interface DiffAndSHA {