Add support for parametrized blocks
- Modify action to support input of block string - Modify make graph function to support parametrized blocks - Add tests for parametrized blocks - Update README with new issue - Fix some format errors and typos
This commit is contained in:
parent
ec79c6dacb
commit
c5aaa5ad5d
62
README.md
62
README.md
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
----
|
---
|
||||||
|
|
||||||
[WakaTime](https://wakatime.com) Weekly Metrics on your Profile Readme:
|
[WakaTime](https://wakatime.com) Weekly Metrics on your Profile Readme:
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ WakaTime gives you an idea of the time you really spent on coding. This helps yo
|
|||||||
|
|
||||||
### Profile Repository
|
### Profile Repository
|
||||||
|
|
||||||
*If you're executing the workflow on your Profile Repository (`<username>/<username>`)*
|
_If you're executing the workflow on your Profile Repository (`<username>/<username>`)_
|
||||||
|
|
||||||
> You wouldn't need an GitHub Access Token since GitHub Actions already makes one for you.
|
> You wouldn't need an GitHub Access Token since GitHub Actions already makes one for you.
|
||||||
|
|
||||||
@ -52,16 +52,17 @@ Please follow the steps below:
|
|||||||
|
|
||||||
1. Go to your `<username>/<username>/actions`, hit `New workflow`, `set up a workflow yourself`, delete all the default content github made for you.
|
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:
|
2. Copy the following code and paste it to your new workflow you created at step 1:
|
||||||
```yml
|
|
||||||
name: Waka Readme
|
|
||||||
|
|
||||||
on:
|
```yml
|
||||||
|
name: Waka Readme
|
||||||
|
|
||||||
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
schedule:
|
schedule:
|
||||||
# Runs at 12am UTC
|
# Runs at 12am UTC
|
||||||
- cron: '0 0 * * *'
|
- cron: "0 0 * * *"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update-readme:
|
update-readme:
|
||||||
name: Update this repo's README
|
name: Update this repo's README
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@ -69,23 +70,23 @@ Please follow the steps below:
|
|||||||
- uses: athul/waka-readme@master
|
- uses: athul/waka-readme@master
|
||||||
with:
|
with:
|
||||||
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
|
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
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.
|
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:
|
5. Add a comment to your `README.md` like this:
|
||||||
|
|
||||||
```md
|
```md
|
||||||
<!--START_SECTION:waka-->
|
<!--START_SECTION:waka-->
|
||||||
<!--END_SECTION:waka-->
|
<!--END_SECTION:waka-->
|
||||||
```
|
```
|
||||||
|
|
||||||
6. Go to Workflows menu (mentioned in step 1), click `Waka Readme`, click `Run workflow`.
|
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.
|
7. Go to your profile page. you will be able to see it.
|
||||||
|
|
||||||
### Other Repository (not Profile)
|
### Other Repository (not Profile)
|
||||||
|
|
||||||
|
_If you're executing the workflow on another repo other than `<username>/<username>`_
|
||||||
|
|
||||||
*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>`
|
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>`
|
||||||
|
|
||||||
@ -97,7 +98,7 @@ name: Waka Readme
|
|||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
# Runs at 12am UTC
|
# Runs at 12am UTC
|
||||||
- cron: '0 0 * * *'
|
- cron: "0 0 * * *"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update-readme:
|
update-readme:
|
||||||
@ -112,12 +113,17 @@ jobs:
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
|
|
||||||
### Running Tests
|
### Running Tests
|
||||||
|
|
||||||
To run tests simply execute the following in the directory containing main.py:
|
To run tests simply execute the following in the directory containing main.py:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
python -m unittest discover
|
python -m unittest discover
|
||||||
```
|
```
|
||||||
|
|
||||||
### Contributing Tests
|
### Contributing Tests
|
||||||
|
|
||||||
These tests uses the python Unit testing framework, [unittest](https://docs.python.org/3/library/unittest.html)
|
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.
|
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.
|
||||||
@ -145,7 +151,7 @@ Docker 16 mins ░░░░░░░░░░░░░░░░
|
|||||||
YAML 7 mins ░░░░░░░░░░░░░░░░░░░░░░░░░ 01.07 %
|
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
|
2. You can specify a commit message to override the default _"Updated the Graph with new Metrics"_. Here is how you do it
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
- uses: athul/waka-readme@master
|
- uses: athul/waka-readme@master
|
||||||
@ -157,5 +163,25 @@ YAML 7 mins ░░░░░░░░░░░░░░░░
|
|||||||
|
|
||||||
If no commit message is specified in the `yml` file, it defaults to _"Updated the Graph with new Metrics"_
|
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?
|
## 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:
|
|
||||||
|
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:
|
||||||
|
22
action.yml
22
action.yml
@ -1,19 +1,19 @@
|
|||||||
name: 'Waka - Readme'
|
name: "Waka - Readme"
|
||||||
author: Athil Cyriac Ajay
|
author: Athil Cyriac Ajay
|
||||||
description: 'Add a Wakatime Coding Activity graph in your Readme'
|
description: "Add a Wakatime Coding Activity graph in your Readme"
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
GH_TOKEN:
|
GH_TOKEN:
|
||||||
description: 'GitHub access token with Repo scope'
|
description: "GitHub access token with Repo scope"
|
||||||
required: true
|
required: true
|
||||||
default: ${{ github.token }}
|
default: ${{ github.token }}
|
||||||
|
|
||||||
WAKATIME_API_KEY:
|
WAKATIME_API_KEY:
|
||||||
description: 'Your Wakatime API Key'
|
description: "Your Wakatime API Key"
|
||||||
required: true
|
required: true
|
||||||
|
|
||||||
REPOSITORY:
|
REPOSITORY:
|
||||||
description: 'Your GitHub repository'
|
description: "Your GitHub repository"
|
||||||
default: ${{ github.repository }}
|
default: ${{ github.repository }}
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
@ -27,11 +27,15 @@ inputs:
|
|||||||
default: "Updated the Graph with new Metrics"
|
default: "Updated the Graph with new Metrics"
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
|
BLOCKS:
|
||||||
|
description: "Add the progress blocks of your choice"
|
||||||
|
default: "░▒▓█"
|
||||||
|
required: false
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: "docker"
|
||||||
image: 'Dockerfile'
|
image: "Dockerfile"
|
||||||
|
|
||||||
branding:
|
branding:
|
||||||
icon: 'info'
|
icon: "info"
|
||||||
color: 'blue'
|
color: "blue"
|
||||||
|
14
main.py
14
main.py
@ -19,6 +19,7 @@ waka_key = os.getenv('INPUT_WAKATIME_API_KEY')
|
|||||||
ghtoken = os.getenv('INPUT_GH_TOKEN')
|
ghtoken = os.getenv('INPUT_GH_TOKEN')
|
||||||
show_title = os.getenv("INPUT_SHOW_TITLE")
|
show_title = os.getenv("INPUT_SHOW_TITLE")
|
||||||
commit_message = os.getenv("INPUT_COMMIT_MESSAGE")
|
commit_message = os.getenv("INPUT_COMMIT_MESSAGE")
|
||||||
|
blocks = os.getenv("INPUT_BLOCKS")
|
||||||
|
|
||||||
|
|
||||||
def this_week() -> str:
|
def this_week() -> str:
|
||||||
@ -29,11 +30,11 @@ def this_week() -> str:
|
|||||||
return f"Week: {week_start.strftime('%d %B, %Y')} - {week_end.strftime('%d %B, %Y')}"
|
return f"Week: {week_start.strftime('%d %B, %Y')} - {week_end.strftime('%d %B, %Y')}"
|
||||||
|
|
||||||
|
|
||||||
def make_graph(percent: float) -> str:
|
def make_graph(percent: float, blocks: str) -> str:
|
||||||
'''Make progress graph from API graph'''
|
'''Make progress graph from API graph'''
|
||||||
blocks = "░▒▓█"
|
graph = blocks[len(blocks)-1] * int(percent / 4 + 1 / 6)
|
||||||
graph = blocks[3] * int(percent / 4 + 1 / 6)
|
remainder_block = int((percent + (len(blocks)-2) /
|
||||||
remainder_block = int((percent + 2 / 3) % 4 * 3 / 4)
|
(len(blocks)-1)) % 4 * (len(blocks)-1) / len(blocks))
|
||||||
if remainder_block > 0:
|
if remainder_block > 0:
|
||||||
graph += blocks[remainder_block]
|
graph += blocks[remainder_block]
|
||||||
graph += blocks[0] * (25 - len(graph))
|
graph += blocks[0] * (25 - len(graph))
|
||||||
@ -64,7 +65,7 @@ def get_stats() -> str:
|
|||||||
# following line provides a neat finish
|
# following line provides a neat finish
|
||||||
fmt_percent = format(lang['percent'], '0.2f').zfill(5)
|
fmt_percent = format(lang['percent'], '0.2f').zfill(5)
|
||||||
data_list.append(
|
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'], blocks)} {fmt_percent} % ")
|
||||||
print("Graph Generated")
|
print("Graph Generated")
|
||||||
data = '\n'.join(data_list)
|
data = '\n'.join(data_list)
|
||||||
if show_title == 'true':
|
if show_title == 'true':
|
||||||
@ -94,6 +95,9 @@ if __name__ == '__main__':
|
|||||||
except GithubException:
|
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.")
|
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.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
if len(blocks) < 1:
|
||||||
|
print("Invalid blocks string. Please provide provide a string with 2 or more characters. Eg. '░▒▓█'")
|
||||||
|
sys.exit(1)
|
||||||
contents = repo.get_readme()
|
contents = repo.get_readme()
|
||||||
waka_stats = get_stats()
|
waka_stats = get_stats()
|
||||||
rdmd = decode_readme(contents.content)
|
rdmd = decode_readme(contents.content)
|
||||||
|
@ -3,26 +3,47 @@ Tests for the main.py
|
|||||||
'''
|
'''
|
||||||
from main import make_graph
|
from main import make_graph
|
||||||
import unittest
|
import unittest
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
class TestMain(unittest.TestCase):
|
class TestMain(unittest.TestCase):
|
||||||
|
|
||||||
def test_make_graph(self):
|
def test_make_graph(self):
|
||||||
'''Tests the make_graph function'''
|
'''Tests the make_graph function'''
|
||||||
def test(percent: float, result: str):
|
def test(percent: float, block: str, result: str):
|
||||||
self.assertEqual(make_graph(percent), result, f"{percent}% should return {result}")
|
self.assertEqual(make_graph(percent, block), result,
|
||||||
test(0, "░░░░░░░░░░░░░░░░░░░░░░░░░")
|
f"{percent}% should return {result}")
|
||||||
test(100, "█████████████████████████")
|
blocks = ["░▒▓█", "⚪⚫"]
|
||||||
test(50, "████████████▒░░░░░░░░░░░░")
|
percents = [0, 100, 50, 50.001, 25, 75, 3.14,
|
||||||
test(50.001, "████████████▓░░░░░░░░░░░░")
|
9.901, 87.334, 87.333, 4.666, 4.667]
|
||||||
test(25, "██████▒░░░░░░░░░░░░░░░░░░")
|
graphGroup = [["░░░░░░░░░░░░░░░░░░░░░░░░░",
|
||||||
test(75, "██████████████████▓░░░░░░")
|
"█████████████████████████",
|
||||||
test(3.14, "▓░░░░░░░░░░░░░░░░░░░░░░░░")
|
"████████████▒░░░░░░░░░░░░",
|
||||||
test(9.901, "██▒░░░░░░░░░░░░░░░░░░░░░░")
|
"████████████▓░░░░░░░░░░░░",
|
||||||
test(87.334, "██████████████████████░░░")
|
"██████▒░░░░░░░░░░░░░░░░░░",
|
||||||
test(87.333, "█████████████████████▓░░░")
|
"██████████████████▓░░░░░░",
|
||||||
test(4.666, "█░░░░░░░░░░░░░░░░░░░░░░░░")
|
"▓░░░░░░░░░░░░░░░░░░░░░░░░",
|
||||||
test(4.667, "█▒░░░░░░░░░░░░░░░░░░░░░░░")
|
"██▒░░░░░░░░░░░░░░░░░░░░░░",
|
||||||
|
"██████████████████████░░░",
|
||||||
|
"█████████████████████▓░░░",
|
||||||
|
"█░░░░░░░░░░░░░░░░░░░░░░░░",
|
||||||
|
"█▒░░░░░░░░░░░░░░░░░░░░░░░"],
|
||||||
|
["⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
|
||||||
|
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫",
|
||||||
|
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
|
||||||
|
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
|
||||||
|
"⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
|
||||||
|
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪",
|
||||||
|
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
|
||||||
|
"⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
|
||||||
|
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪",
|
||||||
|
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪",
|
||||||
|
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
|
||||||
|
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪"]]
|
||||||
|
for i, graphs in enumerate(graphGroup):
|
||||||
|
os.environ["INPUT_BLOCKS"] = blocks[i]
|
||||||
|
for j, graph in enumerate(graphs):
|
||||||
|
test(percents[j], blocks[i], graph)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user