@@ -50,6 +50,19 @@ require_env_var MONTH_END "Month end date (YYYY-MM-DD)"
5050require_command jq
5151validate_github_token
5252
53+ # Validate date format to prevent jq filter injection
54+ if ! [[ " ${MONTH_START} " =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
55+ print_error " MONTH_START must be YYYY-MM-DD, got: ${MONTH_START} "
56+ exit 1
57+ fi
58+ if ! [[ " ${MONTH_END} " =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
59+ print_error " MONTH_END must be YYYY-MM-DD, got: ${MONTH_END} "
60+ exit 1
61+ fi
62+
63+ ISSUES_TEMP=$( mktemp)
64+ trap ' rm -f "${ISSUES_TEMP}"' EXIT
65+
5366get_issue_pagination () {
5467 issue_pages=$( curl -s -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; )
5568 echo " ${issue_pages:- 1} "
@@ -61,49 +74,47 @@ limit_issue_pagination () {
6174
6275repo_issues () {
6376 for PAGE in $( limit_issue_pagination) ; do
64- for i in $( curl -s -H " Authorization: token ${GITHUB_TOKEN} " " ${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
77+ for i in $( curl -s -H " Authorization: token ${GITHUB_TOKEN} " " ${API_URL_PREFIX} /repos/${ORG} /${REPO} /issues?state=all&labels=Linked%20[AC]&page=${PAGE} &per_page=100" | jq -r --arg s " ${MONTH_START} " --arg e " ${MONTH_END} " ' map(select(.created_at | . >= ($s+" T00:00") and . <= ($e+" T23:59"))) | sort_by(.number) | .[].number' ) ; do
6578 ISSUE_PAYLOAD=$( curl -s -H " Authorization: token ${GITHUB_TOKEN} " " ${API_URL_PREFIX} /repos/${ORG} /${REPO} /issues/${i} " -H " Accept: application/vnd.github.mercy-preview+json" )
6679 ISSUE_TIMELINE_PAYLOAD=$( curl -s -H " Authorization: token ${GITHUB_TOKEN} " " ${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")' )
6780
6881 ISSUE_AUTHOR=$( echo " ${ISSUE_PAYLOAD} " | jq -r .user.login)
69- ISSUE_TITLE=$( echo " ${ISSUE_PAYLOAD} " | jq -r .title | tr ' " ' " ' " )
82+ ISSUE_TITLE=$( echo " ${ISSUE_PAYLOAD} " | jq -r .title)
7083 ISSUE_HTML_URL=$( echo " ${ISSUE_PAYLOAD} " | jq -r .html_url)
7184
7285 ISSUE_TIMELINE_LABELED_BY=$( echo " ${ISSUE_TIMELINE_PAYLOAD} " | jq -s ' first(.[]| .actor.login)' | jq -r)
7386
74- cat >> test.json << EOF
75- {
76- "author": "${ISSUE_AUTHOR} ",
77- "title": "${ISSUE_TITLE} ",
78- "issue_url": "${ISSUE_HTML_URL} ",
79- "contributor": "${ISSUE_TIMELINE_LABELED_BY} "
80- }
81- EOF
87+ jq -n \
88+ --arg author " ${ISSUE_AUTHOR} " \
89+ --arg title " ${ISSUE_TITLE} " \
90+ --arg url " ${ISSUE_HTML_URL} " \
91+ --arg contrib " ${ISSUE_TIMELINE_LABELED_BY} " \
92+ ' {"author":$author,"title":$title,"issue_url":$url,"contributor":$contrib}' \
93+ >> " ${ISSUES_TEMP} "
8294 done
8395 done
8496}
8597
8698author_json () {
87- AUTHORS=$( cat test.json | jq -r ' .author' | sort | uniq -c | awk -F " " ' {print "{\"author\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .author)
99+ AUTHORS=$( cat " ${ISSUES_TEMP} " | jq -r ' .author' | sort | uniq -c | awk -F " " ' {print "{\"author\":""\""\ $2"\""",\"count\":" $1"}"}' | jq -r .author)
88100 for AUTHOR in ${AUTHORS} ; do
89- TEST_PAYLOAD=$( cat test.json | jq -r ' .author' | sort | uniq -c | awk -F " " ' {print "{\"author\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .)
101+ TEST_PAYLOAD=$( cat " ${ISSUES_TEMP} " | jq -r ' .author' | sort | uniq -c | awk -F " " ' {print "{\"author\":""\""\ $2"\""",\"count\":" $1"}"}' | jq -r .)
90102 TEST_PAYLOAD_AUTHOR=$( echo " ${TEST_PAYLOAD} " | jq -r --arg AUTHOR " ${AUTHOR} " ' select(.author==$AUTHOR) | .author' )
91103 TEST_PAYLOAD_AUTHOR_COUNT=$( echo " ${TEST_PAYLOAD} " | jq -r --arg AUTHOR " ${AUTHOR} " ' select(.author==$AUTHOR) | .count' )
92- TEST_PAYLOAD_AUTHOR_ISSUE_URL=$( cat test.json | jq -r --arg AUTHOR " ${AUTHOR} " ' select(.author==$AUTHOR) | .title, .issue_url' )
104+ TEST_PAYLOAD_AUTHOR_ISSUE_URL=$( cat " ${ISSUES_TEMP} " | jq -r --arg AUTHOR " ${AUTHOR} " ' select(.author==$AUTHOR) | .title, .issue_url' )
93105 echo -e " <a href=\" https://github.com/${TEST_PAYLOAD_AUTHOR} \" >${TEST_PAYLOAD_AUTHOR} </a> - ${TEST_PAYLOAD_AUTHOR_COUNT} "
94106 done | sort -n -k 4,4 -r >> output.txt
95107}
96108
97109contributor_json () {
98- CONTRIBUTORS=$( cat test.json | jq -r ' .contributor' | sort | uniq -c | awk -F " " ' {print "{\"contributor\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .contributor)
110+ CONTRIBUTORS=$( cat " ${ISSUES_TEMP} " | jq -r ' .contributor' | sort | uniq -c | awk -F " " ' {print "{\"contributor\":""\""\ $2"\""",\"count\":" $1"}"}' | jq -r .contributor)
99111 for CONTRIBUTOR in ${CONTRIBUTORS} ; do
100- TEST_PAYLOAD=$( cat test.json | jq -r ' .contributor' | sort | uniq -c | awk -F " " ' {print "{\"contributor\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .)
112+ TEST_PAYLOAD=$( cat " ${ISSUES_TEMP} " | jq -r ' .contributor' | sort | uniq -c | awk -F " " ' {print "{\"contributor\":""\""\ $2"\""",\"count\":" $1"}"}' | jq -r .)
101113 TEST_PAYLOAD_CONTRIBUTOR=$( echo " ${TEST_PAYLOAD} " | jq -r --arg CONTRIBUTOR " ${CONTRIBUTOR} " ' select(.contributor==$CONTRIBUTOR) | .contributor' )
102114 TEST_PAYLOAD_CONTRIBUTOR_COUNT=$( echo " ${TEST_PAYLOAD} " | jq -r --arg CONTRIBUTOR " ${CONTRIBUTOR} " ' select(.contributor==$CONTRIBUTOR) | .count' )
103- TEST_PAYLOAD_CONTRIBUTOR_ISSUE_URL=$( cat test.json | jq -r --arg CONTRIBUTOR " ${CONTRIBUTOR} " ' select(.contributor==$CONTRIBUTOR) | .issue_url' )
115+ TEST_PAYLOAD_CONTRIBUTOR_ISSUE_URL=$( cat " ${ISSUES_TEMP} " | jq -r --arg CONTRIBUTOR " ${CONTRIBUTOR} " ' select(.contributor==$CONTRIBUTOR) | .issue_url' )
104116 echo -e " <a href=\" https://github.com/${TEST_PAYLOAD_CONTRIBUTOR} \" >${TEST_PAYLOAD_CONTRIBUTOR} </a> - ${TEST_PAYLOAD_CONTRIBUTOR_COUNT} "
105117 done | sort -n -k 4,4 -r >> output.txt
106- rm -Rf test.json
107118}
108119
109120repo_issues
0 commit comments