Refactor using gitea-js.
This commit is contained in:
@@ -47770,8 +47770,10 @@ var package_default = {
|
|||||||
axios: "^1.3.4",
|
axios: "^1.3.4",
|
||||||
chalk: "^5.2.0",
|
chalk: "^5.2.0",
|
||||||
cleye: "^1.3.2",
|
cleye: "^1.3.2",
|
||||||
|
"cross-fetch": "^4.1.0",
|
||||||
crypto: "^1.0.1",
|
crypto: "^1.0.1",
|
||||||
execa: "^7.0.0",
|
execa: "^7.0.0",
|
||||||
|
"gitea-js": "^1.23.0",
|
||||||
ignore: "^5.2.4",
|
ignore: "^5.2.4",
|
||||||
ini: "^3.0.1",
|
ini: "^3.0.1",
|
||||||
inquirer: "^9.1.4",
|
inquirer: "^9.1.4",
|
||||||
|
|||||||
+7908
-4490
File diff suppressed because it is too large
Load Diff
+13
-12
@@ -4,6 +4,8 @@ import { outro } from '@clack/prompts';
|
|||||||
import { generateCommitMessageByDiff } from './generateCommitMessageFromGitDiff';
|
import { generateCommitMessageByDiff } from './generateCommitMessageFromGitDiff';
|
||||||
import { randomIntFromInterval } from './utils/randomIntFromInterval';
|
import { randomIntFromInterval } from './utils/randomIntFromInterval';
|
||||||
import { sleep } from './utils/sleep';
|
import { sleep } from './utils/sleep';
|
||||||
|
import { giteaApi } from 'gitea-js';
|
||||||
|
import fetch from 'cross-fetch';
|
||||||
|
|
||||||
// This should be a token with access to your repository scoped in as a secret.
|
// This should be a token with access to your repository scoped in as a secret.
|
||||||
const GITHUB_TOKEN = core.getInput('GITHUB_TOKEN');
|
const GITHUB_TOKEN = core.getInput('GITHUB_TOKEN');
|
||||||
@@ -13,18 +15,16 @@ const GITEA_URL = core.getInput('GITEA_URL') || 'https://try.gitea.io';
|
|||||||
|
|
||||||
// Initialize platform-specific clients
|
// Initialize platform-specific clients
|
||||||
let octokit: ReturnType<typeof github.getOctokit>;
|
let octokit: ReturnType<typeof github.getOctokit>;
|
||||||
let giteaClient: any; // We'll initialize this properly below
|
let giteaClient: ReturnType<typeof giteaApi>;
|
||||||
|
|
||||||
if (PLATFORM === 'gitea' || PLATFORM === 'forgejo') {
|
if (PLATFORM === 'gitea' || PLATFORM === 'forgejo') {
|
||||||
// Dynamically import the Gitea client
|
|
||||||
try {
|
try {
|
||||||
const gitea = require('@go-gitea/sdk.js').ApiClient;
|
giteaClient = giteaApi(GITEA_URL, {
|
||||||
giteaClient = new gitea({
|
token: GITHUB_TOKEN,
|
||||||
baseUrl: GITEA_URL,
|
customFetch: fetch,
|
||||||
auth: GITHUB_TOKEN,
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.error(`Failed to import Gitea client: ${error}`);
|
core.error(`Failed to import/initialize Gitea client: ${error}`);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -41,16 +41,16 @@ type Diff = string;
|
|||||||
async function getCommitDiff(commitSha: string): Promise<{ sha: SHA; diff: Diff }> {
|
async function getCommitDiff(commitSha: string): Promise<{ sha: SHA; diff: Diff }> {
|
||||||
if (PLATFORM === 'gitea' || PLATFORM === 'forgejo') {
|
if (PLATFORM === 'gitea' || PLATFORM === 'forgejo') {
|
||||||
try {
|
try {
|
||||||
const diffResponse = await giteaClient.repository.repoDownloadCommitDiffOrPatch({
|
const response = await giteaClient.repos.repoDownloadCommitDiffOrPatch(
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
sha: commitSha,
|
commitSha,
|
||||||
diffType: 'diff',
|
'diff'
|
||||||
});
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sha: commitSha,
|
sha: commitSha,
|
||||||
diff: diffResponse.data,
|
diff: response.data,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.error(`Failed to fetch Gitea/Forgejo commit diff: ${error}`);
|
core.error(`Failed to fetch Gitea/Forgejo commit diff: ${error}`);
|
||||||
@@ -75,6 +75,7 @@ async function getCommitDiff(commitSha: string): Promise<{ sha: SHA; diff: Diff
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
interface DiffAndSHA {
|
interface DiffAndSHA {
|
||||||
sha: SHA;
|
sha: SHA;
|
||||||
diff: Diff;
|
diff: Diff;
|
||||||
|
|||||||
Reference in New Issue
Block a user