1- #! /bin/zsh
1+ #! /bin/bash
22
33# Validates that all PRs in a list have the same title
44#
@@ -16,18 +16,18 @@ if [ ! -f "$pr_list_file" ]; then
1616 exit 1
1717fi
1818
19- typeset -A titles
20- typeset -A title_urls
21- first_title= " "
19+ # Temporary file to store title|url pairs
20+ temp_file= $( mktemp )
21+ trap " rm -f $temp_file " EXIT
2222
2323while IFS= read -r pr_url || [ -n " $pr_url " ]; do
2424 [ -z " $pr_url " ] || [[ " $pr_url " == \# * ]] && continue
2525 pr_url=$( echo " $pr_url " | xargs)
2626
2727 if [[ " $pr_url " =~ ^https://github\. com/([^/]+)/([^/]+)/pull/([0-9]+) ]]; then
28- owner=" ${match [1]} "
29- repo=" ${match [2]} "
30- pr_number=" ${match [3]} "
28+ owner=" ${BASH_REMATCH [1]} "
29+ repo=" ${BASH_REMATCH [2]} "
30+ pr_number=" ${BASH_REMATCH [3]} "
3131 else
3232 echo " ⚠️ Invalid URL: $pr_url "
3333 continue
@@ -40,45 +40,32 @@ while IFS= read -r pr_url || [ -n "$pr_url" ]; do
4040 fi
4141
4242 echo " 📋 $owner /$repo #$pr_number : $title "
43-
44- if [ -z " $first_title " ]; then
45- first_title=" $title "
46- fi
47-
48- titles[$title ]=$(( ${titles[$title]:- 0} + 1 ))
49- # Append URL to the list for this title
50- if [ -z " ${title_urls[$title]} " ]; then
51- title_urls[$title ]=" $pr_url "
52- else
53- title_urls[$title ]=" ${title_urls[$title]} |$pr_url "
54- fi
43+ echo " $title |$pr_url " >> " $temp_file "
5544done < " $pr_list_file "
5645
5746echo " "
5847echo " ========================================"
5948echo " Title Summary:"
6049
61- # Find the majority count
62- max_count=0
63- for title in " ${(@ k)titles} " ; do
64- if [ ${titles[$title]} -gt $max_count ]; then
65- max_count=${titles[$title]}
66- fi
67- done
50+ # Get unique titles with counts, sorted by count descending
51+ title_counts=$( cut -d' |' -f1 " $temp_file " | sort | uniq -c | sort -rn)
52+ unique_count=$( echo " $title_counts " | wc -l | xargs)
53+ max_count=$( echo " $title_counts " | head -1 | awk ' {print $1}' )
6854
69- for title in " ${( @ k)titles} " ; do
70- echo " (${titles[$title] } x) $title "
55+ echo " $title_counts " | while read -r count title ; do
56+ echo " (${count } x) $title "
7157 # Show URLs for non-majority titles
72- if [ ${titles[$title]} -lt $max_count ]; then
73- echo " ${title_urls[$ title]} " | tr ' |' ' \n ' | while read -r url; do
58+ if [ " $count " -lt " $max_count " ]; then
59+ grep " ^ ${ title} | " " $temp_file " | cut -d ' |' -f2 | while read -r url; do
7460 echo " └─ $url "
7561 done
7662 fi
7763done
64+
7865echo " ========================================"
7966
80- if [ ${ # titles[@]} -eq 1 ]; then
67+ if [ " $unique_count " -eq 1 ]; then
8168 echo " ✅ All PRs have the same title"
8269else
83- echo " ⚠️ PRs have ${ # titles[@]} different titles"
70+ echo " ⚠️ PRs have $unique_count different titles"
8471fi
0 commit comments