-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-activity-report.sh
More file actions
77 lines (61 loc) · 2.86 KB
/
git-activity-report.sh
File metadata and controls
77 lines (61 loc) · 2.86 KB
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
#!/bin/bash
# script taken and adaped from apache/lucene (https://github.com/apache/lucene/blob/main/.github/workflows/activity-report.sh)
# script inputs, with some defaults.
# date format examples:
# - now
# - 3 months ago
# - yyyy-mm-dd
: "${SINCE:?The SINCE env variable is required (now, 3 months ago, yyyy-mm-dd)}"
: "${UNTIL:=now}"
: "${REPO:?The REPO env variable is required (format: owner/repo)}"
# compute yyyy-mm-dd formats
SINCE_TS=$(date -u -d "$SINCE" +"%Y-%m-%d")
UNTIL_TS=$(date -u -d "$UNTIL" +"%Y-%m-%d")
# validate repo format
if [[ ! "$REPO" =~ ^[^/]+/[^/]+$ ]]; then
echo "Error: REPO must be in the format 'owner/repo'"
exit 1
fi
# https://cli.github.com/manual/gh_help_environment
export GH_FORCE_TTY=160
export NO_COLOR=true
echo "# Repository Activity Report ($REPO)"
echo "Date range covered by this report: $SINCE_TS .. $UNTIL_TS"
echo "## Commits and issue summary:"
echo -n "* The number of commits to the main branch: "
git log main --pretty='format:%h,%as,%an,%s' --since="$SINCE" --before="$UNTIL" | wc -l
echo -n "* The number of commits to any branch: "
git log --all --pretty='format:%h,%as,%an,%s' --since="$SINCE" --before="$UNTIL" | wc -l
echo -n "* The number of issues filed: "
gh issue list --state all --search "created:$SINCE_TS..$UNTIL_TS" --repo $REPO --limit 1000 --json id | jq length
echo -n "* The number of closed issues out of those filed: "
gh issue list --state all --search "created:$SINCE_TS..$UNTIL_TS is:closed" --repo $REPO --limit 1000 --json id | jq length
echo -n "* The number of pull requests: "
gh pr list --state all --search "created:$SINCE_TS..$UNTIL_TS" --repo $REPO --limit 1000 --json id | jq length
echo -n "* The number of closed pull requests out of those filed: "
gh pr list --state all --search "created:$SINCE_TS..$UNTIL_TS is:closed" --repo $REPO --limit 1000 --json id | jq length
echo
echo "## Top contributors in the given time period (all commits, any branch)"
echo '```'
git log --all --pretty='format:%an' --since="$SINCE" --before="$UNTIL" | sort | uniq -c | sort -r -n
echo '```'
echo
echo "## All pull requests:"
echo '```'
gh pr list --state all --search "created:$SINCE_TS..$UNTIL_TS" --repo $REPO --limit 1000 \
--json number,author,title,createdAt,state \
--template '{{range .}}{{tablerow (printf "#%v" .number ) .state .title .author.name (timeago .createdAt)}}{{end}}'
echo '```'
echo
echo "## All issues:"
echo '```'
gh issue list --state all --search "created:$SINCE_TS..$UNTIL_TS" --repo $REPO --limit 1000 \
--json number,author,title,createdAt,state \
--template '{{range .}}{{tablerow (printf "#%v" .number ) .state .title .author.name (timeago .createdAt)}}{{end}}'
echo '```'
echo
echo "## All commits to the main branch, including hash, author, commit title (one-liners):"
echo '```'
git log main --pretty='format:%h %as %<(20)%an %s' --since="$SINCE_TS" --before="$UNTIL_TS"
echo
echo '```'