93 Commits

Author SHA1 Message Date
Jovial Joe Jayarson
ba3aa17f4e Merge pull request #138 from joe733/workshop
patch: work around pip's secure-install bug; bump version
2023-07-20 06:01:27 +05:30
Jovial Joe Jayarson
9630bc0a2b patch: work around pip's secure-install bug; bump version
- upstream issue: https://github.com/pypa/pip/issues/9644
- runs tests within a container, uses the same `dockerfile`
- ignores `pdm.lock`, removes `requirement.txt`
- update manual contribution steps
- bumps project version

**Related Items**

_Issues_

- Closes #137
2023-07-19 18:12:28 +05:30
Jovial Joe Jayarson
78ac94ef4f Merge pull request #135 from joe733/workshop
feat: flags to tweak commit info; bump version
2023-07-19 08:43:50 +05:30
Jovial Joe Jayarson
a3e45eb050 feat: flags to tweak commit info; bump version
- flags are now available to modify commit information
- adds these flags to `dockerfile` & `action.yml`
- fixes a few typos
- improves `Readme.md`
- updates secondary dependencies
- bumps project version

**Related Items**

_Issues_

- Closes #103
- Closes #104
- Closes #125
2023-07-18 14:01:38 +05:30
Jovial Joe Jayarson
7d29cf150e fix: license format from choosealicense.com 2023-07-18 13:31:35 +05:30
Jovial Joe Jayarson
cefd952b71 Merge pull request #134 from joe733/workshop
chore: monthly updates for July'23
2023-07-18 06:30:40 +05:30
Jovial Joe Jayarson
77ba5f6a96 chore: monthly updates for July'23
- migrate to `pdm` from `poetry`
- update dependencies
- improvises `dockerfile` (drops `containerfile`)
- only `python` & `pip` are required in ci/cd
- adds `compose.yml`
- simplifies local & containerized development
2023-07-17 08:30:12 +05:30
Jovial Joe Jayarson
c34fb893a6 Merge pull request #131 from joe733/workshop
maint: monthly updates for June '23
2023-06-14 17:30:31 +05:30
Jovial Joe Jayarson
1fc26a4121 feat: update dependencies; bump version 2023-06-14 14:13:38 +05:30
Jovial Joe Jayarson
82c9408d6d maint: follows google pydocstyle 2023-06-13 19:40:52 +05:30
Jovial Joe Jayarson
9bee9ba11b maint: migrate to black formatting 2023-06-13 19:17:26 +05:30
Jovial Joe Jayarson
b42a071671 Merge pull request #129 from athul/dependabot/pip/cryptography-41.0.0
chore(deps): bump cryptography from 40.0.2 to 41.0.0
2023-06-03 05:39:40 +05:30
dependabot[bot]
e8541dbe4e chore(deps): bump cryptography from 40.0.2 to 41.0.0
Bumps [cryptography](https://github.com/pyca/cryptography) from 40.0.2 to 41.0.0.
- [Changelog](https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst)
- [Commits](https://github.com/pyca/cryptography/compare/40.0.2...41.0.0)

---
updated-dependencies:
- dependency-name: cryptography
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-02 20:31:09 +00:00
Jisan
da0f4f1847 feat: Add language syntax support for color code (#128)
- feat: text highlight
- fix: wrong env, typo
2023-06-02 11:17:41 +05:30
Jovial Joe Jayarson
d26ed33e7a Merge pull request #124 from athul/dependabot/pip/requests-2.31.0
chore(deps): bump requests from 2.29.0 to 2.31.0
2023-05-23 12:31:51 +05:30
dependabot[bot]
a50019231d chore(deps): bump requests from 2.29.0 to 2.31.0
Bumps [requests](https://github.com/psf/requests) from 2.29.0 to 2.31.0.
- [Release notes](https://github.com/psf/requests/releases)
- [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md)
- [Commits](https://github.com/psf/requests/compare/v2.29.0...v2.31.0)

---
updated-dependencies:
- dependency-name: requests
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-23 06:51:25 +00:00
Jovial Joe Jayarson
080a8c9b63 Merge pull request #122 from joe733/workshop
fix: adds granularity to show more languages
2023-05-05 16:07:45 +05:30
Jovial Joe Jayarson
fbc9196645 fix: adds granularity to show more languages
- adds option `STOP_AT_OTHER` to stop retrieval at lang marked `Other`
- updates dependencies
- makes dev dependencies optional
- bumps project version
- updates readme

**Related Items**

*Issues*

- Closes #121
2023-05-04 17:15:14 +05:30
Jovial Joe Jayarson
59f35b046b Merge pull request #120 from joe733/workshop
feat: bumped version to 0.1.9
2023-03-25 12:52:13 +05:30
Jovial Joe Jayarson
60fa45f3f0 feat: bumped version to 0.1.9
- updates dependencies
- prefer type inference with function return
- fix typos / minor improvements
- ignore all ``*.env` files
- bumped package version to 0.1.9
2023-03-25 10:05:49 +05:30
Jovial Joe Jayarson
60fe3b9f48 Merge pull request #119 from joe733/workshop
fix: adds check to find placeholder in old readme
2023-02-28 12:36:09 +05:30
Jovial Joe Jayarson
29dba6dd79 fix: adds check to find placeholder in old readme 2023-02-27 12:36:25 +05:30
Jovial Joe Jayarson
ac0bb21462 feat: bump version, update deps 2023-02-09 07:25:07 +05:30
Jovial Joe Jayarson
413150be53 Merge pull request #116 from joe733/workshop
fix: adds lang count option properly
2023-02-09 00:29:20 +05:30
Jovial Joe Jayarson
b2db3c3280 fix: adds lang count option properly
- adds language count, thanks @novialriptide
- validates language count input
- adds documentation for lang count
- adds lang count in action.yml
- stricter type checks & changes were made
- formatting changes
- updates dependencies
2023-02-04 17:31:44 +05:30
Jovial Joe Jayarson
6e66f34e5a Merge pull request #115 from novialriptide/add-language-count
Add language_count
2023-02-02 16:52:42 +05:30
Andrew Hong
de673c4749 Add language_count 2023-02-02 01:18:18 -05:00
dependabot[bot]
ce472c9c93 Merge pull request #113 from athul/dependabot/pip/certifi-2022.12.7 2022-12-09 12:49:54 +00:00
dependabot[bot]
8514942821 chore(deps): bump certifi from 2022.9.24 to 2022.12.7
Bumps [certifi](https://github.com/certifi/python-certifi) from 2022.9.24 to 2022.12.7.
- [Release notes](https://github.com/certifi/python-certifi/releases)
- [Commits](https://github.com/certifi/python-certifi/compare/2022.09.24...2022.12.07)

---
updated-dependencies:
- dependency-name: certifi
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-09 09:30:09 +00:00
Jovial Joe Jayarson
d2c91885c3 Merge pull request #111 from joe733/workshop
maint: misc. refactorings, fixes, updates
2022-12-03 07:46:30 +05:30
Jovial Joe Jayarson
bd7707fc5a maint: misc. refactorings, fixes, updates
- puts tests in the correct location of github workflow
- fixes `.env` values not loading via `load_dotenv` - required early loading
- corrects many static type linting errors
- combines all inputs into a single class with validation
- formats markdown & python files, as well as output
- slightly improved log messages, caught potential attribute error
- updates dependencies
2022-12-01 07:41:38 +05:30
Jovial Joe Jayarson
72af24c8af Merge pull request #110 from guilyx/master
Custom section name in user readme
2022-11-28 17:15:18 +05:30
Erwin Lejeune
8ffb95d479 Customizable Section Name 2022-11-28 15:30:28 +04:00
Jovial Joe Jayarson
a80f7247c2 Merge pull request #108 from joe733/workshop
feat: release v0.1.7 🚀
2022-11-24 07:34:37 +05:30
Jovial Joe Jayarson
f106d3b9cc feat: release v0.1.7 🚀
- migrated to python 3.11 & poetry 1.2+
- updated project dependencies & readme
- DockerfileDev is now containerfile
- improve contribution docs
- it includes development with podman
2022-11-22 16:01:02 +05:30
Jovial Joe Jayarson
c2075190e1 Merge pull request #101 from joe733/workshop
feat: updated dockerfile, deps, guide & fix src
2022-09-21 09:30:15 +05:30
Jovial Joe Jayarson
44f2fac0d4 feat: updated dockerfile, deps, guide & fix src
- fix logical error, better non 200 resp message in main.py
- updated dependencies
- major updates to contributing guide
- quicker prod builds with reduced docker layers
- adds dockerfile for development
- updates github action for unit-tests
2022-09-21 09:21:22 +05:30
Jovial Joe Jayarson
3f32dda864 Merge pull request #99 from reekystive/patch-1
Fix API_BASE_URL default value in README
2022-09-13 23:00:18 +05:30
ReekyStive
8ba2186686 Fix API_BASE_URL default value in README 2022-09-13 17:57:17 +08:00
Jovial Joe Jayarson
6a37da6353 Merge pull request #92 from joe733/workshop
maint: attempt to fix repeated HTTP 202
2022-08-15 08:18:18 +05:30
Jovial Joe Jayarson
6c57b99980 maint: attempt to fix repeated HTTP 202
- removes http:// & https:// mount from request session
- removes request session (corrupt cookies might cause trouble)
- uses fake user-agent for each fresh requsts (new depns)
- updt. deps, adds SAST dev deps - bandit
2022-08-12 21:06:41 +05:30
Jovial Joe Jayarson
4451606530 Merge pull request #89 from joe733/workshop
feat: bumped versions, upd. deps
2022-08-07 21:40:37 +05:30
Jovial Joe Jayarson
30c19dde74 feat: bumped versions, upd. deps
- Fix issues with retry while fetching API data
- Made readme more reader friendly
- Some improvements in log messages
- Update project dependencies
2022-08-06 22:55:51 +05:30
Jovial Joe Jayarson
4518aa2e35 Merge pull request #88 from joe733/workshop
feat: adds show-time flag for unclassified langs
2022-08-06 12:44:52 +05:30
Jovial Joe Jayarson
9a92d7a3c8 feat: adds show-time flag for unclassified langs
- Adds hardcoded defaults for envars
- Updates default commit message
- Uses __slots__ for constants
2022-08-06 12:27:53 +05:30
Jovial Joe Jayarson
9704223eb6 Merge pull request #84 from joe733/workshop
maint: update depens, fix misc typos
2022-07-23 12:08:43 +05:30
Jovial Joe Jayarson
8d3bca6e36 maint: update depens, fix misc typos 2022-07-19 21:00:32 +05:30
Athul Cyriac Ajay
b317bba454 Merge pull request #79 from joe733/workshop
YOLO
2022-02-27 16:13:38 +05:30
Jovial Joe Jayarson
9915bc091b fix: runs in dkrfile & tstng.yml, md fmt err, rm distutils, time delay 2022-02-27 16:01:33 +05:30
Jovial Joe Jayarson
88979b6b3c feat: bye travis, hi gh actn, hndl empty resp, tip in readme 2022-02-26 12:32:16 +05:30
Jovial Joe Jayarson
ec7c2a0b9c fix: updates readme, add contib steps, py version in travis ci 2022-02-25 22:00:51 +05:30
Jovial Joe Jayarson
9486a673b8 fix: update tests, lists known issues, sep data & logic 2022-02-25 10:09:04 +05:30
Jovial Joe Jayarson
c1064d56ae feat: total refactoring of project, code, depns and workflow 2022-02-25 08:28:04 +05:30
jameshwc
1b31f85a36 Add time range as a parameter (#75)
* Add time range as a parameter

* Update the format of time range title; validate the json from wakatime API

* Update README to introduce TIME_RANGE parameter

Authored by: @jameshwc
2022-02-21 07:28:47 +05:30
Athul Cyriac Ajay
645f70e0c2 Merge pull request #76 from athul/patch_29044e8
chore: Change default of SHOW_TIME to false
2022-02-19 07:43:55 +05:30
Athul Cyriac Ajay
bc6f093055 chore: Change default of SHOW_TIME to false 2022-02-17 08:44:27 +05:30
Jovial Joe Jayarson
2cb70368d3 Merge pull request #74 from declandragon/master
add total time
2022-02-15 23:16:27 +05:30
Jovial Joe Jayarson
29044e8e52 feat: new dev depns, adds total coding time 2022-02-15 23:14:38 +05:30
Jovial Joe Jayarson
c1c945d84e Merge branch 'master' into declandragon/master 2022-02-15 23:01:47 +05:30
dragon
dbc6d0363d add total time 2022-02-13 13:50:49 +08:00
Jovial Joe Jayarson
07e44d1423 fix: imprv grammar, typos, links, images 2022-02-05 10:15:41 +05:30
Jovial Joe Jayarson
2bd9ca56a0 Merge pull request #72 from samr1ddh1/master
updated readme (closes #71)
2022-02-05 10:13:13 +05:30
Samriddhi B
86e8f3cec9 updated screenshot(closes #71) 2022-02-01 21:33:05 +05:30
Samriddhi B
b1d19d0944 updated readme 2022-01-30 20:12:04 +05:30
Athul Cyriac Ajay
10fe464b3f Merge pull request #67 from lucassabreu/feat/hide-time
(feat): option to hide time
2021-10-08 08:47:22 +05:30
Lucas dos Santos Abreu
a4b0e4f26b (fix): default is true
Co-authored-by: Athul Cyriac Ajay <athul8720@gmail.com>
2021-10-06 13:45:07 -03:00
Lucas dos Santos Abreu
6e63c24c52 (fix): token is not required 2021-10-06 13:23:52 -03:00
Lucas dos Santos Abreu
271c8a29af (feat): readme 2021-10-06 13:21:46 -03:00
Lucas dos Santos Abreu
9837d10946 (feat): allow user to hide time
`SHOW_TIME` will increase the size of the graph, and hide the `text`
string with the amount of time.
2021-10-06 13:21:46 -03:00
Jovial Joe Jayarson
da68592788 fix: makes some more linting aprs 2021-10-04 20:25:13 +05:30
Jovial Joe Jayarson
4424eb05d9 Merge pull request #68 from joe733/master
feat: update readme & pipenv dependencies
2021-10-04 20:06:05 +05:30
Jovial Joe Jayarson
6da2f0445f feat: update readme & pipenv dependencies 2021-10-04 20:03:57 +05:30
Jovial Joe Jayarson
98f62d0aa9 Merge pull request #66 from Mimori256/patch-2
fix a typo
2021-08-14 11:03:35 +05:30
Mimori256
d69a99729e Update test_main.py 2021-08-13 15:45:01 +09:00
Jovial Joe Jayarson
1104abbc61 Merge pull request #64 from ryul1206/fix-week-start
Fix #63: The week_start is different from WakaTime
2021-06-23 15:27:38 +05:30
Hong-ryul Jung
4aeea1e94b Fix #63: The week_start is different from WakaTime 2021-06-23 01:44:44 +09:00
Yadong Zhang
30896489cb added guide figure. 2021-05-30 21:34:58 +05:30
Jovial Joe Jayarson
283ed2d09d Merge pull request #61 from Mimori256/master
Fix typos
2021-05-08 11:18:21 +05:30
Mimori256
49dcb5d3d7 Fix typos 2021-05-08 10:13:05 +09:00
Ferdinand Mütsch
65a5365b94 chore: implement minor change requests 2021-04-16 11:32:24 +05:30
Ferdinand Mütsch
49db3cb845 feat: allow to configure api url (resolve #59) 2021-04-16 11:32:24 +05:30
Athul Cyriac Ajay
22a8495563 Add GH Discussions link 2020-12-11 20:23:09 +05:30
Siddharth Chandra
4ae860d6e3 add test_decode_readme, add test_generate_new_readme (#50)
* add test_generate_new_readme

* add test_decode_readme
2020-11-27 13:21:49 +05:30
Yufan You
25201232d8 Fix the graph is incorrect when the length of the blocks is not 4 (#45) 2020-11-16 20:30:01 +05:30
Athul Cyriac Ajay
b822de0992 Update FUNDING.yml 2020-11-02 16:50:30 +05:30
Jovial Joe Jayarson
a6b91c890b Merge pull request #46 from athul/fix-tests
fix: fixes import path
2020-10-19 15:58:04 +05:30
Jovial Joe Jayarson
25316e4f7f fix: tolerates mix of testing commands 2020-10-19 13:34:10 +05:30
Jovial Joe Jayarson
0e61c1620f fix: fixes import path
- Import main from absolute if relative path is not available
- Ignored .vscode/ configs
2020-10-19 12:55:47 +05:30
Jovial Joe Jayarson
8c16fb865f tweak: Added GitHub Socialify 2020-10-15 17:38:16 +05:30
Athul Cyriac Ajay
070586d4f7 Merge pull request #41 from divykj/incremental-dockerfile
Optimize Docker build
2020-09-21 18:59:20 +05:30
Divy Jain
e39d1ac61d optimize Docker build 2020-09-21 13:23:31 +05:30
Athul Cyriac Ajay
501c9d2136 Merge pull request #40 from nelson6e65/patch-2
🐛 Typo in "Extras" doc
2020-09-16 08:54:55 +05:30
Nelson Martell
44d837a362 🐛 Typo in "Extras" doc
Documentation mentions `HEAD_FLAG: true`, but in the code example `SHOW_TITLE: true` is used
2020-09-15 18:57:20 -05:00
21 changed files with 12644 additions and 416 deletions

27
.env.template Executable file
View File

@@ -0,0 +1,27 @@
# Do NOT edit this file, make
# a copy and rename as `.env`
INPUT_GH_TOKEN=
INPUT_WAKATIME_API_KEY=
# meta
INPUT_API_BASE_URL=
INPUT_REPOSITORY=
# content
INPUT_SHOW_TITLE=
INPUT_SECTION_NAME=
INPUT_BLOCKS=
INPUT_CODE_LANG=
INPUT_TIME_RANGE=
INPUT_LANG_COUNT=
INPUT_SHOW_TIME=
INPUT_SHOW_TOTAL=
INPUT_SHOW_MASKED_TIME=
INPUT_STOP_AT_OTHER=
# commit
INPUT_COMMIT_MESSAGE=
INPUT_TARGET_BRANCH=
INPUT_TARGET_PATH=
INPUT_COMMITTER_NAME=
INPUT_COMMITTER_EMAIL=
INPUT_AUTHOR_NAME=
INPUT_AUTHOR_EMAIL=

2
.github/FUNDING.yml vendored
View File

@@ -1,4 +1,4 @@
# These are supported funding model platforms
ko_fi: athulcyriac
custom: https://www.buymeacoffee.com/JeVlc7T
custom: https://www.buymeacoffee.com/athulca

24
.github/workflows/testing.yml vendored Normal file
View File

@@ -0,0 +1,24 @@
name: WakaReadme CI
on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:
jobs:
UnitTests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build docker image
run: |
# Clear existing cache
docker builder prune --force
# Build and run container (executes unit tests)
docker compose -p waka-readme -f ./compose.yml up --no-color --pull always --build --force-recreate
# Cleanup
docker compose -p waka-readme -f ./compose.yml down --rmi all

171
.gitignore vendored
View File

@@ -1,2 +1,169 @@
#generated when running the tests
__pycache__/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
poetry.lock
# pdm
# Similar to poetry.lock, it is generally recommended to include pdm.lock in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
# However, this project does not rely on pdm for production.
pdm.lock
.pdm-python
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
*.env
env.sh
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# VSCode
.vscode/
# asdf
.tool-versions
# ruff
.ruff_cache

View File

@@ -1,7 +0,0 @@
language: python
python:
- "3.7"
install:
- pip install -r requirements.txt
script:
- python -m unittest discover

66
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,66 @@
# Contributing
![python_ver](https://img.shields.io/badge/Python-%3E%3D3.11-blue.svg)
> First off, thank you! Please follow along.
**You need to _`fork`_ this repository & _`clone`_ it onto your system.** Inside the cloned folder, create a `.env` file with the following contents (without `# comments`):
```ini
INPUT_GH_TOKEN=EXAMPLE_GITHUB_PAT # required (for development)
INPUT_WAKATIME_API_KEY=EXAMPLE-WAKATIME-API-KEY # required
INPUT_API_BASE_URL=https://wakatime.com/api # required
INPUT_REPOSITORY=GITHUB_USERNAME/REPOSITORY_NAME # required
INPUT_COMMIT_MESSAGE=Updated WakaReadme graph with new metrics
INPUT_SHOW_TITLE=true
INPUT_SECTION_NAME=waka
INPUT_BLOCKS=->
INPUT_SHOW_TIME=true
INPUT_SHOW_TOTAL=true
INPUT_TIME_RANGE=last_7_days
INPUT_SHOW_MASKED_TIME=false
INPUT_LANG_COUNT=0
INPUT_STOP_AT_OTHER=true
```
**NEVER commit this `.env` file!**
## Using containers (recommended)
> Assumes that you already have latest version of either [`podman`](https://podman.io/) or [`docker`](https://www.docker.com/) (with [`compose`](https://docs.docker.com/compose/)) installed & configured.
>
> Replace `podman` with `docker` everywhere, if you're using the latter.
```sh
# Build
$ podman-compose -p waka-readme -f ./docker-compose.yml up -d
# Logs
$ podman logs WakaReadmeDev
# Cleanup
$ podman-compose -p waka-readme -f ./docker-compose.yml down
```
---
## Using virtual environments
> Assumes you've already installed & configured latest version of [python](https://www.python.org/).
1. Inside the cloned folder run the following commands to install dependencies
```console
$ python -m venv .venv
$ . ./.venv/bin/activate
$ python -m pip install .
```
to activate virtual environment & install dependencies.
2. To test or execute the program in development, run:
```console
(.venv)$ python -m unittest discover # run tests
(.venv)$ python -m main --dev # execute program in dev mode
```
> You can use any other virtual environment & dependency manager as well.

View File

@@ -1,8 +0,0 @@
FROM python:latest
# Install dependencies.
ADD requirements.txt /requirements.txt
ADD main.py /main.py
RUN pip install -r requirements.txt
CMD ["python", "/main.py"]

25
LICENSE
View File

@@ -1,20 +1,21 @@
The MIT License (MIT)
MIT License
Copyright (c) 2020 ATHUL CYRIAC AJAY
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

13
Pipfile
View File

@@ -1,13 +0,0 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
requests = "*"
pygithub = "*"
[requires]
python_version = "3.7"

85
Pipfile.lock generated
View File

@@ -1,85 +0,0 @@
{
"_meta": {
"hash": {
"sha256": "ee0dbc310e64a4cc599d6b5e02bb22e3f33eb97ead8e5f1e315cf355fbef9367"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.7"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"certifi": {
"hashes": [
"sha256:5930595817496dd21bb8dc35dad090f1c2cd0adfaf21204bf6732ca5d8ee34d3",
"sha256:8fc0819f1f30ba15bdb34cceffb9ef04d99f420f68eb75d901e9560b8749fc41"
],
"version": "==2020.6.20"
},
"chardet": {
"hashes": [
"sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae",
"sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"
],
"version": "==3.0.4"
},
"deprecated": {
"hashes": [
"sha256:525ba66fb5f90b07169fdd48b6373c18f1ee12728ca277ca44567a367d9d7f74",
"sha256:a766c1dccb30c5f6eb2b203f87edd1d8588847709c78589e1521d769addc8218"
],
"version": "==1.2.10"
},
"idna": {
"hashes": [
"sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6",
"sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0"
],
"version": "==2.10"
},
"pygithub": {
"hashes": [
"sha256:8375a058ec651cc0774244a3bc7395cf93617298735934cdd59e5bcd9a1df96e",
"sha256:d2d17d1e3f4474e070353f201164685a95b5a92f5ee0897442504e399c7bc249"
],
"index": "pypi",
"version": "==1.51"
},
"pyjwt": {
"hashes": [
"sha256:5c6eca3c2940464d106b99ba83b00c6add741c9becaec087fb7ccdefea71350e",
"sha256:8d59a976fb773f3e6a39c85636357c4f0e242707394cadadd9814f5cbaa20e96"
],
"version": "==1.7.1"
},
"requests": {
"hashes": [
"sha256:b3559a131db72c33ee969480840fff4bb6dd111de7dd27c8ee1f820f4f00231b",
"sha256:fe75cc94a9443b9246fc7049224f75604b113c36acb93f87b80ed42c44cbb898"
],
"index": "pypi",
"version": "==2.24.0"
},
"urllib3": {
"hashes": [
"sha256:3018294ebefce6572a474f0604c2021e33b3fd8006ecd11d62107a5d2a963527",
"sha256:88206b0eb87e6d677d424843ac5209e3fb9d0190d0ee169599165ec25e9d9115"
],
"version": "==1.25.9"
},
"wrapt": {
"hashes": [
"sha256:b62ffa81fb85f4332a4f609cab4ac40709470da05643a082ec1eb88e6d9b97d7"
],
"version": "==1.12.1"
}
},
"develop": {}
}

293
README.md
View File

@@ -1,57 +1,122 @@
# Dev Metrics in Readme [![Build Status](https://travis-ci.com/athul/waka-readme.svg?branch=master)](https://travis-ci.com/athul/waka-readme)
<center>
![waka-readme](https://socialify.git.ci/athul/waka-readme/image?description=1&forks=1&name=1&pulls=1&stargazers=1&theme=Light)
</center>
# Dev Metrics in Readme [![Unit Tests](https://github.com/athul/waka-readme/actions/workflows/testing.yml/badge.svg?branch=master)](https://github.com/athul/waka-readme/actions/workflows/testing.yml) ![Python Version](https://img.shields.io/badge/Python-^3.11-blue)
[WakaTime](https://wakatime.com) weekly metrics on your profile readme.
![Project Preview](https://user-images.githubusercontent.com/8397274/87243943-e6b45c00-c457-11ea-94c9-2aa0bf241be8.png)
---
:speech_balloon: **Forum** | [GitHub discussions][gh_discuss]
[WakaTime](https://wakatime.com) Weekly Metrics on your Profile Readme:
## New to WakaTime?
> Nope? Skip to [prep work](#prep-work).
WakaTime gives you an idea of the time you spent on coding. This helps you boost your productivity and competitive edge.
1. Head over to <https://wakatime.com/> and create an account.
2. After logging in get your WakaTime API Key from <https://wakatime.com/api-key/>.
3. Install [WakaTime plugin][waka_plugins] in your favorite editor / IDE.
4. Paste in your API key to start telemetry.
:information_source: **Info** | You can read [WakaTime help][waka_help] to know more about configurations.
Alternatively, you can also fetch data from WakaTime compatible services like [Wakapi][wakapi] or [Hakatime][hakatime].
## Prep Work
1. You need to update the markdown file(.md) with 2 comments. You can refer [here](#update-your-readme) for updating it.
2. You'll need a WakaTime API Key. You can get that from your WakaTime Account Settings
- You can refer [here](#new-to-wakatime), if you're new to WakaTime
3. **Optional** You'll need a GitHub API Token with `repo` scope from [here](https://github.com/settings/tokens) if you're running the action not in your Profile Repository
- You can use [this](#other-repository-not-profile) example to work it out
4. You need to save the WakaTime API Key (and the GitHub API Token, if you need it) in the repository secrets. You can find that in the Settings of your Repository.Be sure to save those as the following.
- WakaTime-api-key as `WAKATIME_API_KEY = <your wakatime API Key>`and
- The GitHub Access Token as `GH_TOKEN=<your github access token>`
5. You can follow either of the Two Examples according to your needs to get started with.
A GitHub repository and a `README.md` file is required. We'll be making use of readme in the [profile repository][profile_readme].
> I strongly suggest you to run the Action in your Profile Repo since you won't be needing a GitHub Access Token
- Save the `README.md` file after copy-pasting the following special comments. Your dev-metics will show up in between.
This Action will run everyday at 00.00 UTC
```md
<!--START_SECTION:waka-->
<!--END_SECTION:waka-->
```
## Update your Readme
`<!--START_SECTION: -->` and `<!--END_SECTION: -->` are placeholders and must be retained as is. Whereas "`waka`" can be replaced by any alphanumeric string. See [#Tweaks](#tweaks) section for more.
Add a comment to your `README.md` like this:
- Navigate to your repo's `Settings > Secrets` and add a new secret _named_ `WAKATIME_API_KEY` with your API key as it's _value_.
```md
<!--START_SECTION:waka-->
<!--END_SECTION:waka-->
```
> Or use the url <https://github.com/USERNAME/USERNAME/settings/secrets/actions/new> by replacing the `USERNAME` with your own username.
>
> ![new_secrets_actions][new_secrets_actions]
These lines will be our entry-points for the dev metrics.
- If you're not using [profile repository][profile_readme], add another secret _named_ `GH_TOKEN` and insert your [GitHub token][gh_access_token]\* in place of _value_.
## New to WakaTime
- Create a new workflow file (`waka-readme.yml`) inside `.github/workflows/` folder of your repository. You can create it from a template using the _actions tab_ of your repository too.
- Clear any existing contents, add the following lines and save the `waka-readme.yml` workflow file.
WakaTime gives you an idea of the time you really spent on coding. This helps you boost your productivity and competitive edge.
```yml
name: Waka Readme
- Head over to <https://wakatime.com> and create an account.
- Get your WakaTime API Key from your [Account Settings in WakaTime](https://wakatime.com/settings/account).
- Install the [WakaTime plugin](https://wakatime.com/plugins) in your favourite editor / IDE.
- Paste in your API key to start the analysis.
on:
workflow_dispatch: # for manual workflow trigger
schedule:
- cron: "0 0 * * *" # runs at every 12AM UTC
### Profile Repository
jobs:
update-readme:
name: WakaReadme DevMetrics
runs-on: ubuntu-latest
steps:
- uses: athul/waka-readme@master
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
# following flags are required, only if this is not on
# profile readme, remove the leading `#` to use them
#GH_TOKEN: ${{ secrets.GH_TOKEN }}
#REPOSITORY: <gh_username/gh_username>
```
_If you're executing the workflow on your Profile Repository (`<username>/<username>`)_
Refer [#Example](#example) section for a full blown workflow file.
> You wouldn't need an GitHub Access Token since GitHub Actions already makes one for you.
## Tweaks
Please follow the steps below:
There are many flags that you can tweak as you wish!
1. Go to your `<username>/<username>/actions`, hit `New workflow`, `set up a workflow yourself`, delete all the default content github made for you.
2. Copy the following code and paste it to your new workflow you created at step 1:
### Meta Tweaks
| Environment flag | Options (`Default`, `Other`, ...) | Description |
| ---------------- | ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| `API_BASE_URL` | `https://wakatime.com/api`, `https://wakapi.dev/api`, `https://hakatime.mtx-dev.xyz/api` | Use WakaTime compatible services like [Wakapi][wakapi] & [Hakatime][hakatime] |
| `REPOSITORY` | `<gh_username>/<gh_username>`, `<gh_username>/<repo_name>` | Waka-readme stats will appear on the provided repository |
### Content Tweaks
| Environment flag | Options (`Default`, `Other`, ...) | Description |
| ------------------ | ----------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| `SHOW_TITLE` | `false`, `true` | Add title to waka-readme stats blob |
| `SECTION_NAME` | `waka`, any alphanumeric string | The generator will look for section name to fill up the readme. |
| `BLOCKS` | `░▒▓█`, `⣀⣄⣤⣦⣶⣷⣿`, `-#`, `=>`, you can be creative | Ascii art used to build stats graph |
| `CODE_LANG` | `txt`, `python` `ruby` `json` , you can use other languages also | Language syntax based highlighted text |
| `TIME_RANGE` | `last_7_days`, `last_30_days`, `last_6_months`, `last_year`, `all_time` | String representing a dispensation from which stats are aggregated |
| `LANG_COUNT` | `5`, any plausible number | Number of languages to be displayed |
| `SHOW_TIME` | `true`, `false` | Displays the amount of time spent for each language |
| `SHOW_TOTAL` | `false`, `true` | Show total coding time |
| `SHOW_MASKED_TIME` | `false`, `true` | Adds total coding time including unclassified languages (overrides: `SHOW_TOTAL`) |
| `STOP_AT_OTHER` | `false`, `true` | Stop when language marked as `Other` is retrieved (overrides: `LANG_COUNT`) |
### Commit Tweaks
| Environment flag | Options (`Default`, `Other`, ...) |
| ----------------- | -------------------------------------------------------------------- |
| `COMMIT_MESSAGE` | `Updated waka-readme graph with new metrics`, any reasonable message |
| `TARGET_BRANCH` | `NOT_SET`, target branch name |
| `TARGET_PATH` | `NOT_SET`, `/path/to/target/file` |
| `COMMITTER_NAME` | `NOT_SET`, committer name |
| `COMMITTER_EMAIL` | `NOT_SET`, committer email |
| `AUTHOR_NAME` | `NOT_SET`, author name |
| `AUTHOR_EMAIL` | `NOT_SET`, author email |
All of these flags are _optional_.
# Example
**`waka-readme.yml`**
```yml
name: Waka Readme
@@ -64,124 +129,70 @@ on:
jobs:
update-readme:
name: Update this repo's README
name: WakaReadme DevMetrics
runs-on: ubuntu-latest
steps:
- uses: athul/waka-readme@master
with:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
# meta
API_BASE_URL: https://wakatime.com/api
REPOSITORY: athul/athul
# content
SHOW_TITLE: true
SECTION_NAME: waka
BLOCKS: ->
CODE_LANG: all_time
TIME_RANGE: true
LANG_COUNT: 10
SHOW_TIME: true
SHOW_TOTAL: true
SHOW_MASKED_TIME: false
STOP_AT_OTHER: true
# commit
COMMIT_MESSAGE: Updated waka-readme graph with new metrics
TARGET_BRANCH: master
TARGET_PATH: README.md
COMMITTER_NAME: GitHubActionBot
COMMITTER_EMAIL: action-bot@github.org
AUTHOR_NAME: Athul
AUTHOR_EMAIL: athul@example.org
# you can populate email-id with secretes instead
```
3. Go to your repo secrets by hitting `Settings => Secrets` tab in your profile repo. You can also enter the url https://github.com/USERNAME/USERNAME/settings/secrets . Please replace the `USERNAME` with your own username.
4. Create a new `Secret`. `Name`: `WAKATIME_API_KEY`, `Value`: Paste the Wakatime API key here. If you don't know what is the key, please go to [Account Settings in WakaTime](https://wakatime.com/settings/account) to find your API Key there.
5. Add a comment to your `README.md` like this:
> Note:
>
> - Flags `REPOSITORY` and `GH_TOKEN` are required, ONLY if you're NOT using [profile readme][profile_readme].
> - `WAKATIME_API_KEY` is a required secret.
> - Every other environment variables is optional.
> - The above example does not show proper default values, refer [#Tweaks](#tweaks) for the same.
**`README.md`**
```md
<!--START_SECTION:waka-->
<!--END_SECTION:waka-->
From: 10 July 2020 - To: 06 August 2022
Total Time: 1,464 hrs 54 mins
Python 859 hrs 29 mins >>>>>>>>>>>>>>----------- 54.68 %
Markdown 132 hrs 33 mins >>----------------------- 08.43 %
TeX 103 hrs 52 mins >>----------------------- 06.61 %
HTML 94 hrs 48 mins >>----------------------- 06.03 %
Nim 64 hrs 31 mins >------------------------ 04.11 %
Other 47 hrs 58 mins >------------------------ 03.05 %
```
6. Go to Workflows menu (mentioned in step 1), click `Waka Readme`, click `Run workflow`.
7. Go to your profile page. you will be able to see it.
## Why only the language stats (and not other data) from the API?
### Other Repository (not Profile)
I am a fan of minimal designs and the profile readme is a great way to show off your skills and interests. The WakaTime API, gets us a **lot of data** about a person's **coding activity including the editors and Operating Systems you used and the projects you worked on**. Some of these projects maybe secretive and should not be shown out to the public. Using up more data via the Wakatime API will clutter the profile readme and hinder your chances on displaying what you provide **value to the community** like the pinned Repositories. I believe that **Coding Stats is nerdiest of all** since you can tell the community that you are **_exercising these languages or learning a new language_**, this will also show that you spend some amount of time to learn and exercise your development skills. That's what matters in the end :heart:
_If you're executing the workflow on another repo other than `<username>/<username>`_
You'll need to get a [GitHub Access Token](https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token) with a `repo` scope and save it in the Repo Secrets `GH_TOKEN = <Your GitHub Access Token>`
Here is Sample Workflow File for running it:
```yml
name: Waka Readme
on:
schedule:
# Runs at 12am UTC
- cron: "0 0 * * *"
jobs:
update-readme:
name: Update Readme with Metrics
runs-on: ubuntu-latest
steps:
- uses: athul/waka-readme@master
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
REPOSITORY: <username/username> # optional, By default, it will automatically use the repository who's executing the workflow.
```
## Tests
### Running Tests
To run tests simply execute the following in the directory containing main.py:
```python
python -m unittest discover
```
### Contributing Tests
These tests uses the python Unit testing framework, [unittest](https://docs.python.org/3/library/unittest.html)
Since this project is contained all within one file, 'main.py'. You can simply add a function to the TestMain class in tests/test_main.py, similar to the test_graph function.
## Extras
1. If you want to add the week in the Header of your stats, you can add `HEAD_FLAG: true` in your workflow file like this
```yml
- uses: athul/waka-readme@master
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
SHOW_TITLE: true
```
`SHOW_TITLE` flag can be set to true if you want to display the week number and days in the readme, by default it will be false. Here is an example output with `SHOW_TITLE` set to true.
```text
Week: 10 July, 2020 - 17 July, 2020
Python 8 hrs 52 mins ███████████████████░░░░░░ 75.87 %
Go 1 hr 15 mins ██░░░░░░░░░░░░░░░░░░░░░░░ 10.79 %
Markdown 52 mins █░░░░░░░░░░░░░░░░░░░░░░░░ 07.43 %
Docker 16 mins ░░░░░░░░░░░░░░░░░░░░░░░░░ 02.32 %
YAML 7 mins ░░░░░░░░░░░░░░░░░░░░░░░░░ 01.07 %
```
2. You can specify a commit message to override the default _"Updated the Graph with new Metrics"_. Here is how you do it
```yml
- uses: athul/waka-readme@master
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
COMMIT_MESSAGE: Updated the Readme
```
If no commit message is specified in the `yml` file, it defaults to _"Updated the Graph with new Metrics"_
3. You can change the block characters to match with the style of your readme. By default the one show in the graphs before is used. Here is how you do it
```yml
- uses: athul/waka-readme@master
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
BLOCKS: ⣀⣄⣤⣦⣶⣷⣿
```
This will change the graphs to something like this:
```text
Python 8 hrs 52 mins ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣀⣀⣀⣀⣀⣀ 75.87 %
Go 1 hr 15 mins ⣿⣿⣦⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀ 10.79 %
Markdown 52 mins ⣿⣿⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀ 07.43 %
Docker 16 mins ⣤⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀ 02.32 %
YAML 7 mins ⣄⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀ 01.07 %
```
## Why only the language stats and not other data from the API?
I am a fan of minimal designs and the profile readme is a great way to show off your skills and interests. The WakaTime API, gets us a **lot of data** about a person's **coding activity including the editors and Operating Systems you used and the projects you worked on**. Some of these projects maybe secretive and should not be shown out to the public. Using up more data via the Wakatime API will clutter the profile readme and hinder your chances on displaying what you provide **value to the community** like the pinned Repositories. I believe that **Coding Stats is nerdiest of all** since you can tell the community that you are _**exercising these languages or learning a new language**_, this will also show that you spend some amount of time to learn and exercise your development skills. That's what matters in the end :heart:
[//]: #(Links)
[wakapi]: https://wakapi.dev
[hakatime]: https://github.com/mujx/hakatime
[waka_plugins]: https://wakatime.com/plugins
[waka_help]: https://wakatime.com/help/editors
[profile_readme]: https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-profile/customizing-your-profile/managing-your-profile-readme
[new_secrets_actions]: https://user-images.githubusercontent.com/52720626/151221742-bc37d139-2bb3-4554-b27c-46b107d1f408.png
[gh_access_token]: https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token
[gh_discuss]: https://github.com/athul/waka-readme/discussions

View File

@@ -1,40 +1,101 @@
name: "Waka - Readme"
author: Athil Cyriac Ajay
description: "Add a Wakatime Coding Activity graph in your Readme"
author: "Athul Cyriac Ajay"
description: "WakaTime coding activity graph in your profile readme"
inputs:
GH_TOKEN:
description: "GitHub access token with Repo scope"
required: true
default: ${{ github.token }}
required: true
WAKATIME_API_KEY:
description: "Your Wakatime API Key"
description: "Your Wakatime/Wakapi/Hakatime API Key"
required: true
# meta tweaks
API_BASE_URL:
description: "Alternative API base URL when using a third-party WakaTime-ish backend"
default: "https://wakatime.com/api"
required: false
REPOSITORY:
description: "Your GitHub repository"
default: ${{ github.repository }}
required: false
# content tweaks
SHOW_TITLE:
description: "Displays the week number and days in Readme as title"
default: false
default: "false"
required: false
COMMIT_MESSAGE:
description: "Add a commit message of your choice"
default: "Updated the Graph with new Metrics"
SECTION_NAME:
description: "Section name for data to appear in readme"
required: false
default: "waka"
BLOCKS:
description: "Add the progress blocks of your choice"
default: "░▒▓█"
required: false
CODE_LANG:
description: "Add syntax formatter for generated code"
default: "txt"
required: false
TIME_RANGE:
description: "Time range of the queried statistics"
default: "last_7_days"
required: false
LANG_COUNT:
description: "Maximum number of languages to be shown"
default: "5"
required: false
SHOW_TIME:
description: "Displays the amount of time spent for each language"
default: "true"
required: false
SHOW_TOTAL:
description: "Displays total coding time"
default: "false"
required: false
SHOW_MASKED_TIME:
description: "Displays total coding time including unclassified languages"
default: "false"
required: false
STOP_AT_OTHER:
description: "Stop data retrieval when language marked 'Other' is reached"
default: "false"
required: false
# commit tweaks
COMMIT_MESSAGE:
description: "Add a commit message of your choice"
default: "Updated waka-readme graph with new metrics"
required: false
TARGET_BRANCH:
description: "Target branch"
default: "NOT_SET"
required: false
TARGET_PATH:
description: "Target file path"
default: "NOT_SET"
required: false
COMMITTER_NAME:
description: "Committer name"
default: "NOT_SET"
required: false
COMMITTER_EMAIL:
description: "Committer email"
default: "NOT_SET"
required: false
AUTHOR_NAME:
description: "Author name"
default: "NOT_SET"
required: false
AUTHOR_EMAIL:
description: "Author email"
default: "NOT_SET"
required: false
runs:
using: "docker"
image: "Dockerfile"
image: "dockerfile"
branding:
icon: "info"

11
compose.yml Normal file
View File

@@ -0,0 +1,11 @@
# for CI testing
services:
waka-readme:
env_file:
- .env.template
build:
context: .
dockerfile: dockerfile
image: waka-readme:testing
container_name: WakaReadmeTesting
command: python -m unittest discover

9
docker-compose.yml Normal file
View File

@@ -0,0 +1,9 @@
services:
waka-readme:
env_file:
- .env
build:
context: .
dockerfile: dockerfile
image: waka-readme:dev
container_name: WakaReadmeDev

47
dockerfile Normal file
View File

@@ -0,0 +1,47 @@
FROM docker.io/python:3-slim
ENV INPUT_GH_TOKEN \
INPUT_WAKATIME_API_KEY \
# meta
INPUT_API_BASE_URL \
INPUT_REPOSITORY \
# content
INPUT_SHOW_TITLE \
INPUT_SECTION_NAME \
INPUT_BLOCKS \
INPUT_CODE_LANG \
INPUT_TIME_RANGE \
INPUT_LANG_COUNT \
INPUT_SHOW_TIME \
INPUT_SHOW_TOTAL \
INPUT_SHOW_MASKED_TIME \
INPUT_STOP_AT_OTHER \
# commit
INPUT_COMMIT_MESSAGE \
INPUT_TARGET_BRANCH \
INPUT_TARGET_PATH \
INPUT_COMMITTER_NAME \
INPUT_COMMITTER_EMAIL \
INPUT_AUTHOR_NAME \
INPUT_AUTHOR_EMAIL
ENV PATH="${PATH}:/root/.local/bin" \
# python
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PYTHONDONTWRITEBYTECODE=1 \
# pip
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DEFAULT_TIMEOUT=100
# copy project files
COPY --chown=root:root pyproject.toml main.py /app/
# install dependencies
RUN python -m pip install /app/
# execute program
CMD python /app/main.py

587
main.py
View File

@@ -1,107 +1,524 @@
'''
WakaTime progress visualizer
'''
"""WakaReadme : WakaTime progress visualizer.
Wakatime Metrics on your Profile Readme.
Title:
```txt
From: 15 February, 2022 - To: 22 February, 2022
````
Byline:
```txt
Total: 34 hrs 43 mins
```
Body:
```txt
Python 27 hrs 29 mins ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⣀⣀⣀⣀ 77.83 %
YAML 2 hrs 14 mins ⣿⣦⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀ 06.33 %
Markdown 1 hr 54 mins ⣿⣤⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀ 05.39 %
TOML 1 hr 48 mins ⣿⣤⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀ 05.11 %
Other 35 mins ⣦⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀ 01.68 %
```
Contents := Title + Byline + Body
"""
# standard
from dataclasses import dataclass
from random import SystemRandom
from functools import partial
from datetime import datetime
from base64 import b64encode
import logging as logger
from time import sleep
from typing import Any
import sys
import re
import os
import base64
import sys
import datetime
import requests
from github import Github, GithubException
START_COMMENT = '<!--START_SECTION:waka-->'
END_COMMENT = '<!--END_SECTION:waka-->'
listReg = f"{START_COMMENT}[\\s\\S]+{END_COMMENT}"
repository = os.getenv('INPUT_REPOSITORY')
waka_key = os.getenv('INPUT_WAKATIME_API_KEY')
ghtoken = os.getenv('INPUT_GH_TOKEN')
show_title = os.getenv("INPUT_SHOW_TITLE")
commit_message = os.getenv("INPUT_COMMIT_MESSAGE")
blocks = os.getenv("INPUT_BLOCKS")
# external
from github import ContentFile, Github, GithubException, InputGitAuthor, Repository
from requests.exceptions import RequestException
from requests import get as rq_get
from faker import Faker
def this_week() -> str:
'''Returns a week streak'''
week_end = datetime.datetime.today() - datetime.timedelta(days=1)
week_start = week_end - datetime.timedelta(days=7)
print("Week header created")
return f"Week: {week_start.strftime('%d %B, %Y')} - {week_end.strftime('%d %B, %Y')}"
################### setup ###################
def make_graph(percent: float, blocks: str) -> str:
'''Make progress graph from API graph'''
graph = blocks[len(blocks)-1] * int(percent / 4 + 1 / 6)
remainder_block = int((percent + (len(blocks)-2) /
(len(blocks)-1)) % 4 * (len(blocks)-1) / len(blocks))
if remainder_block > 0:
graph += blocks[remainder_block]
graph += blocks[0] * (25 - len(graph))
return graph
print()
# hush existing loggers
for lgr_name in logger.root.manager.loggerDict:
# to disable log propagation completely set '.propagate = False'
logger.getLogger(lgr_name).setLevel(logger.WARNING)
# somehow github.Requester gets missed out from loggerDict
logger.getLogger("github.Requester").setLevel(logger.WARNING)
# configure logger
logger.basicConfig(
datefmt="%Y-%m-%d %H:%M:%S",
format="[%(asctime)s] ln. %(lineno)-3d %(levelname)-8s %(message)s",
level=logger.DEBUG,
)
try:
if len(sys.argv) == 2 and sys.argv[1] == "--dev":
# get env-vars from .env file for development
from dotenv import load_dotenv
# comment this out to disable colored logging
from loguru import logger
# load from .env before class def gets parsed
load_dotenv()
except ImportError as im_err:
logger.warning(im_err)
def get_stats() -> str:
'''Gets API data and returns markdown progress'''
data = requests.get(
f"https://wakatime.com/api/v1/users/current/stats/last_7_days?api_key={waka_key}").json()
################### lib-func ###################
def strtobool(val: str | bool):
"""Strtobool.
PEP 632 https://www.python.org/dev/peps/pep-0632/ is depreciating distutils.
This is from the official source code with slight modifications.
Converts a string representation of truth to `True` or `False`.
Args:
val:
Value to be converted to bool.
Returns:
(Literal[True]):
If `val` is any of 'y', 'yes', 't', 'true', 'on', or '1'.
(Literal[False]):
If `val` is any of 'n', 'no', 'f', 'false', 'off', and '0'.
Raises:
ValueError: If `val` is anything else.
"""
if isinstance(val, bool):
return val
val = val.lower()
if val in {"y", "yes", "t", "true", "on", "1"}:
return True
if val in {"n", "no", "f", "false", "off", "0"}:
return False
raise ValueError(f"invalid truth value for {val}")
################### data ###################
@dataclass(slots=True)
class WakaInput:
"""WakaReadme Input Env Variables."""
# constants
prefix_length: int = 16
graph_length: int = 25
# mapped environment variables
# # required
gh_token: str | None = os.getenv("INPUT_GH_TOKEN")
waka_key: str | None = os.getenv("INPUT_WAKATIME_API_KEY")
api_base_url: str | None = os.getenv("INPUT_API_BASE_URL", "https://wakatime.com/api")
repository: str | None = os.getenv("INPUT_REPOSITORY")
# # depends
commit_message: str = os.getenv(
"INPUT_COMMIT_MESSAGE", "Updated WakaReadme graph with new metrics"
)
code_lang: str = os.getenv("INPUT_CODE_LANG", "txt")
_section_name: str = os.getenv("INPUT_SECTION_NAME", "waka")
start_comment: str = f"<!--START_SECTION:{_section_name}-->"
end_comment: str = f"<!--END_SECTION:{_section_name}-->"
waka_block_pattern: str = f"{start_comment}[\\s\\S]+{end_comment}"
# # optional
show_title: str | bool = os.getenv("INPUT_SHOW_TITLE") or False
block_style: str = os.getenv("INPUT_BLOCKS", "░▒▓█")
time_range: str = os.getenv("INPUT_TIME_RANGE", "last_7_days")
show_time: str | bool = os.getenv("INPUT_SHOW_TIME") or False
show_total_time: str | bool = os.getenv("INPUT_SHOW_TOTAL") or False
show_masked_time: str | bool = os.getenv("INPUT_SHOW_MASKED_TIME") or False
language_count: str | int = os.getenv("INPUT_LANG_COUNT") or 5
stop_at_other: str | bool = os.getenv("INPUT_STOP_AT_OTHER") or False
# # optional meta
target_branch: str = os.getenv("INPUT_TARGET_BRANCH", "NOT_SET")
target_path: str = os.getenv("INPUT_TARGET_PATH", "NOT_SET")
committer_name: str = os.getenv("INPUT_COMMITTER_NAME", "NOT_SET")
committer_email: str = os.getenv("INPUT_COMMITTER_EMAIL", "NOT_SET")
author_name: str = os.getenv("INPUT_AUTHOR_NAME", "NOT_SET")
author_email: str = os.getenv("INPUT_AUTHOR_EMAIL", "NOT_SET")
def validate_input(self):
"""Validate Input Env Variables."""
logger.debug("Validating input variables")
if not self.gh_token or not self.waka_key or not self.api_base_url or not self.repository:
logger.error("Invalid inputs")
logger.info("Refer https://github.com/athul/waka-readme")
return False
if len(self.commit_message) < 1:
logger.error("Commit message length must be greater than 1 character long")
return False
try:
self.show_title = strtobool(self.show_title)
self.show_time = strtobool(self.show_time)
self.show_total_time = strtobool(self.show_total_time)
self.show_masked_time = strtobool(self.show_masked_time)
self.stop_at_other = strtobool(self.stop_at_other)
except (ValueError, AttributeError) as err:
logger.error(err)
return False
if not self._section_name.isalnum():
logger.warning("Section name must be in any of [[a-z][A-Z][0-9]]")
logger.debug("Using default section name: waka")
self._section_name = "waka"
self.start_comment = f"<!--START_SECTION:{self._section_name}-->"
self.end_comment = f"<!--END_SECTION:{self._section_name}-->"
self.waka_block_pattern = f"{self.start_comment}[\\s\\S]+{self.end_comment}"
if len(self.block_style) < 2:
logger.warning("Graph block must be longer than 2 characters")
logger.debug("Using default blocks: ░▒▓█")
self.block_style = "░▒▓█"
if self.time_range not in {
"last_7_days",
"last_30_days",
"last_6_months",
"last_year",
"all_time",
}: # "all_time" is un-documented, should it be used?
logger.warning("Invalid time range")
logger.debug("Using default time range: last_7_days")
self.time_range = "last_7_days"
try:
self.language_count = int(self.language_count)
if self.language_count < -1:
raise ValueError
except ValueError:
logger.warning("Invalid language count")
logger.debug("Using default language count: 5")
self.language_count = 5
for option in (
"target_branch",
"target_path",
"committer_name",
"committer_email",
"author_name",
"author_email",
):
if not getattr(self, option):
logger.warning(f"Improper '{option}' configuration")
logger.debug(f"Using default '{option}'")
setattr(self, option, "NOT_SET")
logger.debug("Input validation complete\n")
return True
################### logic ###################
def make_title(dawn: str | None, dusk: str | None, /):
"""WakaReadme Title.
Makes title for WakaReadme.
"""
logger.debug("Making title")
if not dawn or not dusk:
logger.error("Cannot find start/end date\n")
sys.exit(1)
api_dfm, msg_dfm = "%Y-%m-%dT%H:%M:%SZ", "%d %B %Y"
try:
lang_data = data['data']['languages']
except KeyError:
print("Please Add your WakaTime API Key to the Repository Secrets")
start_date = datetime.strptime(dawn, api_dfm).strftime(msg_dfm)
end_date = datetime.strptime(dusk, api_dfm).strftime(msg_dfm)
except ValueError as err:
logger.error(f"{err}\n")
sys.exit(1)
data_list = []
try:
pad = len(max([l['name'] for l in lang_data[:5]], key=len))
except ValueError:
print("The Data seems to be empty. Please wait for a day for the data to be filled in.")
return '```text\nNo Activity tracked this Week\n```'
for lang in lang_data[:5]:
if lang['hours'] == 0 and lang['minutes'] == 0:
logger.debug("Title was made\n")
return f"From: {start_date} - To: {end_date}"
def make_graph(block_style: str, percent: float, gr_len: int, lg_nm: str = "", /):
"""WakaReadme Graph.
Makes time graph from the API's data.
"""
logger.debug(f"Generating graph for '{lg_nm or '...'}'")
markers = len(block_style) - 1
proportion = percent / 100 * gr_len
graph_bar = block_style[-1] * int(proportion + 0.5 / markers)
remainder_block = int((proportion - len(graph_bar)) * markers + 0.5)
graph_bar += block_style[remainder_block] if remainder_block > 0 else ""
graph_bar += block_style[0] * (gr_len - len(graph_bar))
logger.debug(f"'{lg_nm or '...'}' graph generated")
return graph_bar
def prep_content(stats: dict[str, Any], language_count: int = 5, stop_at_other: bool = False, /):
"""WakaReadme Prepare Markdown.
Prepared markdown content from the fetched statistics.
```
"""
logger.debug("Making contents")
contents = ""
# make title
if wk_i.show_title:
contents += make_title(stats.get("start"), stats.get("end")) + "\n\n"
# make byline
if wk_i.show_masked_time and (
total_time := stats.get("human_readable_total_including_other_language")
):
# overrides "human_readable_total"
contents += f"Total Time: {total_time}\n\n"
elif wk_i.show_total_time and (total_time := stats.get("human_readable_total")):
contents += f"Total Time: {total_time}\n\n"
lang_info: list[dict[str, int | float | str]] | None = []
# Check if any language data exists
if not (lang_info := stats.get("languages")):
logger.debug("The API data seems to be empty, please wait for a day")
contents += "No activity tracked"
return contents.rstrip("\n")
# make lang content
pad_len = len(
# comment if it feels way computationally expensive
max((str(lng["name"]) for lng in lang_info), key=len)
# and then do not for get to set `pad_len` to say 13 :)
)
if language_count == 0 and not stop_at_other:
logger.debug(
"Set INPUT_LANG_COUNT to -1 to retrieve all language"
+ " or specify a positive number (ie. above 0)"
)
return contents.rstrip("\n")
for idx, lang in enumerate(lang_info):
lang_name = str(lang["name"])
# >>> add languages to filter here <<<
# if lang_name in {...}: continue
lang_time = str(lang["text"]) if wk_i.show_time else ""
lang_ratio = float(lang["percent"])
lang_bar = make_graph(wk_i.block_style, lang_ratio, wk_i.graph_length, lang_name)
contents += (
f"{lang_name.ljust(pad_len)} "
+ f"{lang_time: <16}{lang_bar} "
+ f"{lang_ratio:.2f}".zfill(5)
+ " %\n"
)
if language_count == -1:
continue
lth = len(lang['name'])
ln_text = len(lang['text'])
# following line provides a neat finish
fmt_percent = format(lang['percent'], '0.2f').zfill(5)
data_list.append(
f"{lang['name']}{' '*(pad + 3 - lth)}{lang['text']}{' '*(16 - ln_text)}{make_graph(lang['percent'], blocks)} {fmt_percent} % ")
print("Graph Generated")
data = '\n'.join(data_list)
if show_title == 'true':
print("Stats with Weeks in Title Generated")
return '```text\n'+this_week()+'\n\n'+data+'\n```'
else:
print("Usual Stats Generated")
return '```text\n'+data+'\n```'
if stop_at_other and (lang_name == "Other"):
break
if idx + 1 >= language_count > 0: # idx starts at 0
break
logger.debug("Contents were made\n")
return contents.rstrip("\n")
def decode_readme(data: str) -> str:
'''Decode the contents of old readme'''
decoded_bytes = base64.b64decode(data)
return str(decoded_bytes, 'utf-8')
def fetch_stats():
"""WakaReadme Fetch Stats.
Returns statistics as JSON string.
"""
attempts = 4
statistic: dict[str, dict[str, Any]] = {}
encoded_key = str(b64encode(bytes(str(wk_i.waka_key), "utf-8")), "utf-8")
logger.debug(f"Pulling WakaTime stats from {' '.join(wk_i.time_range.split('_'))}")
while attempts > 0:
resp_message, fake_ua = "", cryptogenic.choice([str(fake.user_agent()) for _ in range(5)])
# making a request
if (
resp := rq_get(
url=f"{str(wk_i.api_base_url).rstrip('/')}/v1/users/current/stats/{wk_i.time_range}",
headers={
"Authorization": f"Basic {encoded_key}",
"User-Agent": fake_ua,
},
timeout=(30.0 * (5 - attempts)),
)
).status_code != 200:
resp_message += f"{conn_info}" if (conn_info := resp.json().get("message")) else ""
logger.debug(
f"API response #{5 - attempts}: {resp.status_code}" + f" {resp.reason}{resp_message}"
)
if resp.status_code == 200 and (statistic := resp.json()):
logger.debug("Fetched WakaTime statistics")
break
logger.debug(f"Retrying in {30 * (5 - attempts )}s ...")
sleep(30 * (5 - attempts))
attempts -= 1
if err := (statistic.get("error") or statistic.get("errors")):
logger.error(f"{err}\n")
sys.exit(1)
print()
return statistic.get("data")
def generate_new_readme(stats: str, readme: str) -> str:
'''Generate a new Readme.md'''
stats_in_readme = f"{START_COMMENT}\n{stats}\n{END_COMMENT}"
return re.sub(listReg, stats_in_readme, readme)
def churn(old_readme: str, /):
"""WakaReadme Churn.
if __name__ == '__main__':
g = Github(ghtoken)
Composes WakaTime stats within markdown code snippet.
"""
# check if placeholder pattern exists in readme
if not re.findall(wk_i.waka_block_pattern, old_readme):
logger.warning(f"Cannot find `{wk_i.waka_block_pattern}` pattern in readme")
return None
# getting contents
if not (waka_stats := fetch_stats()):
logger.error("Unable to fetch data, please rerun workflow\n")
sys.exit(1)
# preparing contents
try:
repo = g.get_repo(repository)
except GithubException:
print("Authentication Error. Try saving a GitHub Token in your Repo Secrets or Use the GitHub Actions Token, which is automatically used by the action.")
generated_content = prep_content(
waka_stats, int(wk_i.language_count), bool(wk_i.stop_at_other)
)
except (AttributeError, KeyError, ValueError) as err:
logger.error(f"Unable to read API data | {err}\n")
sys.exit(1)
if len(blocks) < 1:
print("Invalid blocks string. Please provide provide a string with 2 or more characters. Eg. '░▒▓█'")
print(generated_content, "\n", sep="")
# substituting old contents
new_readme = re.sub(
pattern=wk_i.waka_block_pattern,
repl=f"{wk_i.start_comment}\n\n```{wk_i.code_lang}\n{generated_content}\n```\n\n{wk_i.end_comment}",
string=old_readme,
)
if len(sys.argv) == 2 and sys.argv[1] == "--dev":
logger.debug("Detected run in `dev` mode.")
# to avoid accidentally writing back to Github
# when developing or testing waka-readme
return None
return None if new_readme == old_readme else new_readme
def qualify_target(gh_repo: Repository.Repository):
"""Qualify target repository defaults."""
@dataclass
class TargetRepository:
this: ContentFile.ContentFile
path: str
commit_message: str
sha: str
branch: str
committer: InputGitAuthor | None
author: InputGitAuthor | None
gh_branch = gh_repo.default_branch
if wk_i.target_branch != "NOT_SET":
gh_branch = gh_repo.get_branch(wk_i.target_branch)
target = gh_repo.get_readme()
if wk_i.target_path != "NOT_SET":
target = gh_repo.get_contents(
path=wk_i.target_path,
ref=gh_branch if isinstance(gh_branch, str) else gh_branch.commit.sha,
)
if isinstance(target, list):
raise RuntimeError("Cannot handle multiple files.")
committer, author = None, None
if wk_i.committer_name != "NOT_SET" and wk_i.committer_email != "NOT_SET":
committer = InputGitAuthor(name=wk_i.committer_name, email=wk_i.committer_email)
if wk_i.author_name != "NOT_SET" and wk_i.author_email != "NOT_SET":
author = InputGitAuthor(name=wk_i.author_name, email=wk_i.author_email)
return TargetRepository(
this=target,
path=target.path,
commit_message=wk_i.commit_message,
sha=target.sha,
branch=gh_branch if isinstance(gh_branch, str) else gh_branch.name,
committer=committer,
author=author,
)
def genesis():
"""Run Program."""
logger.debug("Connecting to GitHub")
gh_connect = Github(wk_i.gh_token)
# since a validator is being used earlier, casting
# `wk_i.ENV_VARIABLE` to a string here, is okay
gh_repo = gh_connect.get_repo(str(wk_i.repository))
target = qualify_target(gh_repo)
logger.debug("Decoding readme contents\n")
readme_contents = str(target.this.decoded_content, encoding="utf-8")
if not (new_content := churn(readme_contents)):
logger.info("WakaReadme was not updated")
return
logger.debug("WakaReadme stats has changed")
update_metric = partial(
gh_repo.update_file,
path=target.path,
message=target.commit_message,
content=new_content,
sha=target.sha,
branch=target.branch,
)
if target.committer:
update_metric = partial(update_metric, committer=target.committer)
if target.author:
update_metric = partial(update_metric, author=target.author)
update_metric()
logger.info("Stats updated successfully")
################### driver ###################
if __name__ == "__main__":
# faker data preparation
fake = Faker()
Faker.seed(0)
cryptogenic = SystemRandom()
# initial waka-readme setup
logger.debug("Initialize WakaReadme")
wk_i = WakaInput()
if not wk_i.validate_input():
logger.error("Environment variables are misconfigured\n")
sys.exit(1)
contents = repo.get_readme()
waka_stats = get_stats()
rdmd = decode_readme(contents.content)
new_readme = generate_new_readme(stats=waka_stats, readme=rdmd)
if new_readme != rdmd:
repo.update_file(path=contents.path, message=commit_message,
content=new_readme, sha=contents.sha)
# run
try:
genesis()
except KeyboardInterrupt:
print("\r", end=" ")
logger.error("Interrupt signal received\n")
sys.exit(1)
except RuntimeError as err:
logger.error(f"{type(err).__name__}: {err}\n")
sys.exit(1)
except (GithubException, RequestException) as rq_exp:
logger.critical(f"{rq_exp}\n")
sys.exit(1)
print("\nThanks for using WakaReadme!\n")

56
pyproject.toml Normal file
View File

@@ -0,0 +1,56 @@
####################
# Metadata #
####################
[project]
name = "waka-readme"
version = "0.2.3"
description = "Wakatime Weekly Metrics on your Profile Readme."
license = { text = "MIT" }
readme = "README.md"
keywords = ["readme", "profile-page", "wakatime"]
authors = [{ name = "Athul Cyriac Ajay", email = "athul8720@gmail.com" }]
maintainers = [{ name = "Jovial Joe Jayarson" }]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python",
"Typing :: Typed",
]
requires-python = ">=3.11"
dependencies = ["faker>=19.1.0", "pygithub>=1.59.0", "requests>=2.31.0"]
[project.urls]
Homepage = "https://github.com/athul/waka-readme"
Documentation = "https://github.com/athul/waka-readme#readme"
Repository = "https://github.com/athul/waka-readme"
Changelog = "https://github.com/athul/waka-readme/commits/master"
#############################
# Optional Dependencies #
#############################
[project.optional-dependencies]
dev = ["loguru>=0.7.0", "python-dotenv>=1.0.0"]
tooling = ["bandit>=1.7.5", "black>=23.7.0", "ruff>=0.0.278"]
####################
# Configurations #
####################
[tool.black]
line-length = 100
target-version = ["py311"]
[tool.bandit]
exclude_dirs = [".github", ".pytest_cache", ".tox", ".vscode", "site", "tests"]
[tool.ruff]
line-length = 100
[tool.ruff.pydocstyle]
convention = "google"
[tool.ruff.isort]
force-sort-within-sections = true
relative-imports-order = "closest-to-furthest"

View File

@@ -1,9 +0,0 @@
certifi==2020.6.20
chardet==3.0.4
Deprecated==1.2.10
idna==2.10
PyGithub==1.51
PyJWT==1.7.1
requests==2.24.0
urllib3==1.25.9
wrapt==1.12.1

View File

@@ -0,0 +1,9 @@
"""
Initialize test module
"""
# standard
import logging
# comment to enable logging w/ tests
logging.disable(logging.CRITICAL)

11346
tests/sample_data.json Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,50 +1,148 @@
'''
Tests for the main.py
'''
from main import make_graph
"""Unit Tests."""
# standard
from importlib import import_module
from dataclasses import dataclass # , field
from itertools import product
import unittest
import sys
import os
# from pathlib import Path
# from inspect import cleandoc
# from typing import Any
# from json import load
try:
prime = import_module("main")
# works when running as
# python -m unittest discover
except ImportError as err:
print(err)
# sys.exit(1)
@dataclass
class TestData:
"""Test Data."""
# for future tests
# waka_json: dict[str, dict[str, Any]] = field(
# default_factory=lambda: {}
# )
bar_percent: tuple[int | float, ...] | None = None
graph_blocks: tuple[str, ...] | None = None
waka_graphs: tuple[list[str], ...] | None = None
dummy_readme: str = ""
def populate(self) -> None:
"""Populate Test Data."""
# for future tests
# with open(
# file=Path(__file__).parent / "sample_data.json",
# encoding="utf-8",
# mode="rt",
# ) as wkf:
# self.waka_json = load(wkf)
self.bar_percent = (0, 100, 49.999, 50, 25, 75, 3.14, 9.901, 87.334, 87.333, 4.666, 4.667)
self.graph_blocks = ("░▒▓█", "⚪⚫", "⓪①②③④⑤⑥⑦⑧⑨⑩")
self.waka_graphs = (
[
"░░░░░░░░░░░░░░░░░░░░░░░░░",
"█████████████████████████",
"████████████▒░░░░░░░░░░░░",
"████████████▓░░░░░░░░░░░░",
"██████▒░░░░░░░░░░░░░░░░░░",
"██████████████████▓░░░░░░",
"▓░░░░░░░░░░░░░░░░░░░░░░░░",
"██▒░░░░░░░░░░░░░░░░░░░░░░",
"██████████████████████░░░",
"█████████████████████▓░░░",
"█░░░░░░░░░░░░░░░░░░░░░░░░",
"█▒░░░░░░░░░░░░░░░░░░░░░░░",
],
[
"⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
],
[
"⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑤⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑤⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩③⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑧⓪⓪⓪⓪⓪⓪",
"⑧⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑤⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑧⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑧⓪⓪⓪",
"⑩②⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩②⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
],
)
# self.dummy_readme = cleandoc("""
# My Test Readme Start
# <!--START_SECTION:waka-->
# <!--END_SECTION:waka-->
# My Test Readme End
# """)
class TestMain(unittest.TestCase):
"""Testing Main Module."""
def test_make_graph(self):
'''Tests the make_graph function'''
def test(percent: float, block: str, result: str):
self.assertEqual(make_graph(percent, block), result,
f"{percent}% should return {result}")
blocks = ["░▒▓█", "⚪⚫"]
percents = [0, 100, 50, 50.001, 25, 75, 3.14,
9.901, 87.334, 87.333, 4.666, 4.667]
graphGroup = [["░░░░░░░░░░░░░░░░░░░░░░░░░",
"█████████████████████████",
"████████████▒░░░░░░░░░░░░",
"████████████▓░░░░░░░░░░░░",
"██████▒░░░░░░░░░░░░░░░░░░",
"██████████████████▓░░░░░░",
"▓░░░░░░░░░░░░░░░░░░░░░░░░",
"██▒░░░░░░░░░░░░░░░░░░░░░░",
"██████████████████████░░░",
"█████████████████████▓░░░",
"█░░░░░░░░░░░░░░░░░░░░░░░░",
"█▒░░░░░░░░░░░░░░░░░░░░░░░"],
["⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪"]]
for i, graphs in enumerate(graphGroup):
os.environ["INPUT_BLOCKS"] = blocks[i]
for j, graph in enumerate(graphs):
test(percents[j], blocks[i], graph)
def test_make_graph(self) -> None:
"""Test graph maker."""
if not tds.graph_blocks or not tds.waka_graphs or not tds.bar_percent:
raise AssertionError("Data population failed")
for (idx, grb), (jdy, bpc) in product(
enumerate(tds.graph_blocks), enumerate(tds.bar_percent)
):
self.assertEqual(prime.make_graph(grb, bpc, 25), tds.waka_graphs[idx][jdy])
def test_make_title(self) -> None:
"""Test title maker."""
self.assertRegex(
prime.make_title("2022-01-11T23:18:19Z", "2021-12-09T10:22:06Z"),
r"From: \d{2} \w{3,9} \d{4} - To: \d{2} \w{3,9} \d{4}",
)
def test_strtobool(self) -> None:
"""Test string to bool."""
self.assertTrue(prime.strtobool("Yes"))
self.assertFalse(prime.strtobool("nO"))
self.assertTrue(prime.strtobool(True))
self.assertRaises(AttributeError, prime.strtobool, None)
self.assertRaises(ValueError, prime.strtobool, "yo!")
self.assertRaises(AttributeError, prime.strtobool, 20.5)
if __name__ == '__main__':
tds = TestData()
tds.populate()
if __name__ == "__main__":
try:
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
import main as prime
# works when running as
# python tests/test_main.py
except ImportError as im_er:
print(im_er)
sys.exit(1)
unittest.main()