Skip to content

Commit 9e45159

Browse files
authored
Merge pull request #9431 from keymanapp/chore/stats-script-reverb
chore: stats script parameters
2 parents 7e8e7be + efe3c70 commit 9e45159

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

resources/stats/stats.sh

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,50 @@ cd "$THIS_SCRIPT_PATH"
1515

1616
platforms=(android/ ios/ linux/ mac/ web/ windows/ developer/ core/ common/models/)
1717

18-
startdate=2022-05-01
19-
stable=stable-15.0
18+
builder_describe "Stats collector for Keyman PRs and issues
19+
20+
* You must specify either --start-date (-d) or --start-sprint (-s).
21+
" \
22+
stats+ \
23+
"--start-date,-d=startDate Start date for collecting data, yyyy-mm-dd" \
24+
"--start-sprint,-s=startSprint Or, first sprint to start collecting data for" \
25+
"--stable,-S=stableBranch Branch name for previous stable release (required)"
26+
27+
builder_parse "$@"
28+
29+
if builder_has_option --start-sprint; then
30+
SPRINT_END_DATE=$(gh api -X GET \
31+
repos/keymanapp/keyman/milestones -f direction=desc -f sort=due_on -f state=all --paginate \
32+
--jq '.[] | select(.title == "'${startSprint}'").due_on'
33+
)
34+
if [[ -z "$SPRINT_END_DATE" ]]; then
35+
builder_die "Sprint $startSprint not found on GitHub, or it has no due date"
36+
fi
37+
START_DATE=$(date --date "$SPRINT_END_DATE -11 days" '+%Y-%m-%d')
38+
elif builder_has_option --start-date; then
39+
START_DATE="$startDate"
40+
else
41+
builder_die "Either --start-date or --start-sprint must be specified"
42+
fi
43+
44+
if ! builder_has_option --stable; then
45+
builder_die "--stable must be specified"
46+
fi
47+
48+
echo "Collecting statistics for sprints starting on $START_DATE, and with stable branch $stableBranch"
49+
2050
STATS_ROOT="$KEYMAN_ROOT/resources/stats/data/"
2151
mkdir -p "$STATS_ROOT"
2252

23-
echo -e "Platform\tAll PRs\t${stable}\tFeatures\tIssues" > "${STATS_ROOT}stats.tsv"
53+
echo -e "Platform\tAll PRs\t${stableBranch}\tFeatures\tIssues" > "${STATS_ROOT}stats.tsv"
2454

2555
for p in "${platforms[@]}"; do
2656
echo "Getting stats for $p"
2757
mkdir -p "$STATS_ROOT/$p"
28-
gh pr list --json author,createdAt,number,title,labels,state --template "$(cat gh-pr.txt)" --limit 1000 --search "created:>$startdate -label:auto label:$p" --state all > "$STATS_ROOT/${p}pulls.tsv"
29-
gh pr list --json author,createdAt,number,title,labels,state --template "$(cat gh-pr.txt)" --limit 1000 --search "base:$stable created:>$startdate -label:auto label:$p" --state all > "$STATS_ROOT/${p}pulls-stable.tsv"
30-
gh pr list --json author,createdAt,number,title,labels,state --template "$(cat gh-pr.txt)" --limit 1000 --search "created:>$startdate -label:auto label:feat label:$p" --state all > "$STATS_ROOT/${p}pulls-feat.tsv"
31-
gh issue list --json author,createdAt,number,title,labels,state --template "$(cat gh-pr.txt)" --limit 1000 --search "created:>$startdate -label:auto label:$p" --state all > "$STATS_ROOT/${p}issues.tsv"
58+
gh pr list --json author,createdAt,number,title,labels,state --template "$(cat gh-pr.txt)" --limit 1000 --search "created:>$START_DATE -label:auto label:$p" --state all > "$STATS_ROOT/${p}pulls.tsv"
59+
gh pr list --json author,createdAt,number,title,labels,state --template "$(cat gh-pr.txt)" --limit 1000 --search "base:$stableBranch created:>$START_DATE -label:auto label:$p" --state all > "$STATS_ROOT/${p}pulls-stable.tsv"
60+
gh pr list --json author,createdAt,number,title,labels,state --template "$(cat gh-pr.txt)" --limit 1000 --search "created:>$START_DATE -label:auto label:feat label:$p" --state all > "$STATS_ROOT/${p}pulls-feat.tsv"
61+
gh issue list --json author,createdAt,number,title,labels,state --template "$(cat gh-pr.txt)" --limit 1000 --search "created:>$START_DATE -label:auto label:$p" --state all > "$STATS_ROOT/${p}issues.tsv"
3262
stat_all=`cat "$STATS_ROOT/${p}pulls.tsv" | wc -l`
3363
stat_stable=`cat "$STATS_ROOT/${p}pulls-stable.tsv" | wc -l`
3464
stat_feat=`cat "$STATS_ROOT/${p}pulls-feat.tsv" | wc -l`

0 commit comments

Comments
 (0)