gitrings 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gitrings-0.1.0/.github/workflows/ci.yml +19 -0
- gitrings-0.1.0/.github/workflows/release.yml +18 -0
- gitrings-0.1.0/.gitignore +8 -0
- gitrings-0.1.0/LICENSE +21 -0
- gitrings-0.1.0/PKG-INFO +84 -0
- gitrings-0.1.0/README.md +73 -0
- gitrings-0.1.0/action.yml +39 -0
- gitrings-0.1.0/pyproject.toml +39 -0
- gitrings-0.1.0/src/gitrings/__init__.py +0 -0
- gitrings-0.1.0/src/gitrings/cli.py +57 -0
- gitrings-0.1.0/src/gitrings/github.py +145 -0
- gitrings-0.1.0/src/gitrings/gitlab.py +30 -0
- gitrings-0.1.0/src/gitrings/rings.py +67 -0
- gitrings-0.1.0/src/gitrings/story.html +1338 -0
- gitrings-0.1.0/src/gitrings/story.py +85 -0
- gitrings-0.1.0/src/gitrings/svg.py +147 -0
- gitrings-0.1.0/tests/test_rings.py +71 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: ci
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
check:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: astral-sh/setup-uv@v6
|
|
14
|
+
- run: uv sync
|
|
15
|
+
- run: uv run ruff check
|
|
16
|
+
- run: uv run ruff format --check
|
|
17
|
+
- run: uv run mypy src tests
|
|
18
|
+
- run: uv run lint-imports
|
|
19
|
+
- run: uv run pytest
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
name: release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ["v*"]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
pypi:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
environment: pypi
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
id-token: write
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: astral-sh/setup-uv@v6
|
|
17
|
+
- run: uv build
|
|
18
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
gitrings-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cengizhan Demir
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
gitrings-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: gitrings
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Your GitHub years as tree rings: counted honestly, private work included, nothing leaked.
|
|
5
|
+
Project-URL: Repository, https://github.com/cengizhandemiir/gitrings
|
|
6
|
+
Author: Cengizhan Demir
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Python: >=3.12
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# gitrings
|
|
13
|
+
|
|
14
|
+
Your GitHub years as tree rings: counted honestly, private work included, nothing leaked.
|
|
15
|
+
|
|
16
|
+
## How to read the rings
|
|
17
|
+
|
|
18
|
+
| In a tree | In gitrings |
|
|
19
|
+
|---|---|
|
|
20
|
+
| The pith at the centre | The year you joined GitHub |
|
|
21
|
+
| One growth ring per year | One ring per calendar year |
|
|
22
|
+
| A wide ring is a good growing season | Ring width grows with that year's contributions, square-root scaled so one huge year does not flatten the rest |
|
|
23
|
+
| An uneven ring edge | Busy weeks push the ring outward, quiet weeks keep it thin. The edge is your year's daily rhythm, clockwise from January at 12 o'clock |
|
|
24
|
+
| Earlywood and latewood bands | Fine grain lines fill each ring, more of them in a wider year |
|
|
25
|
+
| Bark | The outermost ring, in the accent colour, is the current year, still growing: the days ahead stay thin until they happen |
|
|
26
|
+
|
|
27
|
+
## Why
|
|
28
|
+
|
|
29
|
+
Hosted "wrapped" sites add up the whole contribution calendar and call it commits, miss private work, and keep serving stale cached zeros. gitrings runs with your own token, on your machine or your own Actions runner. The image only ever contains daily counts and yearly totals, never repository, organisation or branch names.
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install gitrings
|
|
35
|
+
gitrings <login> --theme dark --out rings.svg --story year.html
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The card draws itself ring by ring when the README loads, and holds still for readers who ask for reduced motion.
|
|
39
|
+
|
|
40
|
+
`--vs <login>` also writes `rings-vs-<login>.svg`: your tree next to someone else's, both on one scale, so the busier history draws the wider trunk. The other tree shows only what GitHub makes public for that account.
|
|
41
|
+
|
|
42
|
+
`--forest <login> [<login> ...]` also writes `rings-forest.svg`: your tree and theirs on that same shared scale, four to a row, for a team page or a team README. Put `--forest` after your own login. Each account costs one GitHub request for every three years it has existed, so a team of five long-time users takes under a minute.
|
|
43
|
+
|
|
44
|
+
`--gitlab <user>` adds that GitLab account's events to the same rings, day by day, counted the way GitLab's own calendar counts them. GitLab deletes events older than three years, so older rings stay GitHub-only. `GITLAB_URL` points at a self-managed instance (default `https://gitlab.com`), and `GITLAB_TOKEN`, a token with `read_user`, counts private projects too; without it GitLab shows only public events, and GitLab.com blocks anonymous requests from an IP address for an hour after a few dozen.
|
|
45
|
+
|
|
46
|
+
`--story` also writes `year.html`, a tap-through story of the current year: your ring, its size class, the month and weekday it grew most, its shape, your longest run, what it is made of and which languages fed it, ending in a card studio: four layouts (Trunk, Bento, Headline and a 1600×900 Wide one) in five colourways, saved, copied or shared as a PNG, plus the workflow and the snippet that keep the animated card in your profile README. The soundtrack starts off; the sound button cycles through three moods (Forest, Lofi, Pulse), all generated in the browser with the Web Audio API, and in each the melody follows your weekly contribution counts, so there is nothing to download or license. The page holds the same daily counts and totals as the card, plus language names and your avatar URL; it loads fonts from Fontshare and Bunny Fonts and icons from unpkg.
|
|
47
|
+
|
|
48
|
+
The token comes from `GITHUB_TOKEN`, or from `gh auth token` when that is unset. For private contributions to be counted in detail, a classic token needs the `repo` and `user` scopes; without the user scope GitHub reports private work only as an anonymous total.
|
|
49
|
+
|
|
50
|
+
`gitrings --doctor` checks what keeps work out of the rings: whether the token has `repo` and `read:user`, whether an organisation's SAML SSO is still waiting for the token to be authorised, and whether `git config user.email` is a verified email on your account (GitHub only counts commits from those; the check needs `user:email`). It prints `ok` or `fix` per line and exits 1 if anything needs fixing.
|
|
51
|
+
|
|
52
|
+
### Daily card in your profile README
|
|
53
|
+
|
|
54
|
+
Save this as `.github/workflows/gitrings.yml` in your profile repository (`<login>/<login>`):
|
|
55
|
+
|
|
56
|
+
```yaml
|
|
57
|
+
name: gitrings
|
|
58
|
+
on:
|
|
59
|
+
schedule:
|
|
60
|
+
- cron: '17 4 * * *'
|
|
61
|
+
workflow_dispatch:
|
|
62
|
+
permissions:
|
|
63
|
+
contents: write
|
|
64
|
+
jobs:
|
|
65
|
+
rings:
|
|
66
|
+
runs-on: ubuntu-latest
|
|
67
|
+
steps:
|
|
68
|
+
- uses: cengizhandemiir/gitrings@main
|
|
69
|
+
with:
|
|
70
|
+
token: ${{ secrets.GITRINGS_TOKEN }}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Every day it draws `gitrings.svg` and `gitrings-dark.svg` and force-pushes them as the only commit on a `gitrings` branch, so the repository does not grow. Without a `GITRINGS_TOKEN` secret it reads with the workflow's own token, which counts what your public profile shows: private work too, as daily counts, when "Private contributions" is on in your profile settings. With that setting off, a classic token with `repo` and `read:user` as the secret still counts it. Inputs: `login` (default: the repository owner), `token`, `branch` (default: `gitrings`). Then put the card in your README, dark or light to match the reader:
|
|
74
|
+
|
|
75
|
+
```html
|
|
76
|
+
<picture>
|
|
77
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/<login>/<login>/gitrings/gitrings-dark.svg">
|
|
78
|
+
<img alt="@<login>'s GitHub years as tree rings" src="https://raw.githubusercontent.com/<login>/<login>/gitrings/gitrings.svg">
|
|
79
|
+
</picture>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
MIT
|
gitrings-0.1.0/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# gitrings
|
|
2
|
+
|
|
3
|
+
Your GitHub years as tree rings: counted honestly, private work included, nothing leaked.
|
|
4
|
+
|
|
5
|
+
## How to read the rings
|
|
6
|
+
|
|
7
|
+
| In a tree | In gitrings |
|
|
8
|
+
|---|---|
|
|
9
|
+
| The pith at the centre | The year you joined GitHub |
|
|
10
|
+
| One growth ring per year | One ring per calendar year |
|
|
11
|
+
| A wide ring is a good growing season | Ring width grows with that year's contributions, square-root scaled so one huge year does not flatten the rest |
|
|
12
|
+
| An uneven ring edge | Busy weeks push the ring outward, quiet weeks keep it thin. The edge is your year's daily rhythm, clockwise from January at 12 o'clock |
|
|
13
|
+
| Earlywood and latewood bands | Fine grain lines fill each ring, more of them in a wider year |
|
|
14
|
+
| Bark | The outermost ring, in the accent colour, is the current year, still growing: the days ahead stay thin until they happen |
|
|
15
|
+
|
|
16
|
+
## Why
|
|
17
|
+
|
|
18
|
+
Hosted "wrapped" sites add up the whole contribution calendar and call it commits, miss private work, and keep serving stale cached zeros. gitrings runs with your own token, on your machine or your own Actions runner. The image only ever contains daily counts and yearly totals, never repository, organisation or branch names.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install gitrings
|
|
24
|
+
gitrings <login> --theme dark --out rings.svg --story year.html
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The card draws itself ring by ring when the README loads, and holds still for readers who ask for reduced motion.
|
|
28
|
+
|
|
29
|
+
`--vs <login>` also writes `rings-vs-<login>.svg`: your tree next to someone else's, both on one scale, so the busier history draws the wider trunk. The other tree shows only what GitHub makes public for that account.
|
|
30
|
+
|
|
31
|
+
`--forest <login> [<login> ...]` also writes `rings-forest.svg`: your tree and theirs on that same shared scale, four to a row, for a team page or a team README. Put `--forest` after your own login. Each account costs one GitHub request for every three years it has existed, so a team of five long-time users takes under a minute.
|
|
32
|
+
|
|
33
|
+
`--gitlab <user>` adds that GitLab account's events to the same rings, day by day, counted the way GitLab's own calendar counts them. GitLab deletes events older than three years, so older rings stay GitHub-only. `GITLAB_URL` points at a self-managed instance (default `https://gitlab.com`), and `GITLAB_TOKEN`, a token with `read_user`, counts private projects too; without it GitLab shows only public events, and GitLab.com blocks anonymous requests from an IP address for an hour after a few dozen.
|
|
34
|
+
|
|
35
|
+
`--story` also writes `year.html`, a tap-through story of the current year: your ring, its size class, the month and weekday it grew most, its shape, your longest run, what it is made of and which languages fed it, ending in a card studio: four layouts (Trunk, Bento, Headline and a 1600×900 Wide one) in five colourways, saved, copied or shared as a PNG, plus the workflow and the snippet that keep the animated card in your profile README. The soundtrack starts off; the sound button cycles through three moods (Forest, Lofi, Pulse), all generated in the browser with the Web Audio API, and in each the melody follows your weekly contribution counts, so there is nothing to download or license. The page holds the same daily counts and totals as the card, plus language names and your avatar URL; it loads fonts from Fontshare and Bunny Fonts and icons from unpkg.
|
|
36
|
+
|
|
37
|
+
The token comes from `GITHUB_TOKEN`, or from `gh auth token` when that is unset. For private contributions to be counted in detail, a classic token needs the `repo` and `user` scopes; without the user scope GitHub reports private work only as an anonymous total.
|
|
38
|
+
|
|
39
|
+
`gitrings --doctor` checks what keeps work out of the rings: whether the token has `repo` and `read:user`, whether an organisation's SAML SSO is still waiting for the token to be authorised, and whether `git config user.email` is a verified email on your account (GitHub only counts commits from those; the check needs `user:email`). It prints `ok` or `fix` per line and exits 1 if anything needs fixing.
|
|
40
|
+
|
|
41
|
+
### Daily card in your profile README
|
|
42
|
+
|
|
43
|
+
Save this as `.github/workflows/gitrings.yml` in your profile repository (`<login>/<login>`):
|
|
44
|
+
|
|
45
|
+
```yaml
|
|
46
|
+
name: gitrings
|
|
47
|
+
on:
|
|
48
|
+
schedule:
|
|
49
|
+
- cron: '17 4 * * *'
|
|
50
|
+
workflow_dispatch:
|
|
51
|
+
permissions:
|
|
52
|
+
contents: write
|
|
53
|
+
jobs:
|
|
54
|
+
rings:
|
|
55
|
+
runs-on: ubuntu-latest
|
|
56
|
+
steps:
|
|
57
|
+
- uses: cengizhandemiir/gitrings@main
|
|
58
|
+
with:
|
|
59
|
+
token: ${{ secrets.GITRINGS_TOKEN }}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Every day it draws `gitrings.svg` and `gitrings-dark.svg` and force-pushes them as the only commit on a `gitrings` branch, so the repository does not grow. Without a `GITRINGS_TOKEN` secret it reads with the workflow's own token, which counts what your public profile shows: private work too, as daily counts, when "Private contributions" is on in your profile settings. With that setting off, a classic token with `repo` and `read:user` as the secret still counts it. Inputs: `login` (default: the repository owner), `token`, `branch` (default: `gitrings`). Then put the card in your README, dark or light to match the reader:
|
|
63
|
+
|
|
64
|
+
```html
|
|
65
|
+
<picture>
|
|
66
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/<login>/<login>/gitrings/gitrings-dark.svg">
|
|
67
|
+
<img alt="@<login>'s GitHub years as tree rings" src="https://raw.githubusercontent.com/<login>/<login>/gitrings/gitrings.svg">
|
|
68
|
+
</picture>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
MIT
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
name: gitrings
|
|
2
|
+
description: Redraw your GitHub years as tree rings every day, on a side branch your README links to.
|
|
3
|
+
branding:
|
|
4
|
+
icon: disc
|
|
5
|
+
color: green
|
|
6
|
+
inputs:
|
|
7
|
+
login:
|
|
8
|
+
description: Whose rings to draw.
|
|
9
|
+
default: ${{ github.repository_owner }}
|
|
10
|
+
token:
|
|
11
|
+
description: Token that reads the contributions. Empty uses the workflow token, which counts private work only when your profile shows private contributions; a classic token with repo and read:user always counts it.
|
|
12
|
+
default: ""
|
|
13
|
+
branch:
|
|
14
|
+
description: Branch the cards are pushed to. Its history is replaced on every run.
|
|
15
|
+
default: gitrings
|
|
16
|
+
runs:
|
|
17
|
+
using: composite
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/setup-python@v7
|
|
20
|
+
with:
|
|
21
|
+
python-version: "3.12"
|
|
22
|
+
- shell: bash
|
|
23
|
+
run: pip install --quiet "$GITHUB_ACTION_PATH"
|
|
24
|
+
- shell: bash
|
|
25
|
+
env:
|
|
26
|
+
LOGIN: ${{ inputs.login }}
|
|
27
|
+
GITHUB_TOKEN: ${{ inputs.token || github.token }}
|
|
28
|
+
BRANCH: ${{ inputs.branch }}
|
|
29
|
+
PUSH_TOKEN: ${{ github.token }}
|
|
30
|
+
run: |
|
|
31
|
+
cd "$(mktemp -d)"
|
|
32
|
+
gitrings "$LOGIN" --theme light --out gitrings.svg
|
|
33
|
+
gitrings "$LOGIN" --theme dark --out gitrings-dark.svg
|
|
34
|
+
git init --quiet --initial-branch "$BRANCH"
|
|
35
|
+
git add gitrings.svg gitrings-dark.svg
|
|
36
|
+
git -c user.name="github-actions[bot]" \
|
|
37
|
+
-c user.email="41898282+github-actions[bot]@users.noreply.github.com" \
|
|
38
|
+
commit --quiet --message "Redraw gitrings"
|
|
39
|
+
git push --quiet --force "https://x-access-token:$PUSH_TOKEN@github.com/$GITHUB_REPOSITORY.git" "HEAD:$BRANCH"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "gitrings"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Your GitHub years as tree rings: counted honestly, private work included, nothing leaked."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
authors = [{ name = "Cengizhan Demir" }]
|
|
9
|
+
dependencies = []
|
|
10
|
+
|
|
11
|
+
[project.urls]
|
|
12
|
+
Repository = "https://github.com/cengizhandemiir/gitrings"
|
|
13
|
+
|
|
14
|
+
[project.scripts]
|
|
15
|
+
gitrings = "gitrings.cli:main"
|
|
16
|
+
|
|
17
|
+
[dependency-groups]
|
|
18
|
+
dev = ["ruff", "mypy", "pytest", "import-linter"]
|
|
19
|
+
|
|
20
|
+
[build-system]
|
|
21
|
+
requires = ["hatchling"]
|
|
22
|
+
build-backend = "hatchling.build"
|
|
23
|
+
|
|
24
|
+
[tool.ruff]
|
|
25
|
+
line-length = 100
|
|
26
|
+
|
|
27
|
+
[tool.ruff.lint]
|
|
28
|
+
select = ["E", "F", "I", "UP", "B", "SIM"]
|
|
29
|
+
|
|
30
|
+
[tool.mypy]
|
|
31
|
+
strict = true
|
|
32
|
+
|
|
33
|
+
[tool.importlinter]
|
|
34
|
+
root_package = "gitrings"
|
|
35
|
+
|
|
36
|
+
[[tool.importlinter.contracts]]
|
|
37
|
+
name = "Renderer and GitHub client never import each other"
|
|
38
|
+
type = "layers"
|
|
39
|
+
layers = ["gitrings.cli", "gitrings.svg | gitrings.story | gitrings.github | gitrings.gitlab", "gitrings.rings"]
|
|
File without changes
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import os
|
|
3
|
+
import subprocess
|
|
4
|
+
from datetime import date
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from gitrings import gitlab, story, svg
|
|
8
|
+
from gitrings.github import checkup, fetch
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main() -> None:
|
|
12
|
+
parser = argparse.ArgumentParser(
|
|
13
|
+
prog="gitrings", description="Draw your GitHub years as tree rings."
|
|
14
|
+
)
|
|
15
|
+
parser.add_argument("login", nargs="?")
|
|
16
|
+
parser.add_argument("--theme", choices=sorted(svg.THEMES), default="light")
|
|
17
|
+
parser.add_argument("--out", type=Path, default=Path("gitrings.svg"))
|
|
18
|
+
parser.add_argument("--story", type=Path, help="also write the animated year story")
|
|
19
|
+
parser.add_argument("--vs", metavar="LOGIN", help="also draw your rings next to LOGIN's")
|
|
20
|
+
parser.add_argument("--forest", nargs="+", metavar="LOGIN", help="also draw your team's forest")
|
|
21
|
+
parser.add_argument("--gitlab", metavar="USER", help="also count USER's GitLab events")
|
|
22
|
+
parser.add_argument("--doctor", action="store_true", help="check token, SSO and git email")
|
|
23
|
+
args = parser.parse_args()
|
|
24
|
+
if not (args.login or args.doctor):
|
|
25
|
+
parser.error("the following arguments are required: login")
|
|
26
|
+
token = (
|
|
27
|
+
os.environ.get("GITHUB_TOKEN")
|
|
28
|
+
or subprocess.run(
|
|
29
|
+
["gh", "auth", "token"], capture_output=True, text=True, check=True
|
|
30
|
+
).stdout.strip()
|
|
31
|
+
)
|
|
32
|
+
if args.doctor:
|
|
33
|
+
git = subprocess.run(["git", "config", "user.email"], capture_output=True, text=True)
|
|
34
|
+
findings = checkup(token, git.stdout.strip())
|
|
35
|
+
for ok, finding in findings:
|
|
36
|
+
print("ok " if ok else "fix", finding)
|
|
37
|
+
raise SystemExit(0 if all(ok for ok, _ in findings) else 1)
|
|
38
|
+
profile, rings = fetch(args.login, token, date.today())
|
|
39
|
+
if args.gitlab:
|
|
40
|
+
lab = os.environ.get("GITLAB_URL", "https://gitlab.com")
|
|
41
|
+
rings = gitlab.add(rings, args.gitlab, os.environ.get("GITLAB_TOKEN", ""), lab)
|
|
42
|
+
args.out.write_text(svg.render(args.login, rings, args.theme))
|
|
43
|
+
print(f"{args.out}: {len(rings)} rings")
|
|
44
|
+
if args.story:
|
|
45
|
+
args.story.write_text(story.render(profile, rings))
|
|
46
|
+
print(f"{args.story}: {rings[-1].year} story")
|
|
47
|
+
if args.vs:
|
|
48
|
+
_, other = fetch(args.vs, token, date.today())
|
|
49
|
+
pair = args.out.with_stem(f"{args.out.stem}-vs-{args.vs}")
|
|
50
|
+
pair.write_text(svg.forest([(args.login, rings), (args.vs, other)], args.theme))
|
|
51
|
+
print(f"{pair}: {args.login} vs {args.vs}")
|
|
52
|
+
if args.forest:
|
|
53
|
+
trees = [(args.login, rings)]
|
|
54
|
+
trees += [(login, fetch(login, token, date.today())[1]) for login in args.forest]
|
|
55
|
+
grove = args.out.with_stem(f"{args.out.stem}-forest")
|
|
56
|
+
grove.write_text(svg.forest(trees, args.theme))
|
|
57
|
+
print(f"{grove}: {len(trees)} trees")
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import urllib.error
|
|
3
|
+
import urllib.request
|
|
4
|
+
from datetime import date
|
|
5
|
+
from email.message import Message
|
|
6
|
+
from itertools import batched
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from gitrings.rings import Profile, Ring
|
|
10
|
+
|
|
11
|
+
API = "https://api.github.com/graphql"
|
|
12
|
+
REST = "https://api.github.com"
|
|
13
|
+
PROFILE = """
|
|
14
|
+
query($login: String!, $from: DateTime!, $to: DateTime!) {
|
|
15
|
+
user(login: $login) {
|
|
16
|
+
createdAt name avatarUrl
|
|
17
|
+
contributionsCollection(from: $from, to: $to) {
|
|
18
|
+
totalCommitContributions totalPullRequestContributions
|
|
19
|
+
totalPullRequestReviewContributions totalIssueContributions
|
|
20
|
+
totalRepositoryContributions restrictedContributionsCount
|
|
21
|
+
commitContributionsByRepository(maxRepositories: 100) {
|
|
22
|
+
contributions { totalCount }
|
|
23
|
+
repository { isPrivate primaryLanguage { name color } }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
"""
|
|
29
|
+
CALENDAR = """
|
|
30
|
+
y{end.year}: contributionsCollection(from: "{end.year}-01-01T00:00:00Z", to: "{end}T23:59:59Z") {{
|
|
31
|
+
contributionCalendar {{ weeks {{ contributionDays {{ date contributionCount }} }} }}
|
|
32
|
+
}}
|
|
33
|
+
"""
|
|
34
|
+
KINDS = {
|
|
35
|
+
"commits": "totalCommitContributions",
|
|
36
|
+
"pullRequests": "totalPullRequestContributions",
|
|
37
|
+
"reviews": "totalPullRequestReviewContributions",
|
|
38
|
+
"issues": "totalIssueContributions",
|
|
39
|
+
"repositories": "totalRepositoryContributions",
|
|
40
|
+
"restricted": "restrictedContributionsCount",
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _query(token: str, query: str, variables: dict[str, str]) -> Any:
|
|
45
|
+
request = urllib.request.Request(
|
|
46
|
+
API,
|
|
47
|
+
data=json.dumps({"query": query, "variables": variables}).encode(),
|
|
48
|
+
headers={"Authorization": f"bearer {token}", "User-Agent": "gitrings"},
|
|
49
|
+
)
|
|
50
|
+
with urllib.request.urlopen(request) as response:
|
|
51
|
+
body = json.load(response)
|
|
52
|
+
if "errors" in body:
|
|
53
|
+
raise RuntimeError(body["errors"])
|
|
54
|
+
return body["data"]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _window(login: str, year: int, end: date) -> dict[str, str]:
|
|
58
|
+
return {"login": login, "from": f"{year}-01-01T00:00:00Z", "to": f"{end}T23:59:59Z"}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def fetch(login: str, token: str, today: date) -> tuple[Profile, list[Ring]]:
|
|
62
|
+
user = _query(token, PROFILE, _window(login, today.year, today))["user"]
|
|
63
|
+
collection = user["contributionsCollection"]
|
|
64
|
+
languages: dict[str, tuple[str, int]] = {}
|
|
65
|
+
private = 0
|
|
66
|
+
for entry in collection["commitContributionsByRepository"]:
|
|
67
|
+
count = entry["contributions"]["totalCount"]
|
|
68
|
+
private += count if entry["repository"]["isPrivate"] else 0
|
|
69
|
+
language = entry["repository"]["primaryLanguage"]
|
|
70
|
+
if language:
|
|
71
|
+
color, total = languages.get(language["name"], (language["color"] or "#888888", 0))
|
|
72
|
+
languages[language["name"]] = (color, total + count)
|
|
73
|
+
profile = Profile(
|
|
74
|
+
login=login,
|
|
75
|
+
name=user["name"] or login,
|
|
76
|
+
avatar=user["avatarUrl"],
|
|
77
|
+
kinds={kind: collection[field] for kind, field in KINDS.items()},
|
|
78
|
+
languages=sorted(
|
|
79
|
+
((name, color, total) for name, (color, total) in languages.items()),
|
|
80
|
+
key=lambda language: -language[2],
|
|
81
|
+
),
|
|
82
|
+
private_commits=private,
|
|
83
|
+
)
|
|
84
|
+
ends = [
|
|
85
|
+
min(today, date(year, 12, 31)) for year in range(int(user["createdAt"][:4]), today.year + 1)
|
|
86
|
+
]
|
|
87
|
+
calendars: dict[str, Any] = {}
|
|
88
|
+
for chunk in batched(ends, 3):
|
|
89
|
+
fields = "".join(CALENDAR.format(end=end) for end in chunk)
|
|
90
|
+
query = f"query($login: String!) {{ user(login: $login) {{ {fields} }} }}"
|
|
91
|
+
calendars |= _query(token, query, {"login": login})["user"]
|
|
92
|
+
rings = []
|
|
93
|
+
for end in ends:
|
|
94
|
+
weeks = calendars[f"y{end.year}"]["contributionCalendar"]["weeks"]
|
|
95
|
+
days = tuple(
|
|
96
|
+
day["contributionCount"]
|
|
97
|
+
for week in weeks
|
|
98
|
+
for day in week["contributionDays"]
|
|
99
|
+
if day["date"].startswith(str(end.year)) and day["date"] <= end.isoformat()
|
|
100
|
+
)
|
|
101
|
+
rings.append(Ring(end.year, days))
|
|
102
|
+
return profile, rings
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _get(token: str, path: str) -> tuple[Any, Message]:
|
|
106
|
+
request = urllib.request.Request(
|
|
107
|
+
REST + path, headers={"Authorization": f"bearer {token}", "User-Agent": "gitrings"}
|
|
108
|
+
)
|
|
109
|
+
with urllib.request.urlopen(request) as response:
|
|
110
|
+
return json.load(response), response.headers
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def checkup(token: str, git_email: str) -> list[tuple[bool, str]]:
|
|
114
|
+
"""What keeps work out of the rings: token scopes, SSO authorisation, the git commit email."""
|
|
115
|
+
listed = _get(token, "/user")[1].get("X-OAuth-Scopes")
|
|
116
|
+
scopes = {scope.strip() for scope in (listed or "").split(",")}
|
|
117
|
+
scopes |= {"read:user"} if "user" in scopes else set()
|
|
118
|
+
missing = " and ".join(sorted({"repo", "read:user"} - scopes))
|
|
119
|
+
if listed is None:
|
|
120
|
+
findings = [(False, "fine-grained and app tokens hide their scopes: use a classic token")]
|
|
121
|
+
elif missing:
|
|
122
|
+
findings = [(False, f"token lacks {missing}: private work counts only as a total")]
|
|
123
|
+
else:
|
|
124
|
+
findings = [(True, "token has repo and read:user")]
|
|
125
|
+
sso = _get(token, "/user/repos?per_page=1")[1].get("X-GitHub-SSO", "")
|
|
126
|
+
if orgs := sso.partition("organizations=")[2]:
|
|
127
|
+
blocked = f"{len(orgs.split(','))} organisation(s)"
|
|
128
|
+
findings.append(
|
|
129
|
+
(False, f"SSO keeps out {blocked}: authorise at https://github.com/settings/tokens")
|
|
130
|
+
)
|
|
131
|
+
else:
|
|
132
|
+
findings.append((True, "no organisation is waiting for SSO authorisation"))
|
|
133
|
+
try:
|
|
134
|
+
emails = _get(token, "/user/emails")[0]
|
|
135
|
+
except urllib.error.HTTPError:
|
|
136
|
+
findings.append((False, "the token needs user:email to check your git email"))
|
|
137
|
+
return findings
|
|
138
|
+
if git_email.lower() in {entry["email"].lower() for entry in emails if entry["verified"]}:
|
|
139
|
+
findings.append((True, f"git commits as {git_email}, a verified email of yours"))
|
|
140
|
+
else:
|
|
141
|
+
unknown = git_email or "(no user.email)"
|
|
142
|
+
findings.append(
|
|
143
|
+
(False, f"commits as {unknown} go uncounted: https://github.com/settings/emails")
|
|
144
|
+
)
|
|
145
|
+
return findings
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import urllib.request
|
|
3
|
+
from collections import Counter
|
|
4
|
+
from datetime import date, timedelta
|
|
5
|
+
|
|
6
|
+
from gitrings.rings import Ring
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def add(rings: list[Ring], user: str, token: str, base: str) -> list[Ring]:
|
|
10
|
+
"""Adds a GitLab user's events per day, counted as GitLab's calendar does; it keeps 3 years."""
|
|
11
|
+
counts: Counter[str] = Counter()
|
|
12
|
+
page = "1"
|
|
13
|
+
while page:
|
|
14
|
+
request = urllib.request.Request(
|
|
15
|
+
f"{base}/api/v4/users/{user}/events?per_page=100&page={page}",
|
|
16
|
+
headers={"User-Agent": "gitrings"} | ({"PRIVATE-TOKEN": token} if token else {}),
|
|
17
|
+
)
|
|
18
|
+
with urllib.request.urlopen(request) as response:
|
|
19
|
+
counts.update(event["created_at"][:10] for event in json.load(response))
|
|
20
|
+
page = response.headers.get("X-Next-Page", "")
|
|
21
|
+
return [
|
|
22
|
+
Ring(
|
|
23
|
+
ring.year,
|
|
24
|
+
tuple(
|
|
25
|
+
count + counts[(date(ring.year, 1, 1) + timedelta(day)).isoformat()]
|
|
26
|
+
for day, count in enumerate(ring.days)
|
|
27
|
+
),
|
|
28
|
+
)
|
|
29
|
+
for ring in rings
|
|
30
|
+
]
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from calendar import isleap
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from math import sqrt
|
|
4
|
+
|
|
5
|
+
SWAY = 0.4
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass(frozen=True)
|
|
9
|
+
class Ring:
|
|
10
|
+
year: int
|
|
11
|
+
days: tuple[int, ...]
|
|
12
|
+
|
|
13
|
+
@property
|
|
14
|
+
def total(self) -> int:
|
|
15
|
+
return sum(self.days)
|
|
16
|
+
|
|
17
|
+
@property
|
|
18
|
+
def length(self) -> int:
|
|
19
|
+
return 366 if isleap(self.year) else 365
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True)
|
|
23
|
+
class Profile:
|
|
24
|
+
login: str
|
|
25
|
+
name: str
|
|
26
|
+
avatar: str
|
|
27
|
+
kinds: dict[str, int]
|
|
28
|
+
languages: list[tuple[str, str, int]]
|
|
29
|
+
private_commits: int
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def widths(rings: list[Ring], span: float, min_width: float) -> list[float]:
|
|
33
|
+
weights = [sqrt(ring.total) for ring in rings]
|
|
34
|
+
spare = span - min_width * len(rings)
|
|
35
|
+
scale = spare / sum(weights) if sum(weights) else 0.0
|
|
36
|
+
return [min_width + weight * scale for weight in weights]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _smooth(values: list[float], window: int) -> list[float]:
|
|
40
|
+
half = window // 2
|
|
41
|
+
size = len(values)
|
|
42
|
+
return [
|
|
43
|
+
sum(values[(i + k) % size] for k in range(-half, half + 1)) / (2 * half + 1)
|
|
44
|
+
for i in range(size)
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def growth(ring: Ring, samples: int) -> list[float]:
|
|
49
|
+
"""Thickness factor per angle, mean 1: busy weeks bulge, quiet weeks and days ahead thin."""
|
|
50
|
+
days = [j * ring.length // samples for j in range(samples)]
|
|
51
|
+
counts = [float(ring.days[day]) if day < len(ring.days) else 0.0 for day in days]
|
|
52
|
+
activity = _smooth(_smooth(counts, 21), 21)
|
|
53
|
+
top = max(activity) or 1.0
|
|
54
|
+
mean = sum(activity) / samples / top
|
|
55
|
+
return [1 + SWAY * (value / top - mean) for value in activity]
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def boundaries(
|
|
59
|
+
rings: list[Ring], pith: float, span: float, min_width: float, samples: int
|
|
60
|
+
) -> list[list[float]]:
|
|
61
|
+
radius = [pith] * samples
|
|
62
|
+
outer = []
|
|
63
|
+
for ring, width in zip(rings, widths(rings, span, min_width), strict=True):
|
|
64
|
+
radius = [r + width * g for r, g in zip(radius, growth(ring, samples), strict=True)]
|
|
65
|
+
outer.append(radius)
|
|
66
|
+
scale = min(1.0, (pith + span) / max(outer[-1]))
|
|
67
|
+
return [[r * scale for r in edge] for edge in outer]
|