From 1dc94f194daf89fcfc9c3f309e96c9bbfb31ee57 Mon Sep 17 00:00:00 2001 From: George Taylor Date: Sat, 4 May 2024 22:24:32 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=8E=89=20Add=20initial=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workflows/auto-create-gitmoji-labels.yml | 12 ++++++ .gitignore | 1 + README.md | 21 ++++++++- action.yml | 43 +++++++++++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/auto-create-gitmoji-labels.yml create mode 100644 .gitignore create mode 100644 action.yml diff --git a/.github/workflows/auto-create-gitmoji-labels.yml b/.github/workflows/auto-create-gitmoji-labels.yml new file mode 100644 index 0000000..1f3f842 --- /dev/null +++ b/.github/workflows/auto-create-gitmoji-labels.yml @@ -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/gitmoji-auto-label@v0.0.1 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62c8935 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ \ No newline at end of file diff --git a/README.md b/README.md index 5e1a858..d228207 100644 --- a/README.md +++ b/README.md @@ -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/gitmoji-auto-label@v0.0.1 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +``` + +Using the above example verbatim, you can use the job title `gitmoji-pr-title` as a required check. \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..10e5d69 --- /dev/null +++ b/action.yml @@ -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' \ No newline at end of file From 0dadcd784334c647712821a65ac5b4f3b60cce2a Mon Sep 17 00:00:00 2001 From: George Taylor Date: Sat, 4 May 2024 22:25:22 +0100 Subject: [PATCH 2/2] Update auto-create-gitmoji-labels.yml --- .github/workflows/auto-create-gitmoji-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-create-gitmoji-labels.yml b/.github/workflows/auto-create-gitmoji-labels.yml index 1f3f842..e02dc19 100644 --- a/.github/workflows/auto-create-gitmoji-labels.yml +++ b/.github/workflows/auto-create-gitmoji-labels.yml @@ -7,6 +7,6 @@ jobs: runs-on: ubuntu-latest steps: - name: Enforce gitmoji PR title - uses: georgepstaylor/gitmoji-auto-label@v0.0.1 + uses: georgepstaylor/gitmoji-auto-label@${{github.sha}} with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file