feat: adds flag IGNORE_LANGUAGES (#146)

- feat: adds flag `IGNORE_LANGUAGES`  (#146)

---------

Co-authored-by: Jovial Joe Jayarson <jovial7joe@hotmail.com>
This commit is contained in:
Andrew Hong 2023-10-20 22:28:43 -04:00 committed by GitHub
parent dd576f44c6
commit 54c3312012
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 25 deletions

View File

@ -17,6 +17,7 @@ INPUT_SHOW_TIME=
INPUT_SHOW_TOTAL= INPUT_SHOW_TOTAL=
INPUT_SHOW_MASKED_TIME= INPUT_SHOW_MASKED_TIME=
INPUT_STOP_AT_OTHER= INPUT_STOP_AT_OTHER=
INPUT_IGNORED_LANGUAGES=
# commit # commit
INPUT_COMMIT_MESSAGE= INPUT_COMMIT_MESSAGE=
INPUT_TARGET_BRANCH= INPUT_TARGET_BRANCH=

View File

@ -21,6 +21,7 @@ INPUT_TIME_RANGE=last_7_days
INPUT_SHOW_MASKED_TIME=false INPUT_SHOW_MASKED_TIME=false
INPUT_LANG_COUNT=0 INPUT_LANG_COUNT=0
INPUT_STOP_AT_OTHER=true INPUT_STOP_AT_OTHER=true
INPUT_IGNORED_LANGUAGES=
``` ```
**NEVER commit this `.env` file!** **NEVER commit this `.env` file!**
@ -32,10 +33,8 @@ INPUT_STOP_AT_OTHER=true
> Replace `podman` with `docker` everywhere, if you're using the latter. > Replace `podman` with `docker` everywhere, if you're using the latter.
```sh ```sh
# Build # Build and watch logs
$ podman-compose -p waka-readme -f ./docker-compose.yml up -d $ podman-compose -p waka-readme -f ./docker-compose.yml up
# Logs
$ podman logs WakaReadmeDev
# Cleanup # Cleanup
$ podman-compose -p waka-readme -f ./docker-compose.yml down $ podman-compose -p waka-readme -f ./docker-compose.yml down
``` ```

View File

@ -93,7 +93,7 @@ A GitHub repository and a `README.md` file is required. We'll be making use of r
name: WakaReadme DevMetrics name: WakaReadme DevMetrics
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: athul/waka-readme@master - uses: athul/waka-readme@master # this action name
with: with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }} WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
``` ```
@ -114,7 +114,7 @@ There are many flags that you can modify as you see fit.
### Content Tweaks ### Content Tweaks
| Environment flag | Options (`Default`, `Other`, ...) | Description | | Environment flag | Options (`Default`, `Other`, ...) | Description |
| ------------------ | ----------------------------------------------------------------------- | --------------------------------------------------------------------------------- | | ------------------- | ----------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| `SHOW_TITLE` | `false`, `true` | Add title to waka-readme stats blob | | `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. | | `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 | | `BLOCKS` | `░▒▓█`, `⣀⣄⣤⣦⣶⣷⣿`, `-#`, `=>`, you can be creative | Ascii art used to build stats graph |
@ -125,6 +125,7 @@ There are many flags that you can modify as you see fit.
| `SHOW_TOTAL` | `false`, `true` | Show total coding time | | `SHOW_TOTAL` | `false`, `true` | Show total coding time |
| `SHOW_MASKED_TIME` | `false`, `true` | Adds total coding time including unclassified languages (overrides: `SHOW_TOTAL`) | | `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`) | | `STOP_AT_OTHER` | `false`, `true` | Stop when language marked as `Other` is retrieved (overrides: `LANG_COUNT`) |
| `IGNORED_LANGUAGES` | <code> </code>, `Binary YAML JSON TOML` | Hide languages from your stats |
### Commit Tweaks ### Commit Tweaks
@ -159,7 +160,8 @@ jobs:
name: WakaReadme DevMetrics name: WakaReadme DevMetrics
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: athul/waka-readme@master # this action name
- uses: athul/waka-readme@master # do NOT replace with anything else
with: with:
GH_TOKEN: ${{ secrets.GH_TOKEN }} # optional if on profile readme GH_TOKEN: ${{ secrets.GH_TOKEN }} # optional if on profile readme
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }} # required WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }} # required
@ -177,6 +179,7 @@ jobs:
SHOW_TOTAL: true # optional SHOW_TOTAL: true # optional
SHOW_MASKED_TIME: false # optional SHOW_MASKED_TIME: false # optional
STOP_AT_OTHER: true # optional STOP_AT_OTHER: true # optional
IGNORED_LANGUAGES: YAML JSON TOML # optional
### commit ### commit
COMMIT_MESSAGE: Updated waka-readme graph with new metrics # optional COMMIT_MESSAGE: Updated waka-readme graph with new metrics # optional
TARGET_BRANCH: master # optional TARGET_BRANCH: master # optional
@ -213,6 +216,7 @@ Other 47 hrs 58 mins >------------------------ 03.05 %
- If you are using `GH_TOKEN`, make sure set the [fine grained token](https://github.com/settings/tokens?type=beta) scope to repository contents with `read-and-write` access. See [#141 (comment)](https://github.com/athul/waka-readme/issues/141#issuecomment-1679831949). - If you are using `GH_TOKEN`, make sure set the [fine grained token](https://github.com/settings/tokens?type=beta) scope to repository contents with `read-and-write` access. See [#141 (comment)](https://github.com/athul/waka-readme/issues/141#issuecomment-1679831949).
- `WAKATIME_API_KEY` is a **required** secret. All other environment variables are optional. - `WAKATIME_API_KEY` is a **required** secret. All other environment variables are optional.
- The above example does NOT show proper default values, refer [#Tweaks](#tweaks) for the same. - The above example does NOT show proper default values, refer [#Tweaks](#tweaks) for the same.
- `IGNORED_LANGUAGES` is suggested for [.NET](https://dotnet.microsoft.com) users, as WakaTime assumes you're working with `Binary`, while debugging.
## Why only the language stats (and not other data) from the API? ## Why only the language stats (and not other data) from the API?

View File

@ -62,6 +62,10 @@ inputs:
description: "Stop data retrieval when language marked 'Other' is reached" description: "Stop data retrieval when language marked 'Other' is reached"
default: "false" default: "false"
required: false required: false
IGNORED_LANGUAGES:
description: "Ignore space separated, listed languages"
default: ""
required: false
# commit tweaks # commit tweaks
COMMIT_MESSAGE: COMMIT_MESSAGE:

View File

@ -16,6 +16,7 @@ ENV INPUT_GH_TOKEN \
INPUT_SHOW_TOTAL \ INPUT_SHOW_TOTAL \
INPUT_SHOW_MASKED_TIME \ INPUT_SHOW_MASKED_TIME \
INPUT_STOP_AT_OTHER \ INPUT_STOP_AT_OTHER \
INPUT_IGNORED_LANGUAGES \
# commit # commit
INPUT_COMMIT_MESSAGE \ INPUT_COMMIT_MESSAGE \
INPUT_TARGET_BRANCH \ INPUT_TARGET_BRANCH \

View File

@ -16,6 +16,7 @@ ENV INPUT_GH_TOKEN \
INPUT_SHOW_TOTAL \ INPUT_SHOW_TOTAL \
INPUT_SHOW_MASKED_TIME \ INPUT_SHOW_MASKED_TIME \
INPUT_STOP_AT_OTHER \ INPUT_STOP_AT_OTHER \
INPUT_IGNORED_LANGUAGES \
# commit # commit
INPUT_COMMIT_MESSAGE \ INPUT_COMMIT_MESSAGE \
INPUT_TARGET_BRANCH \ INPUT_TARGET_BRANCH \

15
main.py
View File

@ -149,6 +149,7 @@ class WakaInput:
show_masked_time: str | bool = os.getenv("INPUT_SHOW_MASKED_TIME") 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 language_count: str | int = os.getenv("INPUT_LANG_COUNT") or 5
stop_at_other: str | bool = os.getenv("INPUT_STOP_AT_OTHER") or False stop_at_other: str | bool = os.getenv("INPUT_STOP_AT_OTHER") or False
ignored_languages: str = os.getenv("INPUT_IGNORED_LANGUAGES", "")
# # optional meta # # optional meta
target_branch: str = os.getenv("INPUT_TARGET_BRANCH", "NOT_SET") target_branch: str = os.getenv("INPUT_TARGET_BRANCH", "NOT_SET")
target_path: str = os.getenv("INPUT_TARGET_PATH", "NOT_SET") target_path: str = os.getenv("INPUT_TARGET_PATH", "NOT_SET")
@ -270,7 +271,7 @@ def make_graph(block_style: str, percent: float, gr_len: int, lg_nm: str = "", /
return graph_bar return graph_bar
def prep_content(stats: dict[str, Any], language_count: int = 5, stop_at_other: bool = False, /): def prep_content(stats: dict[str, Any], /):
"""WakaReadme Prepare Markdown. """WakaReadme Prepare Markdown.
Prepared markdown content from the fetched statistics. Prepared markdown content from the fetched statistics.
@ -306,17 +307,19 @@ def prep_content(stats: dict[str, Any], language_count: int = 5, stop_at_other:
max((str(lng["name"]) for lng in lang_info), key=len) max((str(lng["name"]) for lng in lang_info), key=len)
# and then do not for get to set `pad_len` to say 13 :) # and then do not for get to set `pad_len` to say 13 :)
) )
if language_count == 0 and not stop_at_other: language_count, stop_at_other = int(wk_i.language_count), bool(wk_i.stop_at_other)
if language_count == 0 and not wk_i.stop_at_other:
logger.debug( logger.debug(
"Set INPUT_LANG_COUNT to -1 to retrieve all language" "Set INPUT_LANG_COUNT to -1 to retrieve all language"
+ " or specify a positive number (ie. above 0)" + " or specify a positive number (ie. above 0)"
) )
return contents.rstrip("\n") return contents.rstrip("\n")
ignored_languages = set[str](igl.lower() for igl in wk_i.ignored_languages.strip().split())
for idx, lang in enumerate(lang_info): for idx, lang in enumerate(lang_info):
lang_name = str(lang["name"]) lang_name = str(lang["name"])
# >>> add languages to filter here <<< if ignored_languages and lang_name.lower() in ignored_languages:
# if lang_name in {...}: continue continue
lang_time = str(lang["text"]) if wk_i.show_time else "" lang_time = str(lang["text"]) if wk_i.show_time else ""
lang_ratio = float(lang["percent"]) lang_ratio = float(lang["percent"])
lang_bar = make_graph(wk_i.block_style, lang_ratio, wk_i.graph_length, lang_name) lang_bar = make_graph(wk_i.block_style, lang_ratio, wk_i.graph_length, lang_name)
@ -393,9 +396,7 @@ def churn(old_readme: str, /):
sys.exit(1) sys.exit(1)
# preparing contents # preparing contents
try: try:
generated_content = prep_content( generated_content = prep_content(waka_stats)
waka_stats, int(wk_i.language_count), bool(wk_i.stop_at_other)
)
except (AttributeError, KeyError, ValueError) as err: except (AttributeError, KeyError, ValueError) as err:
logger.error(f"Unable to read API data | {err}\n") logger.error(f"Unable to read API data | {err}\n")
sys.exit(1) sys.exit(1)