Skip to content

Label Child Issues

Label Child Issues #17

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"
# Remove any empty labels and format as a JSON array of strings
formatted_labels=$(echo "$labels" | awk 'NF' | jq -R -s -c 'split("\n")')
echo "LABELS=$formatted_labels" >> $GITHUB_ENV
- name: Debug - Print LABELS Environment Variable
if: env.PARENT_ISSUE
run: |
echo "Formatted Labels: $LABELS"
- name: Apply Labels to Child Issue
if: env.PARENT_ISSUE
run: |
curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"labels\": ${LABELS}}" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/labels"