Skip to content

Commit

Permalink
Merge pull request #182 from github/commit-author-fixes
Browse files Browse the repository at this point in the history
fallback to `commit.commit.author.name`
  • Loading branch information
GrantBirki authored Dec 3, 2024
2 parents 1f63276 + d385b55 commit daf8e2a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Here are the configuration options for this Action:
| `checkDiff` | yes | `"true"` | An option to check that the PR diff only has a removal diff, with no additions - This option defaults to `"true"` but it can be disabled by setting it to `"false"` |
| `checkLabels` | yes | `"true"` | An option to check that the labels on the PR match those defined in the privileged requester config |
| `commitVerification` | yes | `"false"` | Whether or not to validate all commits have proper verification via GPG signed commits |
| `fallback_to_commit_author` | no | `"false"` | Whether or not to fallback to the commit author value if the commit login value is missing |

### Outputs 📤

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ inputs:
description: 'Whether or not to validate all commits have proper verification via GPG signed commits'
required: true
default: 'false'
fallback_to_commit_author:
description: 'Whether or not to fallback to the commit author value if the commit login value is missing'
required: true
default: 'false'
outputs:
approved: # output will be available to future steps
description: "Whether or not the PR was approved - 'true' or 'false'"
Expand Down
16 changes: 15 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion src/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@ class Runner {
core.debug(`checking commits: ${commits.length}`);

for (const [, commit] of commits) {
const commitAuthor = commit.author.login.toLowerCase();
var commitAuthor = null;
try {
commitAuthor = commit.author.login.toLowerCase();
} catch (e) {
if (core.getBooleanInput("fallback_to_commit_author") === true) {
core.debug(`commit.author.login not found: ${e}`);
core.debug(
`trying commit.commit.author.name: ${commit.commit.author.name}`,
);
commitAuthor = commit.commit.author.name.toLowerCase();
} else {
throw new Error(`commit.author.login not found: ${e}`);
}
}

const commitVerification = commit?.commit?.verification?.verified;
const sha = commit?.sha;

Expand Down

0 comments on commit daf8e2a

Please sign in to comment.