Skip to content

ci: archive traffic stats daily - #54

Open
Statyk7 wants to merge 1 commit into
mainfrom
ci/traffic-stats
Open

Statyk7 wants to merge 1 commit into
mainfrom
ci/traffic-stats

Conversation

@Statyk7

@Statyk7 Statyk7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Description

GitHub keeps clone, view, and referrer traffic for 14 days only. This adds a daily traffic_stats workflow that saves it to CSV files on the orphan stats branch, so we keep a history of how the plugin is being picked up.

  • traffic.csv: one row per day with clones, unique cloners, views, and unique viewers. Each run rewrites the days still in GitHub's window, so today's partial count is corrected the next day, and older rows are kept.
  • referrers.csv: a dated snapshot of the top referrers, which GitHub only reports as a 14-day total. A second run on the same day replaces that day's snapshot.

The stats branch is already seeded with Oct 21 to Nov 3 and Nov 12 to Nov 25. Nov 4 to Nov 11 is lost. Pushes to stats don't trigger CI, which runs on pull requests only.

Setup before merging: the traffic API isn't readable with the default GITHUB_TOKEN, so the workflow needs a TRAFFIC_STATS_TOKEN repo secret: a fine-grained token scoped to this repo with Administration: Read-only. Until it is set, the job fails at the fetch step.

The merge step was tested locally against the live API, run twice to check that a second run adds no duplicates. The workflow itself has not run on GitHub yet.

Type of Change

  • New feature (feat)
  • Bug fix (fix)
  • Code refactor (refactor)
  • Documentation (docs)
  • CI change (ci)
  • Chore (chore)

🤖 Generated with Claude Code

https://claude.ai/code/session_017Vxxv9fVFGupLXEnmx5bSq

GitHub keeps clone and view traffic for 14 days only. Save it daily to
CSV files on the orphan stats branch so the history is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017Vxxv9fVFGupLXEnmx5bSq
@Statyk7
Statyk7 requested a review from a team as a code owner November 26, 2026 14:59
Comment on lines +6 to +8
# The traffic API needs a token with push access to the repo, which the default
# GITHUB_TOKEN does not have for this endpoint. TRAFFIC_STATS_TOKEN must be a
# fine-grained token scoped to this repo with "Administration: read".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Push access" and "Administration: read" disagree. Only the read-only scope is needed, so drop the push-access wording so nobody creates an over-scoped token.

Suggested change
# The traffic API needs a token with push access to the repo, which the default
# GITHUB_TOKEN does not have for this endpoint. TRAFFIC_STATS_TOKEN must be a
# fine-grained token scoped to this repo with "Administration: read".
# The traffic API is not readable with the default GITHUB_TOKEN.
# TRAFFIC_STATS_TOKEN must be a fine-grained token scoped to this repo with
# "Administration: read".

Comment on lines +36 to +41
if git fetch --depth=1 origin stats; then
git checkout -B stats FETCH_HEAD
else
git checkout --orphan stats
git rm -rfq .
fi

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any git fetch failure, including a network error, sends the job into the orphan path, and the run then fails later at push with a non-fast-forward error. Check whether the branch exists explicitly so a real fetch error fails right here.

Suggested change
if git fetch --depth=1 origin stats; then
git checkout -B stats FETCH_HEAD
else
git checkout --orphan stats
git rm -rfq .
fi
if git ls-remote --exit-code --heads origin stats >/dev/null; then
git fetch --depth=1 origin stats
git checkout -B stats FETCH_HEAD
else
git checkout --orphan stats
git rm -rfq .
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants