Skip to content

Commit 36a907e

Browse files
authored
Merge pull request #219 from imagewize/add/gh-traffic-sort-by-unique-clones
Add --sort-by flag to gh-traffic.sh
2 parents 8954bb7 + e4ff15b commit 36a907e

4 files changed

Lines changed: 57 additions & 5 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
- Passing positional args without `--no-interactive` still triggers prompts
4444
- Script auto-generates AI-powered description and creates PR via GitHub CLI
4545
- PRs: include a short description of scope, commands run/outputs (or screenshots for doc-only visual changes), and linked issues if applicable. Note any risk areas (data migration, remote writes).
46+
- After modifying scripts in the catalog (e.g., `scripts/git/*.sh`), regenerate `go/internal/catalog/catalog.json` by running `go generate ./...` from the repo root, then commit the updated file before pushing.
4647

4748
### Important Rules
4849
- **AI co-authorship in commits is allowed**`Co-Authored-By` lines for Claude or Mistral Vibe are permitted

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [5.20.0] - 2026-09-09
11+
12+
### Added
13+
14+
- **`gh-traffic.sh` gains `--sort-by`** to sort the summary table by `unique-clones` or
15+
`unique-views`. Previously the summary sorted by unique views when views were shown
16+
and by unique clones when only clones were requested; the new flag lets you force
17+
either order regardless of which sections are enabled.
18+
1019
## [5.19.0] - 2026-09-04
1120

1221
### Fixed

go/internal/catalog/catalog.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,14 @@
385385
"required": false,
386386
"description": "Show only the cross-repo summary table, skipping per-repo detail",
387387
"raw": "--summary optional {} Show only the cross-repo summary table, skipping per-repo detail"
388+
},
389+
{
390+
"name": "--sort-by",
391+
"required_raw": "optional",
392+
"required": false,
393+
"default": "unique-views",
394+
"description": "Sort summary by 'unique-views' or 'unique-clones' (default: unique-views when views shown, unique-clones when only clones shown)",
395+
"raw": "--sort-by optional {unique-views} Sort summary by 'unique-views' or 'unique-clones' (default: unique-views when views shown, unique-clones when only clones shown)"
388396
}
389397
],
390398
"examples": [

scripts/git/gh-traffic.sh

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# @flag --json optional {} Output raw JSON instead of formatted tables
2121
# @flag --quiet optional {} Suppress header rows in table output
2222
# @flag --summary optional {} Show only the cross-repo summary table, skipping per-repo detail
23+
# @flag --sort-by optional {unique-views} Sort summary by 'unique-views' or 'unique-clones' (default: unique-views when views shown, unique-clones when only clones shown)
2324
# @example wp-ops gh-traffic imagewize/nynaeve --quiet
2425
# @example wp-ops gh-traffic imagewize/nynaeve imagewize/wp-ops --all
2526

@@ -33,6 +34,7 @@ DAYS=14
3334
SHOW_VIEWS=false
3435
SHOW_CLONES=false
3536
SHOW_REFERRERS=false
37+
SORT_BY="" # Will default to unique-views or unique-clones based on visible sections
3638
REPOS=()
3739

3840
# Help function
@@ -56,6 +58,8 @@ Options:
5658
-j, --json Output raw JSON instead of formatted tables
5759
-q, --quiet Suppress header rows in table output
5860
-s, --summary Show only the cross-repo summary table, skipping per-repo detail
61+
--sort-by COL Sort summary by COL: 'unique-views' or 'unique-clones'
62+
(default: unique-views when views shown, unique-clones when only clones shown)
5963
6064
Arguments:
6165
owner/repo GitHub repository in format owner/repo (required, repeatable)
@@ -65,9 +69,10 @@ Sections:
6569
always had. --clones, --referrers, and --all opt into the rest.
6670
6771
When more than one repo is given, a summary table (one row per repo, 14-day
68-
totals) is printed first, sorted by unique views descending — unique clones,
69-
if views weren't requested. It's skipped for a single repo (redundant with
70-
the detail table) and for a referrers-only run (nothing numeric to sort).
72+
totals) is printed first, sorted by unique views descending by default (unique
73+
clones if views weren't requested, or as specified with --sort-by). It's skipped
74+
for a single repo (redundant with the detail table) and for a referrers-only
75+
run (nothing numeric to sort).
7176
7277
--summary shows only that rollup, for any number of repos, and drops
7378
--referrers if it was also given (or implied by --all) — the summary has
@@ -89,6 +94,9 @@ Examples:
8994
# Just the rollup across many repos, views and clones
9095
./scripts/git/gh-traffic.sh --all --summary imagewize/nynaeve imagewize/wp-ops imagewize/aludra
9196
97+
# Sort summary by unique clones instead of unique views
98+
./scripts/git/gh-traffic.sh --all --summary --sort-by unique-clones imagewize/nynaeve imagewize/wp-ops
99+
92100
Requirements:
93101
- GitHub CLI (gh) installed and authenticated
94102
- jq for JSON processing
@@ -160,6 +168,20 @@ while [[ $# -gt 0 ]]; do
160168
SUMMARY_ONLY=true
161169
shift
162170
;;
171+
--sort-by)
172+
if [[ -n "${2:-}" ]]; then
173+
if [[ "${2:-}" =~ ^(unique-views|unique-clones)$ ]]; then
174+
SORT_BY="$2"
175+
shift 2
176+
else
177+
echo "Error: --sort-by must be 'unique-views' or 'unique-clones'" >&2
178+
exit 1
179+
fi
180+
else
181+
echo "Error: --sort-by requires a value" >&2
182+
exit 1
183+
fi
184+
;;
163185
-*)
164186
echo "Error: Unknown option $1" >&2
165187
echo "Use --help for usage information" >&2
@@ -361,7 +383,13 @@ print_referrers() {
361383
# views weren't requested).
362384
print_summary() {
363385
local sort_label="unique views"
364-
[[ "$SHOW_VIEWS" = false ]] && sort_label="unique clones"
386+
if [[ -n "$SORT_BY" ]]; then
387+
if [[ "$SORT_BY" = "unique-clones" ]]; then
388+
sort_label="unique clones"
389+
fi
390+
elif [[ "$SHOW_VIEWS" = false ]]; then
391+
sort_label="unique clones"
392+
fi
365393

366394
local header=""
367395
if [[ "$SHOW_VIEWS" = true && "$SHOW_CLONES" = true ]]; then
@@ -386,7 +414,13 @@ print_summary() {
386414
clones_uniques=$(printf '%s' "${CLONES_PAYLOAD[$i]}" | jq -r '.uniques')
387415
fi
388416

389-
if [[ "$SHOW_VIEWS" = true ]]; then
417+
if [[ -n "$SORT_BY" ]]; then
418+
if [[ "$SORT_BY" = "unique-clones" ]]; then
419+
sort_key="$clones_uniques"
420+
else
421+
sort_key="$views_uniques"
422+
fi
423+
elif [[ "$SHOW_VIEWS" = true ]]; then
390424
sort_key="$views_uniques"
391425
else
392426
sort_key="$clones_uniques"

0 commit comments

Comments
 (0)