Metadata-Version: 2.5
Name: github-statistics
Version: 0.1.0
Summary: Daily, visual activity statistics for GitHub organisations and repositories
Project-URL: Homepage, https://github.com/lfreleng-actions/github-statistics-action
Project-URL: Repository, https://github.com/lfreleng-actions/github-statistics-action
Project-URL: Issues, https://github.com/lfreleng-actions/github-statistics-action/issues
Author-email: The Linux Foundation <mwatkins@linuxfoundation.org>
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: httpx[http2]==0.28.1
Requires-Dist: jinja2==3.1.6
Requires-Dist: jsonschema==4.26.0
Requires-Dist: matplotlib==3.11.2
Requires-Dist: numpy==2.4.6
Requires-Dist: pillow==13.0.0
Requires-Dist: rich==15.0.0
Requires-Dist: typer==0.29.2
Provides-Extra: dev
Requires-Dist: hypothesis==6.170.15; extra == 'dev'
Requires-Dist: mypy==2.4.1; extra == 'dev'
Requires-Dist: pytest-asyncio==1.5.0; extra == 'dev'
Requires-Dist: pytest-cov==7.1.0; extra == 'dev'
Requires-Dist: pytest==9.2.0; extra == 'dev'
Requires-Dist: pyyaml==6.0.4; extra == 'dev'
Requires-Dist: respx==0.23.1; extra == 'dev'
Requires-Dist: ruff==0.17.5; extra == 'dev'
Requires-Dist: types-jsonschema==4.26.0.20261006; extra == 'dev'
Requires-Dist: types-pyyaml==6.0.12.20261113; extra == 'dev'
Description-Content-Type: text/markdown

<!--
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2025 The Linux Foundation
-->

# 📊 GitHub Statistics

