Label Child Issues #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
# Convert newline-separated labels into a comma-separated string | |
formatted_labels=$(echo "$labels" | tr '\n' ',' | sed 's/,$//') | |
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 }} |