-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
51 lines (45 loc) · 1.8 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
---
name: Enforce Pull Request has a valid gitmoji prefix
description: This action enforces that a pull request title contains a valid gitmoji prefix
inputs:
GITHUB_TOKEN:
description: 'GitHub token'
required: true
runs:
using: "composite"
steps:
- name: Get all Gitmoji's
id: gitmojis
shell: bash
run: |
curl -s https://gitmoji.dev/api/gitmojis | jq '.gitmojis[].emoji' > gitmojis.txt
- name: Check if PR title has a valid gitmoji prefix
id: check-gitmoji
shell: bash
run: |
gitmojis=$(cat gitmojis.txt)
gitmoji=$(echo "${{ github.event.pull_request.title }}" | cut -d ' ' -f1)
if [[ ! $gitmojis == *"$gitmoji"* ]]; then
echo "Invalid gitmoji prefix in PR title. Please use a valid gitmoji prefix."
exit 1
fi
- name: Failure Comment
shell: bash
if: failure()
run: |
COMMENT=":x: Invalid gitmoji prefix in PR title. Please use a valid gitmoji prefix."
GITHUB_TOKEN=${{ inputs.GITHUB_TOKEN }}
COMMENT_URL="https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
curl -s -H "Authorization: token ${GITHUB_TOKEN}" -X POST $COMMENT_URL -d "{\"body\":\"$COMMENT\"}"
- name: Success Comment
shell: bash
if: success()
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
COMMENT=":white_check_mark: Valid gitmoji prefix in PR title."
GITHUB_TOKEN=${{ inputs.GITHUB_TOKEN }}
COMMENT_URL="https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments"
curl -s -H "Authorization: token ${GITHUB_TOKEN}" -X POST $COMMENT_URL -d "{\"body\":\"$COMMENT\"}"
branding:
icon: 'check-circle'
color: 'green'