Skip to content

Commit d4c7486

Browse files
committed
chore: stats script parameters
1 parent 574e850 commit d4c7486

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

resources/stats/stats.sh

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,47 @@ 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+
stats+ \
20+
"--start-date,-d=startDate Start date for collecting data, yyyy-mm-dd" \
21+
"--start-sprint,-s=startSprint Or, first sprint to start collecting data for" \
22+
"--stable,-S=stableBranch Branch name for previous stable release"
23+
24+
builder_parse "$@"
25+
26+
if builder_has_option --start-sprint; then
27+
SPRINT_END_DATE=$(gh api -X GET \
28+
repos/keymanapp/keyman/milestones -f direction=desc -f sort=due_on -f state=all --paginate \
29+
--jq '.[] | select(.title == "'${startSprint}'").due_on'
30+
)
31+
if [[ -z "$SPRINT_END_DATE" ]]; then
32+
builder_die "Sprint $startSprint not found on GitHub, or it has no due date"
33+
fi
34+
START_DATE=$(date --date "$SPRINT_END_DATE -11 days" '+%Y-%m-%d')
35+
elif builder_has_option --start-date; then
36+
START_DATE="$startDate"
37+
else
38+
builder_die "Either --start-date or --start-sprint must be specified"
39+
fi
40+
41+
if ! builder_has_option --stable; then
42+
builder_die "--stable must be specified"
43+
fi
44+
45+
echo "Collecting statistics for sprints starting on $START_DATE, and with stable branch $stableBranch"
46+
2047
STATS_ROOT="$KEYMAN_ROOT/resources/stats/data/"
2148
mkdir -p "$STATS_ROOT"
2249

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

2552
for p in "${platforms[@]}"; do
2653
echo "Getting stats for $p"
2754
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"
55+
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"
56+
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"
57+
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"
58+
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"
3259
stat_all=`cat "$STATS_ROOT/${p}pulls.tsv" | wc -l`
3360
stat_stable=`cat "$STATS_ROOT/${p}pulls-stable.tsv" | wc -l`
3461
stat_feat=`cat "$STATS_ROOT/${p}pulls-feat.tsv" | wc -l`

0 commit comments

Comments
 (0)