1111# #
1212# # This Script also is expecting the jq library to be installed. https://stedolan.github.io/jq/
1313
14- set -eu
14+ set -euo pipefail
15+
16+ if [[ $# -ne 2 ]]; then
17+ echo " Usage: $0 <base> <head>" >&2
18+ exit 1
19+ fi
20+
21+ for dependency in curl jq mktemp; do
22+ if ! command -v " $dependency " > /dev/null 2>&1 ; then
23+ echo " Error: Missing required dependency: $dependency " >&2
24+ exit 1
25+ fi
26+ done
27+
1528BASE=$1
1629HEAD=$2
17- here=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
18- curl -s -u " $GHUSER :$GHTOKEN " https://api.github.com/repos/expressionengine/expressionengine/compare/$1 ...$2 | jq .commits > core_contributors.json
19- length=" $( cat core_contributors.json | jq ' . | length' ) "
30+ URL=" https://api.github.com/repos/expressionengine/expressionengine/compare/${BASE} ...${HEAD} "
31+
32+ RESPONSE_JSON=" $( mktemp) "
33+ COMMITS_JSON=" $( mktemp) "
34+ CORE_CONTRIBUTORS_HTML=" $( mktemp) "
35+ cleanup () {
36+ rm -f " $RESPONSE_JSON " " $COMMITS_JSON " " $CORE_CONTRIBUTORS_HTML "
37+ }
38+ trap cleanup EXIT
39+
40+ USE_BASIC_AUTH=false
41+ USE_BEARER_AUTH=false
42+ if [[ -n " ${GHUSER:- } " && -n " ${GHTOKEN:- } " ]]; then
43+ USE_BASIC_AUTH=true
44+ elif [[ -n " ${GHTOKEN:- } " ]]; then
45+ USE_BEARER_AUTH=true
46+ else
47+ echo " Warning: GHUSER/GHTOKEN not set; using unauthenticated GitHub API requests (rate limited)." >&2
48+ fi
49+
50+ if [[ " $USE_BASIC_AUTH " == true ]]; then
51+ curl --fail --silent --show-error -u " ${GHUSER} :${GHTOKEN} " " $URL " > " $RESPONSE_JSON "
52+ elif [[ " $USE_BEARER_AUTH " == true ]]; then
53+ curl --fail --silent --show-error -H " Authorization: Bearer ${GHTOKEN} " " $URL " > " $RESPONSE_JSON "
54+ else
55+ curl --fail --silent --show-error " $URL " > " $RESPONSE_JSON "
56+ fi
57+
58+ if ! jq -e ' .commits and (.commits | type == "array")' " $RESPONSE_JSON " > /dev/null; then
59+ API_MESSAGE=" $( jq -r ' .message // "Unexpected API response: .commits not found"' " $RESPONSE_JSON " ) "
60+ echo " Error: $API_MESSAGE " >&2
61+ exit 1
62+ fi
63+
64+ jq ' .commits' " $RESPONSE_JSON " > " $COMMITS_JSON "
2065
2166# Now lets sort of JSON object alphabetically
22- tmp=$( mktemp)
23- jq " . |=sort_by(.commit | .author | .name)" core_contributors.json > " $tmp " && mv " $tmp " core_contributors.json
67+ tmp=" $( mktemp) "
68+ jq " . |=sort_by(.commit | .author | .name // \"\" )" " $COMMITS_JSON " > " $tmp " && mv " $tmp " " $COMMITS_JSON "
2469
70+ length=" $( jq -r ' length' " $COMMITS_JSON " ) "
71+ if ! [[ " $length " =~ ^[0-9]+$ ]]; then
72+ echo " Error: Unable to determine commit length from GitHub response." >&2
73+ exit 1
74+ fi
2575
2676x=0
2777CONTRIBUTORS=" "
2878echo " Starting Loop"
2979declare -a contributorList=()
30- while [ $x -lt $length ]
31- do
32- AUTHOR=$( cat core_contributors.json | jq " .[$x ] | .author | .login" | tr -d ' "' )
80+ while (( x < length )) ; do
81+ AUTHOR=" $( jq -r " .[$x ] | .author | .login // \"\" " " $COMMITS_JSON " ) "
82+ if [[ -z " $AUTHOR " ]]; then
83+ (( x= x+ 1 ))
84+ continue
85+ fi
86+
3387 if [[ ! " ${contributorList[*]-} " =~ " ${AUTHOR} " ]]; then
34- contributorList[${# contributorList[@]} ]=$AUTHOR
35- IMAGE=$( cat core_contributors.json | jq " .[$x ] | .author | .avatar_url" | tr -d ' "' )
36- NAME=$( cat core_contributors.json | jq " .[$x ] | .commit | .author | .name" | tr -d ' "' )
88+ contributorList[${# contributorList[@]} ]=" $AUTHOR "
89+ IMAGE=" $( jq -r " .[$x ] | .author | .avatar_url // \"\" " " $COMMITS_JSON " ) "
90+ NAME=" $( jq -r " .[$x ] | .commit | .author | .name // \"\" " " $COMMITS_JSON " ) "
91+ if [[ -z " $NAME " ]]; then
92+ NAME=" $AUTHOR "
93+ fi
3794
38- echo $NAME ' - ' $AUTHOR | tr -d ' " '
39- CONTRIBUTORS+=$' \n <li><div class="space-y-4 text-center"><img class="mx-auto h-20 w-20 rounded-full lg:w-24 lg:h-24" src="' $IMAGE ' " /><div class="space-y-2"><div class="text-xs font-medium lg:text-sm"><p class="mb-1">' $NAME ' </p><p class="text-indigo-600"><a href="https://github.com/ExpressionEngine/ExpressionEngine/commits?author=' $AUTHOR ' " target="_BLANK">@' $AUTHOR ' </a></p></div></div></div></li>'
95+ echo " $NAME - $AUTHOR "
96+ CONTRIBUTORS+=$' \n <li><div class="space-y-4 text-center"><img class="mx-auto h-20 w-20 rounded-full lg:w-24 lg:h-24" src="' " $IMAGE " ' " /><div class="space-y-2"><div class="text-xs font-medium lg:text-sm"><p class="mb-1">' " $NAME " ' </p><p class="text-indigo-600"><a href="https://github.com/ExpressionEngine/ExpressionEngine/commits?author=' " $AUTHOR " ' " target="_BLANK">@' " $AUTHOR " ' </a></p></div></div></div></li>'
4097 fi
98+
4199 (( x= x+ 1 ))
42100done
43101
44102echo " === Copy html below and insert into changelog ==="
45- cat > " core_contributors.html " << - EOF
103+ cat > " $CORE_CONTRIBUTORS_HTML " << - EOF
46104<div class="max-w-7xl mx-autotext-center">
47105<div class="space-y-8 sm:space-y-12">
48106 <ul role="list" class="mx-auto grid grid-cols-2 gap-x-4 gap-y-1 sm:grid-cols-4 md:gap-x-6 lg:max-w-5xl lg:gap-x-8 lg:gap-y-1 xl:grid-cols-5">
@@ -52,6 +110,4 @@ cat > "core_contributors.html" <<- EOF
52110</div>
53111
54112EOF
55- cat core_contributors.html
56- rm core_contributors.json
57- rm core_contributors.html
113+ cat " $CORE_CONTRIBUTORS_HTML "
0 commit comments