diff --git a/action.yml b/action.yml index 3e8fe99..92534c9 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,7 @@ --- +# TODO need strategy where to store defaults - which an be overriden by repo vars + name: Github Release Information description: Fetch and convert data from github to use for a release trigger @@ -30,7 +32,7 @@ outputs: value: ${{ steps.bump-increment.outputs.increment }} changelog-markdown: description: String containing full makrdown syntax for release changelog information - value: "Default Value" # TODO changelog markdown string + value: ${{ steps.write-changelog.outputs.changelog }} runs: using: composite @@ -69,4 +71,12 @@ runs: increment=$(python -c 'import fetch_github_data; print(fetch_github_data.get_version_increment())' "${{ inputs.repo }}" "${{ inputs.query_parameters }}" "${{ inputs.date }}") echo "increment=$increment" >> $GITHUB_OUTPUT + - name: Get bump increment + id: write-changelog + shell: bash + run: | + cd $GITHUB_ACTION_PATH + increment=$(python -c 'import fetch_github_data; print(fetch_github_data.prepare_changelog_markdown())' "${{ inputs.repo }}" "${{ inputs.query_parameters }}" "${{ inputs.date }}") + echo "changelog=$changelog" >> $GITHUB_OUTPUT + ... diff --git a/fetch_github_data.py b/fetch_github_data.py index cadc47f..21823f6 100644 --- a/fetch_github_data.py +++ b/fetch_github_data.py @@ -66,22 +66,31 @@ def changelog_per_label(json_dict): if any(item in changelog_labels for item in labels): pass -def prepare_changelog_markdown(collect_inputs, get_changelog): - pr_output_list = [] - pr_output = {} +def prepare_changelog_markdown(): + repo_name, query_tags, latest_release_date = get_inputs() + pr_query = get_raw_output(repo_name=repo_name, query_tags=query_tags, latest_release_date=latest_release_date) + + minor_bump_label_list = get_repo_label(repo=repo_name, label_name="MINOR_BUMP_LABEL") + patch_bump_label_list = get_repo_label(repo=repo_name, label_name="PATCH_BUMP_LABEL") + + # ? should version bump labels also be filter for changelog ? + label_list = minor_bump_label_list + patch_bump_label_list + changelog = "" + + for pr in pr_query: + # get all label names in a list + pr_label_list = [label["name"] for label in pr["labels"]] + fitlered_label = list(set(label_list).intersection(pr_label_list))[0] # any(label in label_list for label in pr_label_list) + + if fitlered_label: + change_list = get_changelog(pr_data=pr["body"], changelog_start="## Changes") + + changelog += f"## {fitlered_label.capitalize()}\n" + changelog += "".join([f"* {change}\n" for change in change_list]) + changelog += "\n" + + return changelog - for pr_data in collect_inputs(): - labels = pr_data["labels"] - changelog_markdown = "" - - changelog_markdown =+ f"## {labels}" - pr_output["title"] = pr_data["title"] - pr_output["label_name"] = [label["name"] for label in pr_data["labels"]] - pr_output["changelog"] = get_changelog(pr_data=pr_data["body"], changelog_start="## Changes") # TODO udpate to "changelog" - - pr_output_list.append(pr_output) - - return pr_output_list def get_labels(): github_data = get_raw_output(*get_inputs()) @@ -93,25 +102,23 @@ def get_labels(): return json.dumps(list(labels)) -def get_version_increment(): - - repo_name, _, _ = get_inputs() - - minor_bump_label= subprocess.run( - ["gh", "variable", "get", "MINOR_BUMP_LABEL", "--repo", repo_name], +def get_repo_label(repo, label_name): + + label= subprocess.run( + ["gh", "variable", "get", label_name, "--repo", repo], capture_output=True, text=True, check=True ) - minor_bump_label_list = minor_bump_label.stdout.strip().split(", " or ",") - patch_bump_label= subprocess.run( - ["gh", "variable", "get", "PATCH_BUMP_LABEL", "--repo", "ynput/ayon-addon-action-testing"], - capture_output=True, - text=True, - check=True - ) - patch_bump_label_list = patch_bump_label.stdout.strip().split(", " or ",") + return label.stdout.strip().split(", " or ",") + +def get_version_increment(): + + repo_name, _, _ = get_inputs() + + minor_bump_label_list = get_repo_label(repo=repo_name, label_name="MINOR_BUMP_LABEL") + patch_bump_label_list = get_repo_label(repo=repo_name, label_name="PATCH_BUMP_LABEL") for label in json.loads(get_labels()): if label.lower() in minor_bump_label_list: