async function run()

in permission-check/index.js [28:76]


async function run() {
    var _a;
    const desiredPermission = core.getInput('permission');
    const desiredTeamOptions = core.getInput('teams');
    if (!desiredPermission && !desiredTeamOptions) {
        throw Error('No "permission" or "team" options specified. At least one must be specified.');
    }
    const username = core.getInput('username') || github_1.context.actor;
    const errors = [];
    if (desiredPermission) {
        const perms = ['none', 'read', 'write', 'admin'];
        if (perms.indexOf(desiredPermission) < 0) {
            throw Error(`Invalid desired permission: ${desiredPermission}`);
        }
        const response = await (0, github_1.getOctokit)(core.getInput('token')).rest.repos.getCollaboratorPermissionLevel({
            ...github_1.context.repo,
            username,
        });
        const userPermission = response.data.permission;
        if (perms.indexOf(userPermission) < perms.indexOf(desiredPermission)) {
            errors.push(`User '${username}' did not have at least permission '${desiredPermission}', had ${userPermission}`);
        }
        else {
            return true;
        }
    }
    if (desiredTeamOptions) {
        const teamOptions = desiredTeamOptions.split(',').map((t) => t.trim().replace('@', ''));
        for (const teamOption of teamOptions) {
            try {
                const response = await (0, github_1.getOctokit)(core.getInput('token')).rest.teams.getMembershipForUserInOrg({
                    org: github_1.context.repo.owner,
                    team_slug: teamOption,
                    username: username,
                });
                if (((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.state) === 'active') {
                    return true;
                }
            }
            catch (ex) {
                // 404 == not a member of the team
            }
        }
        errors.push(`User '${username}' was not a member of any of the teams: ${teamOptions.join(', ')}`);
    }
    if (errors.length) {
        throw Error(errors.join(' '));
    }
}