getCommitDiff function.
This commit is contained in:
+25
-18
@@ -90186,8 +90186,9 @@ var giteaClient;
|
||||
if (PLATFORM === "gitea" || PLATFORM === "forgejo") {
|
||||
try {
|
||||
const GiteaClient = (init_dist_bundle7(), __toCommonJS(dist_bundle_exports)).Gitea;
|
||||
giteaClient = new GiteaClient(GITEA_URL, {
|
||||
token: GITHUB_TOKEN
|
||||
giteaClient = new GiteaClient({
|
||||
baseUrl: GITEA_URL,
|
||||
auth: GITHUB_TOKEN
|
||||
});
|
||||
} catch (error2) {
|
||||
core.error(`Failed to import Gitea client: ${error2}`);
|
||||
@@ -90202,27 +90203,33 @@ var repo = context2.repo.repo;
|
||||
async function getCommitDiff(commitSha) {
|
||||
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 diffResponse2 = await giteaClient.repository.repoDownloadCommitDiffOrPatch({
|
||||
owner,
|
||||
repo,
|
||||
sha: commitSha,
|
||||
diffType: "diff"
|
||||
});
|
||||
return {
|
||||
sha: commitSha,
|
||||
diff: diffResponse2.data
|
||||
};
|
||||
} catch (error2) {
|
||||
core.error(`Failed to fetch Gitea/Forgejo commit diff: ${error2}`);
|
||||
throw error2;
|
||||
}
|
||||
} else {
|
||||
const diffResponse = await octokit.request(
|
||||
"GET /repos/{owner}/{repo}/commits/{ref}",
|
||||
{
|
||||
owner,
|
||||
repo,
|
||||
ref: commitSha,
|
||||
headers: {
|
||||
Accept: "application/vnd.github.v3.diff"
|
||||
}
|
||||
}
|
||||
);
|
||||
return { sha: commitSha, diff: diffResponse.data };
|
||||
}
|
||||
const diffResponse = await octokit.request(
|
||||
"GET /repos/{owner}/{repo}/commits/{ref}",
|
||||
{
|
||||
owner,
|
||||
repo,
|
||||
ref: commitSha,
|
||||
headers: {
|
||||
Accept: "application/vnd.github.v3.diff"
|
||||
}
|
||||
}
|
||||
);
|
||||
return { sha: commitSha, diff: diffResponse.data };
|
||||
}
|
||||
async function improveMessagesInChunks(diffsAndSHAs) {
|
||||
const chunkSize = diffsAndSHAs.length % 2 === 0 ? 4 : 3;
|
||||
|
||||
+30
-18
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user