Skip to content

Label Child Issues

Label Child Issues #23

name: Label Child Issues
on:
issues:
types: [opened, edited]
jobs:
label_child_issues:
runs-on: ubuntu-latest
steps:
- name: Fetch Linked Issue
id: get_linked_issue
run: |
linked_issue=$(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' | head -n 1)
echo "PARENT_ISSUE=$linked_issue" >> $GITHUB_ENV
- name: Get Parent Issue Labels
if: env.PARENT_ISSUE
run: |
parent_labels=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ env.PARENT_ISSUE }} \
| jq -r '.labels[].name' | paste -sd,)
echo "PARENT_LABELS=$parent_labels" >> $GITHUB_ENV
- name: Apply Labels
if: env.PARENT_ISSUE
run: |
all_labels="epic-task,${{ env.PARENT_LABELS }}"
label_json=$(echo "$all_labels" | jq -R 'split(",") | map(select(length > 0))')
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Content-Type: application/json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/labels \
-d "{\"labels\":$label_json}"
echo "Applied labels: $all_labels"