Skip to content

Commit

Permalink
Refactor cli call to use click
Browse files Browse the repository at this point in the history
  • Loading branch information
philnewm committed Oct 19, 2024
1 parent 5257cf3 commit d5cfd4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
17 changes: 7 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
...
16 changes: 10 additions & 6 deletions github_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""

Expand Down Expand Up @@ -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()

0 comments on commit d5cfd4e

Please sign in to comment.