This Github action can be used to store traffic data beyond the two-week period currently supported. It uses the Github API to pull down the traffic data and stores it into a configurable directory and commits it to your repository. In addition, ascii charts are generated and can be automatically inserted into your README to display traffic.
- Create a personal access token (PAT) with repo permissions
- Store it in your repository secrets with the key
TRAFFIC_ACTION_TOKEN
Create a workflow.yml
file in your .github/workflows
directory. An example is provided.
name: Repository Traffic
on:
schedule:
- cron: "55 23 * * 1"
workflow_dispatch:
jobs:
traffic:
runs-on: ubuntu-latest
steps:
- name: Repository Traffic
uses: wumphlett/repostats@v2.1.0
env:
TRAFFIC_ACTION_TOKEN: ${{ secrets.TRAFFIC_ACTION_TOKEN }}
The env
directive with the TRAFFIC_ACTION_TOKEN
is required. Any variables defined in with
are optional.
Three values can be configured in the with
directive of the action.
format_readme (true/false) - control whether the action will format a template readme with traffic data (see below)
default: false
commit_msg (str) - The commit message used when updating traffic data
default: "Updating repository traffic"
traffic_dir (str) - The directory used to store and update traffic data
default: ".traffic"
Optionally, you can use this action to format your readme with traffic data. This works best if you schedule this action daily.
- Create a
TEMPLATE_README.<any type>
file in your.github
directory - Include either {VIEWS_CHART} or {CLONES_CHART} in your template file
- Note: its recommended that you wrap your formatting directive in triple backticks to preserve spacing
- Enable
format_readme
in yourworkflow.yml
file - Trigger the action to format your readme which will automatically commit the changes
- Note, all changes that you want to make to your readme must now be made to the template instead of the readme in the root of the repo
You can use the package responsible for metric collection/aggregation locally instead of in a github action.
pip install github-repo-stats
- Set the environment variables in
.env.example
TRAFFIC_ACTION_TOKEN
- a personal access token with repo permissionsGITHUB_REPOSITORY
- the repo you're trying to collect metrics for (e.g. wumphlett/repostats)GITHUB_WORKSPACE
- your root directory (can be anything if you're not using readme formatting, else root of a repo)TRAFFIC_DIR
- the directory to store collected metrics (default.traffic
)
- Invoke the commands
repo-data
- collects and aggregates metric data (make sure to run at least every two weeks for complete data)repo-readme
- formats a template readme with a views/clones chart
Total Views per Day from 2024-09-29 to 2024-12-27
Repository Views
1 ┼ ╭╮ ╭╮ ╭╮
1 ┤ ││ ││ ││
1 ┤ ││ ││ ││
1 ┤ ││ ││ ││
1 ┤ ││ ││ ││
1 ┤ ││ ││ ││
1 ┤ ││ ││ ││
1 ┤ ││ ││ ││
0 ┤ ││ ││ ││
0 ┤ ││ ││ ││
0 ┤ ││ ││ ││
0 ┤ ││ ││ ││
0 ┤ ││ ││ ││
0 ┤ ││ ││ ││
0 ┤ ││ ││ ││
0 ┼────────────────────────────────╯╰───────────╯╰──────────╯╰──────────────────────────────
Chart last updated - Fri Dec 27 23:58:40 2024 UTC