-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate_weekly_report.sh
executable file
·103 lines (84 loc) · 3.11 KB
/
generate_weekly_report.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
if [ -z "$2" ]; then
echo "Please supply a repo in the form of org/repo and an organization name (e.g. rancher)"
exit 1
fi
SYSTEM=$(uname)
#check if MacOS or Linux because date is different
if [ "$SYSTEM" == "Darwin" ]; then
WEEKAGO=$(date -v -7d +%F)
else
WEEKAGO=$(date --date="last week" +%F)
fi
WEEK_NO=$(date +"%U %Y")
TEMPLATE="{{range .}}* [#{{.number}}]({{.url}}): {{.title}}{{\"\n\"}}{{end}}"
REPO_NAME=$1
ORG=$2
ORG_NAME="$(gh api -X GET "orgs/"$ORG"/members" -F per_page=100 --paginate --cache 1h --template='{{range .}}-author:{{.login}} {{end}}')"
read -r FORKS STARS < <(gh api -X GET "repos/"$REPO_NAME"" --template='{{.forks}} {{.stargazers_count}}')
FILENAME=".lastweek_${REPO_NAME//\//_}"
#echo $FILENAME
#check if we've already gotten the number of stars/forks from the previous week
if [ -f "$FILENAME" ]; then
. $FILENAME
#echo "Last week stats"
#echo $LAST_WEEK_FORKS
#echo $LAST_WEEK_STARS
STAR_DIFF=$(expr $STARS - $LAST_WEEK_STARS)
FORK_DIFF=$(expr $FORKS - $LAST_WEEK_FORKS)
echo "LAST_WEEK_STARS=$STARS" > ./$FILENAME
echo "LAST_WEEK_FORKS=$FORKS" >> ./$FILENAME
else
echo "LAST_WEEK_STARS=$STARS" > ./$FILENAME
echo "LAST_WEEK_FORKS=$FORKS" >> ./$FILENAME
fi
CLOSED_PR=$(gh pr list --limit 100 --repo $1 -S "closed:>$WEEKAGO" -s closed -t="$TEMPLATE" --json=title,milestone,url,number)
OPENED_PR=$(gh pr list --limit 100 --repo $1 -S "created:>$WEEKAGO" -s all -t="$TEMPLATE" --json=title,milestone,url,number)
CLOSED_ISSUES=$(gh issue list --limit 100 --repo $1 -S "closed:>$WEEKAGO" -s closed -t="$TEMPLATE" --json=title,milestone,url,number)
OPENED_ISSUES=$(gh issue list --limit 100 --repo $1 -S "created:>$WEEKAGO" -s all -t="$TEMPLATE" --json=title,milestone,url,number)
COMMUNITY_PR_CLOSED=$(gh pr list --limit 100 --repo $1 -S "closed:>$WEEKAGO $ORG_NAME" -s closed -t="$TEMPLATE" --json=title,milestone,url,number)
COMMUNITY_PR_OPEN=$(gh pr list --limit 100 --repo $1 -S "created:>$WEEKAGO $ORG_NAME" -s all -t="$TEMPLATE" --json=title,milestone,url,number)
none_or_print () {
if [ -z "$1" ]; then
echo "None"
else
echo "$1"
fi
echo ""
}
echo "# Weekly Report"
echo "Weekly status report for $REPO_NAME Week #$WEEK_NO"
echo ""
echo ""
echo "## Here's what the team has focused on this week:"
echo "* "
echo ""
echo "## Weekly Stats"
echo "| | Opened this week| Closed this week|"
echo "|--|---|-----|"
echo "|Issues| " $(wc -l <<< "$OPENED_ISSUES") "| "$(wc -l <<< "$CLOSED_ISSUES")"|"
echo "|PR's| " $(wc -l <<< "$OPENED_PR") "| " $(wc -l <<< "$CLOSED_PR")"|"
echo ""
echo "| | |"
echo "|--|--|"
echo "| New stars | "$STAR_DIFF"|"
echo "| New forks | "$FORK_DIFF"|"
echo ""
echo "## PR's Closed"
#closed PRs in the last week
none_or_print "$CLOSED_PR"
echo "## PR's Opened"
#opened PRSs last week
none_or_print "$OPENED_PR"
echo "## Issues Opened"
#opened issuess in the last week
none_or_print "$OPENED_ISSUES"
echo "## Issues Closed"
#closed issues in the last week
none_or_print "$CLOSED_ISSUES"
echo "## Community PRs Closed"
#Community PR's closed
none_or_print "$COMMUNITY_PR_CLOSED"
echo "## Community PRs Opened"
#Community PR's
none_or_print "$COMMUNITY_PR_OPEN"