Skip to content

Commit

Permalink
🎉 Add initial workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
georgepstaylor committed May 4, 2024
1 parent a912a2c commit 1dc94f1
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .github/workflows/auto-create-gitmoji-labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Create gitmoji label
on:
pull_request:
types: [opened, edited, reopened, synchronize]
jobs:
create-gitmoji-label:
runs-on: ubuntu-latest
steps:
- name: Enforce gitmoji PR title
uses: georgepstaylor/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
# gitmoji-auto-label


A simple action to automatically label PRs based on the gitmoji used in the title.

## Usage
```yaml
name: Create gitmoji label
on:
pull_request:
types: [opened, edited, reopened, synchronize]
jobs:
create-gitmoji-label:
runs-on: ubuntu-latest
steps:
- name: Enforce gitmoji PR title
uses: georgepstaylor/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
Using the above example verbatim, you can use the job title `gitmoji-pr-title` as a required check.
43 changes: 43 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
name: Auto create gitmoji labels
description: This action automatically creates gitmoji labels JIT

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: Get gitmoji from PR title
id: get-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
else
echo "gitmoji=$gitmoji" >> $GITHUB_OUTPUT
fi
- name: Create label if not exists
id: create-label
shell: bash
run: |
gitmoji=$(cat $GITHUB_OUTPUT | grep gitmoji | cut -d '=' -f2)
random_hex_color=$(openssl rand -hex 3)
label_exists=$(curl -s -H "Authorization : token ${{ inputs.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/labels | jq '.[].name' | grep ${gitmoji}_gitmoji)
if [[ -z $label_exists ]]; then
curl -s -H "Authorization: token ${{ inputs.GITHUB_TOKEN }}" -X POST https://api.github.com/repos/${{ github.repository }}/labels -d "{\"name\":\"${gitmoji}_gitmoji\",\"color\":\"$random_hex_color\"}"
fi
branding:
icon: 'check-circle'
color: 'green'

0 comments on commit 1dc94f1

Please sign in to comment.