Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
bar-chart-2

GitHub Action

github-repo-stats

v1.0.0

github-repo-stats

bar-chart-2

github-repo-stats

github-repo-stats

Installation

Copy and paste the following snippet into your .yml file.

              

- name: github-repo-stats

uses: jgehrcke/[email protected]

Learn more about this action in jgehrcke/github-repo-stats

Choose a version

github-repo-stats

A GitHub Action to periodically inspect a target repository and generate a report for it.

The primary purpose of this Action is to overcome the 14-day limitation of GitHub's built-in traffic statistics.

Demo

Highlights

  • The report is generated in two document formats: HTML and PDF.
  • The HTML report resembles how GitHub renders Markdown and is meant to be exposed via GitHub pages.
  • Charts are based on Altair/Vega.
  • The PDF report contains vector graphics.
  • Data updates, aggregation results, and report files are stored in the git repository that you install this Action in: this Action commits changes to a special branch. No cloud storage or database needed. As a result, you have complete and transparent history for data updates and reports, with clear commit messages, in a single place.
  • The observed repository (the one to build the report for) can be different from the repository you install this Action in.
  • The HTML report can be served right away via GitHub pages (that is how the demo above works).
  • Careful data analysis: there are a number of traps (example) when aggregating data based on what the GitHub Traffic API returns. This project tries to not fall for them. One goal of this project is to perform advanced analysis where possible.

As of now, the report contains:

  • Traffic stats:
    • Unique and total views per day
    • Unique and total clones per day
    • Top referrers (where people come from when they land in your repository)
    • Top paths (what people like to look at in your repository)
  • Evolution of stargazers
  • Evolution of forks

Documentation

Clarification: "stats repository" vs. "data repository"

  • The "stats repository" is the repository to fetch stats for and to generate the report for.
  • The "data repository" is the repository to store data and report files in.

These two repositories can be the same. But they don't have to be :-).

That is, you can for example set up this Action in a private repository but have it observe a public repository.

Setup

The recommended way to run this Action is on a schedule, once per day.

Create a GitHub Actions workflow file (for example .github/workflows/github-repo-stats.yml) with for example the following contents:

on:
  schedule:
    # Run this once per day (hours in UTC time zone).
    # Towards the end of the day for keeping the last
    # data point meaningful.
    - cron: "* 23 * * *"
  workflow_dispatch: # Allow for running this manually.

jobs:
  j1:
    name: github-repo-stats
    runs-on: ubuntu-latest
    steps:
      - name: GHRS
        uses: jgehrcke/github-repo-stats@HEAD
        with:
          # Define the target repository, the repo to fetch
          # stats for and to generate the report for.
          # Leave this undefined when stats repository
          # and data repository should be the same.
          repository: jgehrcke/covid-19-germany-gae
          # Required token privileges: Can read the target
          # repo, and can push to the repository this
          # workflow file lives in (to store data and
          # the report files).
          ghtoken: ${{ secrets.ghrs_github_api_token }}

Input parameter reference

Extract from action.yml:

  repository:
    description: >
      Repository spec (<owner-or-org>/<reponame>) for the repository to fetch
      statistics for.
    default: ${{ github.repository }}
  ghtoken:
    description: >
      GitHub API token for reading repo stats and for interacting with the data
      repo (must be set if repo to fetch stats for is not the data repo).
    default: ${{ github.token }}
  databranch:
    description: >
      Data branch: Branch to push data to (in the data repo).
    default: github-repo-stats
  ghpagesprefix:
    description: >
      Set this if the data branch in the data repo is exposed via GitHub pages.
      Must not end with a slash. Example: https://jgehrcke.github.io/ghrs-test
    default: none

It's recommended that you create the data branch and delete all files from that branch before setting this Action up in your reposistory, so that this data branch appears as a tidy environment. You can of course do that later, too.

Resources