Skip to content

Commit c0cf62d

Browse files
authored
feat(Script): initial github-monthly-issues-report.sh (#4)
1 parent 5bf42eb commit c0cf62d

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env /bin/bash
2+
set -euo pipefail
3+
4+
###
5+
## GLOBAL VARIABLES
6+
###
7+
GITHUB_TOKEN=${GITHUB_TOKEN:-''}
8+
ORG=${ORG:-''}
9+
REPO=${REPO:-''}
10+
API_URL_PREFIX=${API_URL_PREFIX:-'https://api.github.com'}
11+
MONTH_START=${MONTH_START:-''}
12+
MONTH_END=${MONTH_END:-''}
13+
14+
get_public_pagination () {
15+
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;)
16+
echo "${public_pages:-1}"
17+
}
18+
19+
limit_public_pagination () {
20+
seq "$(get_public_pagination)"
21+
}
22+
23+
repo_issues () {
24+
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
26+
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")
27+
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")')
28+
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)
32+
33+
ISSUE_TIMELINE_LABELED_BY=$(echo "$ISSUE_TIMELINE_PAYLOAD" | jq -s 'first(.[]| .actor.login)' | jq -r)
34+
35+
cat >> test.json << EOF
36+
{
37+
"author": "${ISSUE_AUTHOR}",
38+
"title": "${ISSUE_TITLE}",
39+
"issue_url": "${ISSUE_HTML_URL}",
40+
"contributor": "${ISSUE_TIMELINE_LABELED_BY}"
41+
}
42+
EOF
43+
44+
done
45+
done
46+
}
47+
48+
author_json () {
49+
AUTHORS=$(cat test.json| jq -r '.author' | sort | uniq -c | awk -F " " '{print "{\"author\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .author)
50+
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')
54+
#TEST_PAYLOAD_AUTHOR_ISSUE_TITLE=$(cat test.json | jq -r --arg AUTHOR "${AUTHOR}" 'select(.author==$AUTHOR) | .title')
55+
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}"
57+
done | sort -n -k 4,4 -r >> output.txt
58+
}
59+
60+
contributor_json () {
61+
CONTRIBUTORS=$(cat test.json| jq -r '.contributor' | sort | uniq -c | awk -F " " '{print "{\"contributor\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .contributor)
62+
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')
66+
#TEST_PAYLOAD_CONTRIBUTOR_ISSUE_TITLE=$(cat test.json | jq -r --arg CONTRIBUTOR "${CONTRIBUTOR}" 'select(.contributor==$CONTRIBUTOR) | .title' )
67+
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}"
69+
done | sort -n -k 4,4 -r >> output.txt
70+
rm -Rf test.json
71+
}
72+
73+
repo_issues
74+
author_json
75+
contributor_json

0 commit comments

Comments
 (0)