Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
aaff45b1d4 | ||
|
b37bede506 | ||
|
215367a2ad | ||
|
d827cb172d | ||
|
73c1050f48 | ||
|
d0c740a1a1 | ||
|
6f4f9c9933 | ||
|
442c0dae4d | ||
|
fa74a6bca2 | ||
|
55aaf85a2f | ||
|
59c5854cd1 | ||
|
21e5b9c804 |
4
.github/FUNDING.yml
vendored
Normal file
4
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
ko_fi: athulcyriac
|
||||
custom: https://www.buymeacoffee.com/JeVlc7T
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
#generated when running the tests
|
||||
__pycache__/
|
7
.travis.yml
Normal file
7
.travis.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
language: python
|
||||
python:
|
||||
- "3.7"
|
||||
install:
|
||||
- pip install -r requirements.txt
|
||||
script:
|
||||
- python -m unittest discover
|
31
README.md
31
README.md
@@ -1,4 +1,4 @@
|
||||
# Dev Metrics in Readme
|
||||
# Dev Metrics in Readme [](https://travis-ci.com/athul/waka-readme)
|
||||
|
||||

|
||||
|
||||
@@ -56,7 +56,7 @@ Please follow the steps below:
|
||||
name: Waka Readme
|
||||
|
||||
on:
|
||||
workflow_dispatch
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
# Runs at 12am UTC
|
||||
- cron: '0 0 * * *'
|
||||
@@ -111,6 +111,17 @@ jobs:
|
||||
USERNAME: <username> # optional, it will automatically use the username of the owner of 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
|
||||
@@ -134,3 +145,19 @@ Markdown 52 mins █░░░░░░░░░░░░░░░
|
||||
Docker 16 mins ░░░░░░░░░░░░░░░░░░░░░░░░░ 02.32 %
|
||||
YAML 7 mins ░░░░░░░░░░░░░░░░░░░░░░░░░ 01.07 %
|
||||
```
|
||||
|
||||
2. You can specify a commit message to overrdie 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 }}
|
||||
USERNAME: <username>
|
||||
COMMIT_MESSAGE: Updated the Readme
|
||||
```
|
||||
|
||||
If no commit message is specified in the `yml` file, it defaults to _"Updated the Graph with new Metrics"_
|
||||
|
||||
## 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:
|
||||
|
@@ -21,6 +21,11 @@ inputs:
|
||||
description: "Displays the week number and days in Readme as title"
|
||||
default: false
|
||||
required: false
|
||||
|
||||
COMMIT_MESSAGE:
|
||||
description: "Add a commit message of your choice"
|
||||
default: "Updated the Graph with new Metrics"
|
||||
required: false
|
||||
|
||||
|
||||
runs:
|
||||
|
20
main.py
20
main.py
@@ -18,6 +18,7 @@ user = os.getenv('INPUT_USERNAME')
|
||||
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")
|
||||
|
||||
|
||||
def this_week() -> str:
|
||||
@@ -30,10 +31,13 @@ def this_week() -> str:
|
||||
|
||||
def make_graph(percent: float) -> str:
|
||||
'''Make progress graph from API graph'''
|
||||
done_block = '█'
|
||||
empty_block = '░'
|
||||
pc_rnd = round(percent)
|
||||
return f"{done_block*int(pc_rnd/4)}{empty_block*int(25-int(pc_rnd/4))}"
|
||||
blocks = "░▒▓█"
|
||||
graph = blocks[3] * int(percent / 4 + 1 / 6)
|
||||
remainder_block = int((percent + 2 / 3) % 4 * 3 / 4)
|
||||
if remainder_block > 0:
|
||||
graph += blocks[remainder_block]
|
||||
graph += blocks[0] * (25 - len(graph))
|
||||
return graph
|
||||
|
||||
|
||||
def get_stats() -> str:
|
||||
@@ -58,9 +62,9 @@ def get_stats() -> str:
|
||||
# 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'])} {fmt_percent} %")
|
||||
f"{lang['name']}{' '*(pad + 3 - lth)}{lang['text']}{' '*(16 - ln_text)}{make_graph(lang['percent'])} {fmt_percent} % ")
|
||||
print("Graph Generated")
|
||||
data = ' \n'.join(data_list)
|
||||
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```'
|
||||
@@ -70,7 +74,7 @@ def get_stats() -> str:
|
||||
|
||||
|
||||
def decode_readme(data: str) -> str:
|
||||
'''Decode the contets of old readme'''
|
||||
'''Decode the contents of old readme'''
|
||||
decoded_bytes = base64.b64decode(data)
|
||||
return str(decoded_bytes, 'utf-8')
|
||||
|
||||
@@ -93,5 +97,5 @@ if __name__ == '__main__':
|
||||
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='Updated with Dev Metrics',
|
||||
repo.update_file(path=contents.path, message=commit_message,
|
||||
content=new_readme, sha=contents.sha, branch='master')
|
||||
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
29
tests/test_main.py
Normal file
29
tests/test_main.py
Normal file
@@ -0,0 +1,29 @@
|
||||
'''
|
||||
Tests for the main.py
|
||||
'''
|
||||
from main import make_graph
|
||||
import unittest
|
||||
|
||||
|
||||
class TestMain(unittest.TestCase):
|
||||
|
||||
def test_make_graph(self):
|
||||
'''Tests the make_graph function'''
|
||||
def test(percent: float, result: str):
|
||||
self.assertEqual(make_graph(percent), result, f"{percent}% should return {result}")
|
||||
test(0, "░░░░░░░░░░░░░░░░░░░░░░░░░")
|
||||
test(100, "█████████████████████████")
|
||||
test(50, "████████████▒░░░░░░░░░░░░")
|
||||
test(50.001, "████████████▓░░░░░░░░░░░░")
|
||||
test(25, "██████▒░░░░░░░░░░░░░░░░░░")
|
||||
test(75, "██████████████████▓░░░░░░")
|
||||
test(3.14, "▓░░░░░░░░░░░░░░░░░░░░░░░░")
|
||||
test(9.901, "██▒░░░░░░░░░░░░░░░░░░░░░░")
|
||||
test(87.334, "██████████████████████░░░")
|
||||
test(87.333, "█████████████████████▓░░░")
|
||||
test(4.666, "█░░░░░░░░░░░░░░░░░░░░░░░░")
|
||||
test(4.667, "█▒░░░░░░░░░░░░░░░░░░░░░░░")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user