From 8ffb95d479a4f6514397eaabf06f28603e706499 Mon Sep 17 00:00:00 2001 From: Erwin Lejeune Date: Mon, 28 Nov 2022 15:30:28 +0400 Subject: [PATCH] Customizable Section Name --- CONTRIBUTING.md | 1 + README.md | 3 ++- action.yml | 5 +++++ main.py | 15 +++++++++++---- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a7a851f..89b3876 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,6 +58,7 @@ INPUT_REPOSITORY='' INPUT_COMMIT_MESSAGE='' INPUT_SHOW_TITLE='True' + INPUT_SECTION_NAME='wakacustom' INPUT_BLOCKS='->' INPUT_SHOW_TIME='True' INPUT_SHOW_TOTAL='True' diff --git a/README.md b/README.md index 90aadbc..ea5e588 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Alternatively, you can also fetch data from WakaTime compatible services like [W A GitHub repository and a README file is required. We'll be making use of readme in the [profile repository][profile_readme]\*. -- Save the README file after copy-pasting the following special comments. Your dev-metics will show up in between. +- Save the README file after copy-pasting the following special comments. Your dev-metics will show up in between. `waka` here can be replaced by any string as long as you set the `SECTION_NAME` environment variable [as per the Tweaks section](tweaks). ```md @@ -78,6 +78,7 @@ There are many flags that you can tweak to suit your taste! | ------------------ | -------------------------------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | | `API_BASE_URL` | `https://wakatime.com/api` | `https://wakatime.com/api`, `https://wakapi.dev/api`, `https://hakatime.mtx-dev.xyz/api` | Integration with WakaTime compatible services like [Wakapi][wakapi] & [Hakatime][hakatime] are possible | | `REPOSITORY` | `/` | `/` | Waka-readme stats will appear on the provided repository | +| `SECTION_NAME` | `waka` | `any string` | The generator will look for this section to fill up the readme. | | `COMMIT_MESSAGE` | `Updated waka-readme graph with new metrics` | anything else! | Messaged used when committing updated stats | | `SHOW_TITLE` | `false` | `false`, `true` | Add title to waka-readme stats blob | | `BLOCKS` | `░▒▓█` | `░▒▓█`, `⣀⣄⣤⣦⣶⣷⣿`, `-#`, you can be creative! | Ascii art used to build stats graph | diff --git a/action.yml b/action.yml index cea07fe..c815851 100644 --- a/action.yml +++ b/action.yml @@ -34,6 +34,11 @@ inputs: default: "false" required: false + 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: "░▒▓█" diff --git a/main.py b/main.py index 22efe5e..4260000 100644 --- a/main.py +++ b/main.py @@ -66,10 +66,16 @@ class WakaConstants: """ prefix_length: int = 16 graph_length: int = 25 - start_comment: str = '' - end_comment: str = '' + section: str = os.getenv("INPUT_SECTION_NAME", "waka") + start_comment: str = f'' + end_comment: str = f'' waka_block_pattern: str = f'{start_comment}[\\s\\S]+{end_comment}' + def validate_constants(self) -> bool: + if not (self.section): + logger.error('Invalid section name input, refer README') + return False + class WakaInput: """ @@ -336,7 +342,7 @@ def churn(old_readme: str, /) -> str | None: if not (waka_stats := fetch_stats()): logger.error('Unable to fetch data, please rerun workflow') sys.exit(1) - + # processing content generated_content = prep_content(waka_stats) print(generated_content, '\n', sep='') @@ -350,6 +356,7 @@ def churn(old_readme: str, /) -> str | None: # to avoid accidentally writing back to Github # when developing and testing WakaReadme return None + return None if new_readme == old_readme else new_readme @@ -411,7 +418,7 @@ if __name__ == '__main__': logger.debug('Initialize WakaReadme') wk_c = WakaConstants() wk_i = WakaInput() - if not wk_i.validate_input(): + if not (wk_i.validate_input() or wk_i.validate_constants()): logger.error('Environment variables are misconfigured') sys.exit(1) logger.debug('Input validation complete')