feat: permissions (#168)
- Load `app-permissions` from schema exported by `@octokit/openapi` - Update documentation in README.md - Implement the `permissions_*` inputs in the action code --------- Co-authored-by: Parker Brown <17183625+parkerbxyz@users.noreply.github.com>
This commit is contained in:
co-authored by
Parker Brown
parent
f577941506
commit
0e0aa99a86
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Finds all permissions passed via `permision-*` inputs and turns them into an object.
|
||||
*
|
||||
* @see https://docs.github.com/en/actions/sharing-automations/creating-actions/metadata-syntax-for-github-actions#inputs
|
||||
* @param {NodeJS.ProcessEnv} env
|
||||
* @returns {undefined | Record<string, string>}
|
||||
*/
|
||||
export function getPermissionsFromInputs(env) {
|
||||
return Object.entries(env).reduce((permissions, [key, value]) => {
|
||||
if (!key.startsWith("INPUT_PERMISSION_")) return permissions;
|
||||
|
||||
const permission = key.slice("INPUT_PERMISSION_".length).toLowerCase();
|
||||
if (permissions === undefined) {
|
||||
return { [permission]: value };
|
||||
}
|
||||
|
||||
return {
|
||||
// @ts-expect-error - needs to be typed correctly
|
||||
...permissions,
|
||||
[permission]: value,
|
||||
};
|
||||
}, undefined);
|
||||
}
|
||||
Reference in New Issue
Block a user