Initial commit

This commit is contained in:
Lina Tawfik
2025-05-19 08:32:32 -07:00
commit f66f337f4e
58 changed files with 8913 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
import * as core from "@actions/core";
import type { ParsedGitHubContext } from "../context";
import type { Octokit } from "@octokit/rest";
/**
* Check if the actor has write permissions to the repository
* @param octokit - The Octokit REST client
* @param context - The GitHub context
* @returns true if the actor has write permissions, false otherwise
*/
export async function checkWritePermissions(
octokit: Octokit,
context: ParsedGitHubContext,
): Promise<boolean> {
const { repository, actor } = context;
try {
core.info(`Checking permissions for actor: ${actor}`);
// Check permissions directly using the permission endpoint
const response = await octokit.repos.getCollaboratorPermissionLevel({
owner: repository.owner,
repo: repository.repo,
username: actor,
});
const permissionLevel = response.data.permission;
core.info(`Permission level retrieved: ${permissionLevel}`);
if (permissionLevel === "admin" || permissionLevel === "write") {
core.info(`Actor has write access: ${permissionLevel}`);
return true;
} else {
core.warning(`Actor has insufficient permissions: ${permissionLevel}`);
return false;
}
} catch (error) {
core.error(`Failed to check permissions: ${error}`);
throw new Error(`Failed to check permissions for ${actor}: ${error}`);
}
}