From d5cfd4e62952542549d0c9f3d7455738060059f4 Mon Sep 17 00:00:00 2001 From: PhilNewm Date: Sat, 19 Oct 2024 09:41:16 +0200 Subject: [PATCH] Refactor cli call to use click --- action.yml | 17 +++++++---------- github_query.py | 16 ++++++++++------ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/action.yml b/action.yml index c50d6d4..926617d 100644 --- a/action.yml +++ b/action.yml @@ -71,15 +71,12 @@ runs: increment=$(python -c 'import github_query; pr_labels = github_query.get_labels(github_query.parse_args()); patch_repo_var = github_query.get_repo_var(repo="${{ inputs.repo }}", var_name="PATCH_BUMP_LABEL"); minor_repo_var = github_query.get_repo_var(repo="${{ inputs.repo }}", var_name="MINOR_BUMP_LABEL"); print(github_query.get_version_increment(patch_bump_list=patch_repo_var, minor_bump_list=minor_repo_var, pr_label_list=pr_labels))' "${{ inputs.repo }}" "${{ inputs.query_parameters }}" "${{ inputs.date }}") echo "increment=$increment" >> $GITHUB_OUTPUT - # disabled until fixed - # - name: Prepare Changelog - # id: write-changelog - # shell: bash - # run: | - # cd $GITHUB_ACTION_PATH - # changelog=$(python -c 'import github_query; gh_query = github_query.parse_args(); patch_repo_var = github_query.get_repo_var(repo="${{ inputs.repo }}", var_name="PATCH_BUMP_LABEL"); minor_repo_var = github_query.get_repo_var(repo="${{ inputs.repo }}", var_name="MINOR_BUMP_LABEL"); print(github_query.prepare_changelog_markdown(pr_query=gh_query, minor_bump_list=minor_repo_var, patch_bump_list=patch_repo_var))' "${{ inputs.repo }}" "${{ inputs.query_parameters }}" "${{ inputs.date }}") - # oneline_changelog=$(echo "$changelog" | base64 | tr -d '/n') - # echo "oneline changelog: $oneline_changelog" - # # echo "changelog=$oneline_changelog" >> $GITHUB_OUTPUT + - name: Prepare Changelog + id: write-changelog + shell: bash + run: | + cd $GITHUB_ACTION_PATH + changelog=$(python github_query.py generate-release-changelog) + echo "changelog=$changelog" >> $GITHUB_OUTPUT ... diff --git a/github_query.py b/github_query.py index c29d12c..3eb87ab 100644 --- a/github_query.py +++ b/github_query.py @@ -4,6 +4,7 @@ Additionally it's test suite relies mainly on pytest and therefore the functions need to be importable to the pytest script. """ +import click import json import logging import re @@ -17,7 +18,6 @@ Changelog = namedtuple("Changelog", "labels title number url id") - # def parse_args() -> dict: # """Parse command-line arguments and store them in a global variable.""" @@ -187,19 +187,23 @@ def get_version_increment(patch_bump_list: list[str], minor_bump_list: list[str] return "" +@click.group() +def cli(): + pass + + +@cli.command() def generate_release_changelog() -> str: command: str = f"gh pr list --state merged --search 'merged:>=2024-08-01T11:29:22Z' --json body,labels,title,number,url,id --repo ynput/ayon-maya" pr_json = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) - pr_data: str = json.loads(pr_json.stdout) + pr_data: list[dict[str, str]] = json.loads(pr_json.stdout) changelog_labels: list[str] = ["type: bug", "type: enhancement", "type: maintenance"] - pr_filtered: Changelog = filter_changes_per_label(pr_data=pr_data, changelog_label_list=changelog_labels) + pr_filtered: list[Changelog] = filter_changes_per_label(pr_data=pr_data, changelog_label_list=changelog_labels) sorted_changes: list[Changelog] = sort_changes(changes_list=pr_filtered, changelog_label_list=changelog_labels) markdown_changelog: str = build_changelog_markdown(sorted_changes) - print(markdown_changelog) - return markdown_changelog if __name__ == "__main__": - generate_release_changelog() + cli()