1- #! /usr/bin/env /bin/ bash
1+ #! /usr/bin/env bash
22set -euo pipefail
33
44# ##
@@ -11,6 +11,20 @@ API_URL_PREFIX=${API_URL_PREFIX:-'https://api.github.com'}
1111MONTH_START=${MONTH_START:- ' ' }
1212MONTH_END=${MONTH_END:- ' ' }
1313
14+ # Check if GITHUB_TOKEN is set
15+ if [ -z " ${GITHUB_TOKEN} " ]; then
16+ echo " GITHUB_TOKEN is empty. Please set your token and try again"
17+ exit 1
18+ fi
19+
20+ # Validate GITHUB_TOKEN by calling GitHub API
21+ RESPONSE=$( curl -s -o /dev/null -w " %{http_code}" -H " Authorization: token ${GITHUB_TOKEN} " " ${API_URL_PREFIX} /user" )
22+
23+ if [ " ${RESPONSE} " -ne 200 ]; then
24+ echo " Error: GITHUB_TOKEN is invalid or does not have required permissions."
25+ exit 1
26+ fi
27+
1428get_public_pagination () {
1529 public_pages=$( curl -H " Authorization: token ${GITHUB_TOKEN} " -I " ${API_URL_PREFIX} /repos/${ORG} /${REPO} /issues?state=all&labels=Linked%20[AC]&per_page=100" | grep -Eo ' &page=[0-9]+' | grep -Eo ' [0-9]+' | tail -1; )
1630 echo " ${public_pages:- 1} "
@@ -22,15 +36,15 @@ limit_public_pagination () {
2236
2337repo_issues () {
2438 for PAGE in $( limit_public_pagination) ; do
25- for i in $( curl -H " Authorization: token ${GITHUB_TOKEN} " -s " ${API_URL_PREFIX} /repos/${ORG} /${REPO} /issues?state=all&labels=Linked%20[AC]&page=${PAGE} &per_page=100" | jq -r ' map(select(.created_at | . >= "' $ MONTH_START' T00:00" and . <= "' $ MONTH_END' T23:59")) | sort_by(.number) | .[] | .number' ) ; do
39+ for i in $( curl -H " Authorization: token ${GITHUB_TOKEN} " -s " ${API_URL_PREFIX} /repos/${ORG} /${REPO} /issues?state=all&labels=Linked%20[AC]&page=${PAGE} &per_page=100" | jq -r ' map(select(.created_at | . >= "' " ${ MONTH_START} " ' T00:00" and . <= "' " ${ MONTH_END} " ' T23:59")) | sort_by(.number) | .[] | .number' ) ; do
2640 ISSUE_PAYLOAD=$( curl -H " Authorization: token ${GITHUB_TOKEN} " -s " ${API_URL_PREFIX} /repos/${ORG} /${REPO} /issues/${i} " -H " Accept: application/vnd.github.mercy-preview+json" )
2741 ISSUE_TIMELINE_PAYLOAD=$( curl -H " Authorization: token ${GITHUB_TOKEN} " -s " ${API_URL_PREFIX} /repos/${ORG} /${REPO} /issues/${i} /timeline" -H " Accept: application/vnd.github.mockingbird-preview+json" | jq -r ' .[] | select(.label.name=="Linked [AC]" or .label.name=="linked")' )
2842
29- ISSUE_AUTHOR=$( echo " $ISSUE_PAYLOAD " | jq -r .user.login)
30- ISSUE_TITLE=$( echo " $ISSUE_PAYLOAD " | jq -r .title | tr ' "' " '" )
31- ISSUE_HTML_URL=$( echo " $ISSUE_PAYLOAD " | jq -r .html_url)
43+ ISSUE_AUTHOR=$( echo " ${ ISSUE_PAYLOAD} " | jq -r .user.login)
44+ ISSUE_TITLE=$( echo " ${ ISSUE_PAYLOAD} " | jq -r .title | tr ' "' " '" )
45+ ISSUE_HTML_URL=$( echo " ${ ISSUE_PAYLOAD} " | jq -r .html_url)
3246
33- ISSUE_TIMELINE_LABELED_BY=$( echo " $ISSUE_TIMELINE_PAYLOAD " | jq -s ' first(.[]| .actor.login)' | jq -r)
47+ ISSUE_TIMELINE_LABELED_BY=$( echo " ${ ISSUE_TIMELINE_PAYLOAD} " | jq -s ' first(.[]| .actor.login)' | jq -r)
3448
3549 cat >> test.json << EOF
3650{
4660}
4761
4862author_json () {
49- AUTHORS=$( cat test.json| jq -r ' .author' | sort | uniq -c | awk -F " " ' {print "{\"author\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .author)
63+ AUTHORS=$( cat test.json | jq -r ' .author' | sort | uniq -c | awk -F " " ' {print "{\"author\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .author)
5064 for AUTHOR in ${AUTHORS} ; do
51- TEST_PAYLOAD=$( cat test.json| jq -r ' .author' | sort | uniq -c | awk -F " " ' {print "{\"author\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .)
52- TEST_PAYLOAD_AUTHOR=$( echo " $TEST_PAYLOAD " | jq -r --arg AUTHOR " ${AUTHOR} " ' select(.author==$AUTHOR) | .author' )
53- TEST_PAYLOAD_AUTHOR_COUNT=$( echo " $TEST_PAYLOAD " | jq -r --arg AUTHOR " ${AUTHOR} " ' select(.author==$AUTHOR) | .count' )
65+ TEST_PAYLOAD=$( cat test.json | jq -r ' .author' | sort | uniq -c | awk -F " " ' {print "{\"author\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .)
66+ TEST_PAYLOAD_AUTHOR=$( echo " ${ TEST_PAYLOAD} " | jq -r --arg AUTHOR " ${AUTHOR} " ' select(.author==$AUTHOR) | .author' )
67+ TEST_PAYLOAD_AUTHOR_COUNT=$( echo " ${ TEST_PAYLOAD} " | jq -r --arg AUTHOR " ${AUTHOR} " ' select(.author==$AUTHOR) | .count' )
5468 # TEST_PAYLOAD_AUTHOR_ISSUE_TITLE=$(cat test.json | jq -r --arg AUTHOR "${AUTHOR}" 'select(.author==$AUTHOR) | .title')
5569 TEST_PAYLOAD_AUTHOR_ISSUE_URL=$( cat test.json | jq -r --arg AUTHOR " ${AUTHOR} " ' select(.author==$AUTHOR) | .title, .issue_url' )
56- echo -e " <a href=" https://github.com/${TEST_PAYLOAD_AUTHOR} " >${TEST_PAYLOAD_AUTHOR} </a> - ${TEST_PAYLOAD_AUTHOR_COUNT} "
70+ echo -e " <a href=\ " https://github.com/${TEST_PAYLOAD_AUTHOR} \ " >${TEST_PAYLOAD_AUTHOR} </a> - ${TEST_PAYLOAD_AUTHOR_COUNT} "
5771 done | sort -n -k 4,4 -r >> output.txt
5872}
5973
6074contributor_json () {
61- CONTRIBUTORS=$( cat test.json| jq -r ' .contributor' | sort | uniq -c | awk -F " " ' {print "{\"contributor\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .contributor)
75+ CONTRIBUTORS=$( cat test.json | jq -r ' .contributor' | sort | uniq -c | awk -F " " ' {print "{\"contributor\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .contributor)
6276 for CONTRIBUTOR in ${CONTRIBUTORS} ; do
63- TEST_PAYLOAD=$( cat test.json| jq -r ' .contributor' | sort | uniq -c | awk -F " " ' {print "{\"contributor\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .)
64- TEST_PAYLOAD_CONTRIBUTOR=$( echo " $TEST_PAYLOAD " | jq -r --arg CONTRIBUTOR " ${CONTRIBUTOR} " ' select(.contributor==$CONTRIBUTOR) | .contributor' )
65- TEST_PAYLOAD_CONTRIBUTOR_COUNT=$( echo " $TEST_PAYLOAD " | jq -r --arg CONTRIBUTOR " ${CONTRIBUTOR} " ' select(.contributor==$CONTRIBUTOR) | .count' )
77+ TEST_PAYLOAD=$( cat test.json | jq -r ' .contributor' | sort | uniq -c | awk -F " " ' {print "{\"contributor\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .)
78+ TEST_PAYLOAD_CONTRIBUTOR=$( echo " ${ TEST_PAYLOAD} " | jq -r --arg CONTRIBUTOR " ${CONTRIBUTOR} " ' select(.contributor==$CONTRIBUTOR) | .contributor' )
79+ TEST_PAYLOAD_CONTRIBUTOR_COUNT=$( echo " ${ TEST_PAYLOAD} " | jq -r --arg CONTRIBUTOR " ${CONTRIBUTOR} " ' select(.contributor==$CONTRIBUTOR) | .count' )
6680 # TEST_PAYLOAD_CONTRIBUTOR_ISSUE_TITLE=$(cat test.json | jq -r --arg CONTRIBUTOR "${CONTRIBUTOR}" 'select(.contributor==$CONTRIBUTOR) | .title' )
6781 TEST_PAYLOAD_CONTRIBUTOR_ISSUE_URL=$( cat test.json | jq -r --arg CONTRIBUTOR " ${CONTRIBUTOR} " ' select(.contributor==$CONTRIBUTOR) | .issue_url' )
68- echo -e " <a href=" https://github.com/${TEST_PAYLOAD_CONTRIBUTOR} " >${TEST_PAYLOAD_CONTRIBUTOR} </a> - ${TEST_PAYLOAD_CONTRIBUTOR_COUNT} "
82+ echo -e " <a href=\ " https://github.com/${TEST_PAYLOAD_CONTRIBUTOR} \ " >${TEST_PAYLOAD_CONTRIBUTOR} </a> - ${TEST_PAYLOAD_CONTRIBUTOR_COUNT} "
6983 done | sort -n -k 4,4 -r >> output.txt
7084 rm -Rf test.json
7185}
0 commit comments