<!-- prettier-ignore-start -->
<!-- markdownlint-disable-next-line MD013 -->
[![Linux Foundation](https://img.shields.io/badge/Linux-Foundation-blue)](https://linuxfoundation.org/) [![Source Code](https://img.shields.io/badge/GitHub-100000?logo=github&logoColor=white&color=blue)](https://github.com/lfreleng-actions/github-statistics-action) [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/lfreleng-actions/github-statistics-action/badge)](https://scorecard.dev/viewer/?uri=github.com/lfreleng-actions/github-statistics-action)
<!-- prettier-ignore-end -->

Daily, visual activity statistics for a GitHub organisation, a set of
its repositories, or a single repository. Pull requests, issues and CI
each get a 3D bar chart with one bar per day across a configurable
window, with contributor leaderboards beneath. A Python command line
tool generates the output as a GitHub Pages site, and a thin composite
action wraps it for use in workflows.

## 🗒️ Published reports

The link to the published site will appear here once the site goes live.

## Usage

```yaml
permissions:
  actions: read
  checks: read
  contents: read
  issues: read
  pull-requests: read

steps:
  - uses: lfreleng-actions/github-statistics-action@<commit-sha>  # vX.Y.Z
    id: statistics
    with:
      org: lfreleng-actions
      token: ${{ steps.app-token.outputs.token }}
      config: ${{ secrets.GHS_CONFIG || vars.GHS_CONFIG }}
      org_bots: ${{ vars.GHS_ORG_BOTS }}
      output_dir: site
```

The action runs `github-statistics run`: for each target it clears
the target's `img/` and `data/` directories, collects, renders the
charts, writes the JSON exports and the target's pages, then writes
the landing page. `command: scope` instead resolves the public
repositories in scope and publishes them as outputs.

The action installs the release named in
`.github/runtime-pin/requirements.txt`, which Dependabot keeps
current. `tool_version` overrides the pin; pull requests and
`use_local_source: "true"` run the action's own source instead.

### Inputs

Every input is optional and defaults to the empty string. The action
passes a flag to the tool when its input holds a value, so an older pinned
release never receives a flag it does not know. List inputs accept
commas, spaces or newlines between items.

<!-- markdownlint-disable MD013 -->

| Input              | Description                                                                      |
| ------------------ | -------------------------------------------------------------------------------- |
| `command`          | `run` (default) or `scope`                                                       |
| `config`           | Configuration as JSON, raw or base64; see [Configuration](#configuration)        |
| `org`              | Owner to report on: shorthand for a one-target configuration                     |
| `repositories`     | Repository names or globs to keep                                                |
| `exclude`          | Repository names or globs to drop; refused together with `repositories`          |
| `repo`             | `owner/name` for repository scope                                                |
| `token`            | Token to read GitHub with (default: the job's `github.token`)                    |
| `days`             | Window length in days                                                            |
| `until`            | Last day of the window, `YYYY-MM-DD` (default: yesterday, UTC)                   |
| `output_dir`       | Site root (default `site`)                                                       |
| `cache_dir`        | Store root (default `~/.cache/github-statistics`)                                |
| `budget`           | REST requests this run may spend                                                 |
| `refresh`          | `true` to ignore watermarks and re-read the window (`run`)                       |
| `strict`           | `true` to exit 2 when a repository was unreadable (`run`)                        |
| `org_bots`         | The organisation's own bots; replaces the configured list                        |
| `external_bots`    | Bots from outside the organisation; replaces the configured list                 |
| `members`          | Humans counted as members; replaces the configured list                          |
| `member_orgs`      | Organisations whose public members count; replaces the configured list           |
| `ignore_logins`    | Accounts left out of every output; replaces the configured list                  |
| `tool_version`     | `github-statistics` release to run instead of the runtime pin                    |
| `use_local_source` | `true` to run the action's own source (pull requests always do)                  |

<!-- markdownlint-enable MD013 -->

The action carries the token as `GITHUB_TOKEN`, so a configuration used
with the action leaves `token_env` at its default. With
`command: scope`, setting `refresh` or `strict` to `true` fails:
neither applies to `scope`.

### Outputs

<!-- markdownlint-disable MD013 -->

| Output              | Command | Description                                                    |
| ------------------- | ------- | -------------------------------------------------------------- |
| `site_dir`          | `run`   | Directory holding the site                                     |
| `requests_used`     | `run`   | REST requests the run spent                                    |
| `coverage_complete` | `run`   | `true` when every day of every metric is complete              |
| `gap_days`          | `run`   | Days the charts show as gaps, summed over targets              |
| `unclassified_bots` | `run`   | Comma-separated bots that no identity list names               |
| `repositories`      | `scope` | Comma-separated public repositories in scope                   |
| `repository_count`  | `scope` | Number of public repositories in scope                         |

<!-- markdownlint-enable MD013 -->

The run also appends its collection and coverage tables and the site
location to the job summary, and warns about each unclassified bot with the configuration
keys to add it to.

### Exit codes

| Code | Meaning                                                    |
| ---- | ---------------------------------------------------------- |
| 0    | Success; a spent budget still renders and builds the site  |
| 1    | Invalid configuration, or another failure                  |
| 2    | `strict` set and a repository was unreadable               |
| 3    | GitHub rejected the token; the run stops before rendering  |

### Token permissions

The tool reads and never writes. Grant read access alone:

<!-- markdownlint-disable MD013 -->

| Scope           | Token                                                                                                                    | Read permissions                                 |
| --------------- | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------ |
| Organisation    | App installation token naming the resolved public repositories, or a fine-grained PAT limited to public repositories     | metadata, issues, pull requests, actions, checks |
| Repository list | Same, for those repositories                                                                                             | same                                             |
| Single repo     | The job's `GITHUB_TOKEN`                                                                                                 | same, through the job's `permissions`            |

<!-- markdownlint-enable MD013 -->

Never grant write or organisation permissions. A `401` stops the run
with exit code 3; a `403` on one repository marks it unreadable for
the run, and the coverage table says so.

## Configuration

The `config` input, or `--config-data` on the command line, takes the
configuration as JSON, raw or base64; `--config` takes a file. A
complete example (design Appendix A):

```json
{
  "version": 1,
  "identities": {
    "org_bots": [
      "lf-releng-issues-triage-bot[bot]",
      "lf-releng-code-monkey-bot[bot]",
      "lf-releng-code-review-bot[bot]"
    ],
    "external_bots": [
      "dependabot[bot]",
      "pre-commit-ci[bot]",
      "copilot-pull-request-reviewer[bot]",
      "Copilot",
      "github-actions[bot]",
      "sonarqubecloud[bot]"
    ],
    "members": [],
    "member_orgs": [],
    "ignore_logins": []
  },
  "targets": [
    {
      "owner": "lfreleng-actions",
      "token_env": "GITHUB_TOKEN",
      "exclude": ["test-tags-*"],
      "scan_archived": false,
      "scan_forks": false,
      "scan_templates": true,
      "identities": {}
    }
  ],
  "window": { "days": 365 },
  "metrics": {
    "pull_requests": true,
    "issues": true,
    "workflows": true,
    "workflow_outcomes": false
  },
  "classes": ["all", "member", "external", "org_bot", "external_bot"],
  "render": {
    "width": 3840,
    "height": 2160,
    "derivatives": [1920],
    "svg": false,
    "palette": {},
    "back_on_tie": {
      "pull_requests": "closed",
      "issues": "closed",
      "workflows": "jobs"
    }
  },
  "contributors": { "top_n": 100, "columns": [] },
  "budget": { "rest": 3000, "graphql_points": 1500, "reserve": 500 },
  "output": { "directory": "site" },
  "cache": { "directory": null }
}
```

### Identities

Each identity list is available at every level:

<!-- markdownlint-disable MD013 -->

| Key            | Config JSON (`identities.*`) | CLI               | Action input    | Variable for the action input |
| -------------- | ---------------------------- | ----------------- | --------------- | ----------------------------- |
| Our bots       | `org_bots`                   | `--org-bots`      | `org_bots`      | `vars.GHS_ORG_BOTS`           |
| External bots  | `external_bots`              | `--external-bots` | `external_bots` | `vars.GHS_EXTERNAL_BOTS`      |
| Extra members  | `members`                    | `--members`       | `members`       | `vars.GHS_MEMBERS`            |
| Member orgs    | `member_orgs`                | `--member-orgs`   | `member_orgs`   | `vars.GHS_MEMBER_ORGS`        |
| Ignored logins | `ignore_logins`              | `--ignore-logins` | `ignore_logins` | `vars.GHS_IGNORE_LOGINS`      |

<!-- markdownlint-enable MD013 -->

A level that sets a key replaces that key's list from the levels
below it. Precedence, highest first: command line flags and the action
inputs that become them; `targets[].identities` for that target;
top-level `identities`; the built-in defaults, which are empty lists
and `member_orgs` equal to the target owner.

## Running locally

[uv](https://docs.astral.sh/uv/) runs a published release without
installing it:

```bash
export GITHUB_TOKEN="$(gh auth token)"
uvx github-statistics run --repo lfreleng-actions/github-statistics-action \
  --budget 200 --output-dir site
uvx github-statistics scope --org lfreleng-actions --format csv
```

Open `site/index.html` in a browser to view the result.

## Development

The project uses [uv](https://docs.astral.sh/uv/) and needs Python
3.11 or later. Install the locked dependencies and run the tests:

```bash
uv sync
uv run pytest
uv run github-statistics --version
```

Install the commit hooks with [prek](https://prek.j178.dev/), then
run them against the files a change touches:

```bash
prek install -t pre-commit -t commit-msg
prek run --files <files>
```

CI runs `build-test.yaml` on pull requests, and `build-test-release.yaml`
builds, tests and publishes to TestPyPI then PyPI on a tag push.
