From c54dd3a09a03a23fd03fe22e7649f886f35b9813 Mon Sep 17 00:00:00 2001 From: Tamerlan Satualdypov Date: Mon, 1 Jan 2024 02:07:09 +0600 Subject: [PATCH] Added workflow for autolabeling issues and PRs #11 (#12) --- .github/actions/label-generator/action.sh | 7 ++++ .github/actions/label-generator/action.yml | 16 +++++++++ .github/workflows/autolabeler.yml | 41 ++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 .github/actions/label-generator/action.sh create mode 100644 .github/actions/label-generator/action.yml create mode 100644 .github/workflows/autolabeler.yml diff --git a/.github/actions/label-generator/action.sh b/.github/actions/label-generator/action.sh new file mode 100644 index 0000000..47ab6c9 --- /dev/null +++ b/.github/actions/label-generator/action.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if [[ "$1" == *"feature"* ]]; then + echo "feature" +elif [[ "$1" == *"bug"* ]]; then + echo "bug" +fi diff --git a/.github/actions/label-generator/action.yml b/.github/actions/label-generator/action.yml new file mode 100644 index 0000000..0e5ad25 --- /dev/null +++ b/.github/actions/label-generator/action.yml @@ -0,0 +1,16 @@ +name: 'Label generator' +description: 'Generates label based on the given value' +inputs: + value: + description: 'Value to label' + required: true +outputs: + label: + description: 'Label name' + value: ${{ steps.main.outputs.label }} +runs: + using: "composite" + steps: + - id: main + run: echo "label=$(bash ${{ github.action_path }}/action.sh ${{ inputs.value }})" >> $GITHUB_OUTPUT + shell: bash \ No newline at end of file diff --git a/.github/workflows/autolabeler.yml b/.github/workflows/autolabeler.yml new file mode 100644 index 0000000..7e50d99 --- /dev/null +++ b/.github/workflows/autolabeler.yml @@ -0,0 +1,41 @@ +name: 'Autolabeling' + +on: + issues: + types: + - opened + - edited + pull_request_target: + types: + - opened + - edited + +jobs: + label: + runs-on: ubuntu-latest + permissions: + contents: read + issues: write + pull-requests: write + steps: + - uses: actions/checkout@v4 + - id: label-generator + uses: ./.github/actions/label-generator + with: + value: ${{ github.event.issue && github.event.issue.title || github.event.pull_request.head.ref }} + - name: Apply label on Issue + if: github.event.issue + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + URL: ${{ github.event.issue.html_url }} + LABEL: ${{ steps.label-generator.outputs.label }} + run: | + gh issue edit "$URL" --add-label "$LABEL" + - name: Apply label on PR + if: github.event.pull_request + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + URL: ${{ github.event.pull_request.html_url }} + LABEL: ${{ steps.label-generator.outputs.label }} + run: | + gh pr edit "$URL" --add-label "$LABEL" \ No newline at end of file