mirror of
https://github.com/markwylde/claude-code-gitea-action.git
synced 2026-02-20 02:22:49 +08:00
Attempt to make this work
This commit is contained in:
@@ -5,7 +5,13 @@ export type GitHubClient = {
|
||||
};
|
||||
|
||||
export function createClient(token: string): GitHubClient {
|
||||
// Use the GITEA_API_URL environment variable if provided
|
||||
const apiUrl = process.env.GITEA_API_URL;
|
||||
console.log(
|
||||
`Creating client with API URL: ${apiUrl || "default (https://api.github.com)"}`,
|
||||
);
|
||||
|
||||
return {
|
||||
api: createGiteaClient(token),
|
||||
api: apiUrl ? new GiteaApiClient(token, apiUrl) : createGiteaClient(token),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -25,12 +25,17 @@ export class GiteaApiClient {
|
||||
this.baseUrl = baseUrl.replace(/\/+$/, ""); // Remove trailing slashes
|
||||
}
|
||||
|
||||
getBaseUrl(): string {
|
||||
return this.baseUrl;
|
||||
}
|
||||
|
||||
private async request<T = any>(
|
||||
method: string,
|
||||
endpoint: string,
|
||||
body?: any,
|
||||
): Promise<GiteaApiResponse<T>> {
|
||||
const url = `${this.baseUrl}${endpoint}`;
|
||||
console.log(`Making ${method} request to: ${url}`);
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@@ -14,19 +14,53 @@ export async function checkWritePermissions(
|
||||
): Promise<boolean> {
|
||||
const { repository, actor } = context;
|
||||
|
||||
core.info(
|
||||
`Environment check - GITEA_API_URL: ${process.env.GITEA_API_URL || "undefined"}`,
|
||||
);
|
||||
core.info(`API client base URL: ${api.getBaseUrl?.() || "undefined"}`);
|
||||
|
||||
// For Gitea compatibility, check if we're in a non-GitHub environment
|
||||
const giteaApiUrl = process.env.GITEA_API_URL?.trim();
|
||||
const isGitea =
|
||||
process.env.GITEA_API_URL &&
|
||||
!process.env.GITEA_API_URL.includes("api.github.com");
|
||||
giteaApiUrl &&
|
||||
giteaApiUrl !== "" &&
|
||||
!giteaApiUrl.includes("api.github.com") &&
|
||||
!giteaApiUrl.includes("github.com");
|
||||
|
||||
if (isGitea) {
|
||||
core.info(`Detected Gitea environment, assuming actor has permissions`);
|
||||
core.info(
|
||||
`Detected Gitea environment (${giteaApiUrl}), assuming actor has permissions`,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Also check if the API client base URL suggests we're using Gitea
|
||||
const apiUrl = api.getBaseUrl?.() || "";
|
||||
if (
|
||||
apiUrl &&
|
||||
!apiUrl.includes("api.github.com") &&
|
||||
!apiUrl.includes("github.com")
|
||||
) {
|
||||
core.info(
|
||||
`Detected non-GitHub API URL (${apiUrl}), assuming actor has permissions`,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we're still here, we might be using GitHub's API, so attempt the permissions check
|
||||
core.info(
|
||||
`Proceeding with GitHub-style permission check for actor: ${actor}`,
|
||||
);
|
||||
|
||||
// However, if the API client is clearly pointing to a non-GitHub URL, skip the check
|
||||
if (apiUrl && apiUrl !== "https://api.github.com") {
|
||||
core.info(
|
||||
`API URL ${apiUrl} doesn't look like GitHub, assuming permissions and skipping check`,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
core.info(`Checking permissions for actor: ${actor}`);
|
||||
|
||||
// Check permissions directly using the permission endpoint
|
||||
const response = await api.customRequest(
|
||||
"GET",
|
||||
|
||||
Reference in New Issue
Block a user