Skip to content

Commit 1b1f545

Browse files
Poeschlmotlin
authored andcommitted
Add configurable fail notice
1 parent 8aa52a0 commit 1b1f545

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ jobs:
6363
with:
6464
# Defaults to 'true', set to 'false' for warning-only mode
6565
fail-on-merge-commits: 'true'
66+
# Defaults to 'Refer to [handling failure messages](...) for guidance.'
67+
fail-notice: 'Your custom failure message here'
6668
```
6769
6870
## Recommended settings

action.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ inputs:
2323
description: 'Whether to fail the check when merge commits are found, or just warn'
2424
required: false
2525
default: 'true'
26+
fail-notice:
27+
description: 'Message to display when merge commits are found'
28+
required: false
29+
default: 'Refer to [handling failure messages](https://github.com/motlin/forbid-merge-commits-action#handling-failure-messages) for guidance.'
2630

2731
runs:
2832
using: "composite"
@@ -45,15 +49,22 @@ runs:
4549
shell: bash
4650
env:
4751
FAIL_ON_MERGE_COMMITS: ${{ inputs.fail-on-merge-commits }}
52+
FAIL_NOTICE: ${{ inputs.fail-notice }}
4853
run: |
4954
set -Eeuo pipefail
5055
56+
# Transform [text](url) -> url
57+
unwrap_markdown_urls() {
58+
echo "$1" | sed -E 's/\[([^\]]+)\]\(([^)]+)\)/\2/g'
59+
}
60+
5161
MERGE_COMMITS=$(git log --merges --format=%H origin/${{github.base_ref}}..refs/remotes/pull/${{github.event.pull_request.number}}/merge^2 --)
5262
if [ -n "$MERGE_COMMITS" ]; then
5363
ANNOTATION_LEVEL=$([ "$FAIL_ON_MERGE_COMMITS" = "true" ] && echo "error" || echo "warning")
54-
echo "::$ANNOTATION_LEVEL title=Found merge commits::Found merge commits. Refer to https://github.com/motlin/forbid-merge-commits-action#handling-failure-messages for guidance."
64+
CONSOLE_FAIL_NOTICE=$(unwrap_markdown_urls "$FAIL_NOTICE")
65+
echo "::$ANNOTATION_LEVEL title=Found merge commits::Found merge commits. ${CONSOLE_FAIL_NOTICE}"
5566
56-
echo -e '## Found merge commits.\n\nRefer to [handling failure messages](https://github.com/motlin/forbid-merge-commits-action#handling-failure-messages) for guidance.\n' >> $GITHUB_STEP_SUMMARY
67+
echo -e '## Found merge commits.\n\n${FAIL_NOTICE}\n' >> $GITHUB_STEP_SUMMARY
5768
5869
for COMMIT_HASH in $MERGE_COMMITS; do
5970
echo "::warning::Merge commit: $COMMIT_HASH"

0 commit comments

Comments
 (0)