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
|
#!/usr/bin/env bash
set -e
set -u
## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
. "${THIS_SCRIPT%/*}/../../resources/build/build-utils.sh"
## END STANDARD BUILD SCRIPT INCLUDE
. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
cd "$THIS_SCRIPT_PATH"
platforms=(android/ ios/ linux/ mac/ web/ windows/ developer/ core/)
builder_describe "Stats collector for Keyman PRs and issues
* You must specify either --start-date (-d) or --start-sprint (-s).
" \
stats+ \
"--start-date,-d=startDate Start date for collecting data, yyyy-mm-dd" \
"--end-date,-e=endDate End date for collecting data, yyyy-mm-dd" \
"--start-sprint,-s=startSprint Or, first sprint to start collecting data for" \
"--end-sprint,-n=endSprint Or, last sprint to collect data for" \
"--stable,-S=stableBranch Branch name for previous stable release (required)"
builder_parse "$@"
if builder_has_option --start-sprint; then
SPRINT_END_DATE=$(gh api -X GET \
repos/keymanapp/keyman/milestones -f direction=desc -f sort=due_on -f state=all --paginate \
--jq '.[] | select(.title == "'${startSprint}'").due_on'
)
if [[ -z "$SPRINT_END_DATE" ]]; then
builder_die "Sprint $startSprint not found on GitHub, or it has no due date"
fi
START_DATE=$(date --date "$SPRINT_END_DATE -11 days" '+%Y-%m-%d')
elif builder_has_option --start-date; then
START_DATE="$startDate"
else
builder_die "Either --start-date or --start-sprint must be specified"
fi
if ! builder_has_option --stable; then
builder_die "--stable must be specified"
fi
if builder_has_option --end-sprint; then
END_DATE=$(gh api -X GET \
repos/keymanapp/keyman/milestones -f direction=desc -f sort=due_on -f state=all --paginate \
--jq '.[] | select(.title == "'${endSprint}'").due_on'
)
if [[ -z "$END_DATE" ]]; then
builder_die "Sprint $endtSprint not found on GitHub, or it has no due date"
fi
END_DATE=$(date --date "$END_DATE" '+%Y-%m-%d')
elif builder_has_option --end-date; then
END_DATE="$endDate"
fi
if [[ ! -z ${END_DATE+x} ]]; then
echo "Collecting statistics for sprints from $START_DATE to $END_DATE, and with stable branch $stableBranch"
SEARCH_RANGE="created:$START_DATE..$END_DATE"
else
echo "Collecting statistics for sprints starting on $START_DATE, and with stable branch $stableBranch"
SEARCH_RANGE="created:>$START_DATE"
fi
STATS_ROOT="$KEYMAN_ROOT/resources/stats/data/"
mkdir -p "$STATS_ROOT"
echo -e "Platform\tAll PRs\t${stableBranch}\tFeatures\tIssues" > "${STATS_ROOT}stats.tsv"
for p in "${platforms[@]}"; do
echo "Getting stats for $p"
mkdir -p "$STATS_ROOT/$p"
gh pr list --json author,createdAt,number,title,labels,state --template "$(cat gh-pr.txt)" --limit 1000 --search "$SEARCH_RANGE -label:auto label:$p" --state all > "$STATS_ROOT/${p}pulls.tsv"
gh pr list --json author,createdAt,number,title,labels,state --template "$(cat gh-pr.txt)" --limit 1000 --search "base:$stableBranch $SEARCH_RANGE -label:auto label:$p" --state all > "$STATS_ROOT/${p}pulls-stable.tsv"
gh pr list --json author,createdAt,number,title,labels,state --template "$(cat gh-pr.txt)" --limit 1000 --search "$SEARCH_RANGE -label:auto label:feat label:$p" --state all > "$STATS_ROOT/${p}pulls-feat.tsv"
gh issue list --json author,createdAt,number,title,labels,state --template "$(cat gh-pr.txt)" --limit 1000 --search "$SEARCH_RANGE -label:auto label:$p" --state all > "$STATS_ROOT/${p}issues.tsv"
stat_all=`cat "$STATS_ROOT/${p}pulls.tsv" | wc -l`
stat_stable=`cat "$STATS_ROOT/${p}pulls-stable.tsv" | wc -l`
stat_feat=`cat "$STATS_ROOT/${p}pulls-feat.tsv" | wc -l`
stat_issues=`cat "$STATS_ROOT/${p}issues.tsv" | wc -l`
echo -e "$p\t$stat_all\t$stat_stable\t$stat_feat\t$stat_issues" >> "${STATS_ROOT}stats.tsv"
done
|