Skip to content

Commit ce3ba6e

Browse files
committed
add a flag to error if missing
1 parent 956b2e7 commit ce3ba6e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
| username | Obtained from the context by default, can also be customized to pass in | string | ✖ |
3030
| check-bot | Check whether the user is a bot | boolean | ✖ |
3131
| check-contributor | Check whether the user is contributor | boolean | ✖ |
32+
| error-if-missing | Error if require or check if false | boolean | ✖ |
3233
3334
- User permission: `admin` > `write` > `read`
3435
- `username` support [github context](https://docs.github.com/en/actions/learn-github-actions/contexts#github-context)

src/main.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,42 @@ async function run() {
5050
return contributors;
5151
}
5252

53-
if (checkBot == 'true') {
53+
if (checkBot === 'true') {
5454
const { data } = await octokit.users.getByUsername({
5555
username,
5656
});
5757
if (data.type === 'Bot') {
5858
checkResult = true;
5959
}
60-
} else if (checkContributor == 'true') {
60+
} else if (checkContributor === 'true') {
6161
let contributors = await queryContributors();
6262
contributors = contributors.map(({ login }) => login);
6363
if (contributors.length) {
6464
checkResult = contributors.includes(username);
6565
}
6666
}
6767

68+
checkFailed = false;
6869
if (checkBot || checkContributor) {
6970
core.info(`[Action Check] The check result is ${checkResult}.`);
7071
core.setOutput('check-result', checkResult);
72+
checkFailed = checkFailed || !checkResult;
7173
}
7274

7375
if (require) {
7476
requireResult = checkPermission(require, permission);
7577
core.info(`[Action Require] The ${username} permission check is ${requireResult}.`);
7678
core.setOutput('require-result', requireResult);
79+
checkFailed = checkFailed || !requireResult;
80+
}
81+
82+
const errorIfMissing = core.getInput('error-if-missing');
83+
if (checkFailed && (errorIfMissing === 'true')) {
84+
core.setFailed('The required check failed.');
7785
}
7886

7987
core.info(THANKS);
88+
8089
} catch (error) {
8190
core.setFailed(error.message);
8291
}

0 commit comments

Comments
 (0)