Skip to content

Label Child Issues

Label Child Issues #9

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')
# Assuming there's only one linked parent issue
echo "$(echo $linked_issues | head -n 1)" > parent_issue.txt
- name: Get Labels from Parent Issue
id: get_labels
run: |
parent_issue=$(cat parent_issue.txt)
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' > labels.txt
# Add the epic-task label
echo "epic-task" >> labels.txt
# Read the labels into a variable
labels=$(paste -sd "," labels.txt)
echo "LABELS=$labels" >> $GITHUB_ENV
- name: Apply Labels to Child Issue
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: ${{ env.LABELS }}