From 120a60d3c2cd6dcb3d166b4a79956a6f682bfa7f Mon Sep 17 00:00:00 2001 From: Jakob Kraus <52459467+JabobKrauskopf@users.noreply.github.com> Date: Wed, 14 Aug 2024 12:13:50 +0200 Subject: [PATCH] chore: Add github action to automatically label epic tasks (#168) --- .github/workflows/label-epic-task.yml | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/label-epic-task.yml diff --git a/.github/workflows/label-epic-task.yml b/.github/workflows/label-epic-task.yml new file mode 100644 index 00000000..7b66b31b --- /dev/null +++ b/.github/workflows/label-epic-task.yml @@ -0,0 +1,45 @@ +name: Label Child Issues + +on: + issues: + types: [opened, edited] + +jobs: + label_child_issues: + runs-on: ubuntu-latest + steps: + - name: Fetch Linked Issues + id: get_linked_issues + run: | + linked_issues=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/timeline \ + | jq -r '.[] | select(.event == "cross-referenced") | .source.issue.number') + + echo "Linked Issues: $linked_issues" + + # Assuming there's only one linked parent issue + echo "PARENT_ISSUE=$(echo $linked_issues | head -n 1)" >> $GITHUB_ENV + + - name: Get Labels from Parent Issue + id: get_labels + if: env.PARENT_ISSUE + run: | + labels=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository }}/issues/${PARENT_ISSUE} \ + | jq -r '.labels[] | select(.name != "epic") | .name') + + # Add the epic-task label to the list + labels="$labels\nepic-task" + + # Escape newlines for GitHub environment variable handling + formatted_labels="${labels//$'\n'/'%0A'}" + echo "LABELS=$formatted_labels" >> $GITHUB_ENV + + - name: Apply Labels to Child Issue + if: env.PARENT_ISSUE + uses: actions-ecosystem/action-add-labels@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + labels: ${{ env.LABELS }}