Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add a flag to error if missing #13

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
| username | Obtained from the context by default, can also be customized to pass in | string | ✖ |
| check-bot | Check whether the user is a bot | boolean | ✖ |
| check-contributor | Check whether the user is contributor | boolean | ✖ |
| error-if-missing | Error if require or check if false | boolean | ✖ |

- User permission: `admin` > `write` > `read`
- `username` support [github context](https://docs.github.com/en/actions/learn-github-actions/contexts#github-context)
Expand Down
13 changes: 11 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,42 @@ async function run() {
return contributors;
}

if (checkBot == 'true') {
if (checkBot === 'true') {
const { data } = await octokit.users.getByUsername({
username,
});
if (data.type === 'Bot') {
checkResult = true;
}
} else if (checkContributor == 'true') {
} else if (checkContributor === 'true') {
let contributors = await queryContributors();
contributors = contributors.map(({ login }) => login);
if (contributors.length) {
checkResult = contributors.includes(username);
}
}

checkFailed = false;
if (checkBot || checkContributor) {
core.info(`[Action Check] The check result is ${checkResult}.`);
core.setOutput('check-result', checkResult);
checkFailed = checkFailed || !checkResult;
}

if (require) {
requireResult = checkPermission(require, permission);
core.info(`[Action Require] The ${username} permission check is ${requireResult}.`);
core.setOutput('require-result', requireResult);
checkFailed = checkFailed || !requireResult;
}

const errorIfMissing = core.getInput('error-if-missing');
if (checkFailed && (errorIfMissing === 'true')) {
core.setFailed('The required check failed.');
}

core.info(THANKS);

} catch (error) {
core.setFailed(error.message);
}
Expand Down
Loading