From 7603772075929232a6b7cf2102f10f29875a7315 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Sat, 11 May 2024 11:46:00 +0100 Subject: [PATCH] Label the issues with slug --- scripts/label-issues.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 scripts/label-issues.sh diff --git a/scripts/label-issues.sh b/scripts/label-issues.sh new file mode 100755 index 000000000..3e4faa704 --- /dev/null +++ b/scripts/label-issues.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Fetch issues JSON data and parse it properly +issues=$(gh issue list --repo kamranahmedse/developer-roadmap --search "sort:created-asc" --state open --limit 500 --json number,title,createdAt,updatedAt,state,url,comments,reactionGroups,body | jq -c '.[]') + +# checks the body of issue, identifies the slug from the roadmap URLs +# and labels the issue with the corresponding slug +while IFS= read -r issue; do + created_at=$(echo "$issue" | jq -r '.createdAt') + updated_at=$(echo "$issue" | jq -r '.updatedAt') + issue_number=$(echo "$issue" | jq -r '.number') + issue_title=$(echo "$issue" | jq -r '.title') + reaction_groups=$(echo "$issue" | jq -r '.reactionGroups') + has_reactions=$(echo "$issue" | jq -r '.reactionGroups | length') + comment_count=$(echo "$issue" | jq -r '.comments | length') + body_characters=$(echo "$issue" | jq -r '.body | length') + + # If the issue has no body, then skip it + if [ "$body_characters" -eq 0 ]; then + continue + fi + + # Extract the roadmap URLs from the issue body + roadmap_urls=$(echo "$issue" | jq -r '.body' | grep -o 'https://roadmap\.sh/[^ ]*') + + # If no roadmap URLs found, then skip it + if [ -z "$roadmap_urls" ]; then + continue + fi + + # URL is like https://roadmap.sh/frontend + # Extract the slug from the URL + slug_of_first_url=$(echo "$roadmap_urls" | head -n 1 | sed 's/https:\/\/roadmap\.sh\///') + + if [ -z "$slug_of_first_url" ]; then + continue + fi + + # Label the issue with the slug + gh issue edit "$issue_number" --add-label "$slug_of_first_url" +done <<< "$issues"