From 9f88ae4e4fb8ab22afd5642f352e2b01f15eb5f8 Mon Sep 17 00:00:00 2001 From: PhilNewm Date: Tue, 26 Nov 2024 15:49:04 +0100 Subject: [PATCH] Add base branch parameter for filtering --- action.yml | 12 ++++++++---- github_query.py | 15 +++++++++------ src/queries.py | 4 +++- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/action.yml b/action.yml index 488e0ef..8732c18 100644 --- a/action.yml +++ b/action.yml @@ -13,8 +13,12 @@ inputs: repo: description: Repository to query data from in the format of / required: true + base_branch: + description: Only filter for PRs merged into this branch + required: true + default: "develop" date: - description: Starting date to start query from. + description: Starting date to start query from required: true query_parameters: description: Parameters to query for in pr Information @@ -58,7 +62,7 @@ runs: shell: bash run: | cd $GITHUB_ACTION_PATH - label_list=$(python github_query.py pr-labels "${{ inputs.repo }}" "${{ inputs.query_parameters }}" "${{ inputs.date }}") + label_list=$(python github_query.py pr-labels "${{ inputs.repo }}" "${{ inputs.base_branch }}" "${{ inputs.query_parameters }}" "${{ inputs.date }}") echo "label_list=$label_list" >> $GITHUB_OUTPUT @@ -67,7 +71,7 @@ runs: shell: bash run: | cd $GITHUB_ACTION_PATH - increment=$(python github_query.py version-increment "${{ inputs.repo }}" "${{ inputs.query_parameters }}" "${{ inputs.date }}") + increment=$(python github_query.py version-increment "${{ inputs.repo }}" "${{ inputs.base_branch }}" "${{ inputs.query_parameters }}" "${{ inputs.date }}") echo "increment=$increment" >> $GITHUB_OUTPUT @@ -81,7 +85,7 @@ runs: shell: bash run: | cd $GITHUB_ACTION_PATH - changelog=$(python github_query.py generate-release-changelog "${{ inputs.repo }}" "${{ inputs.query_parameters }}" "${{ inputs.date }}" "${{ inputs.changelog_labels }}") + changelog=$(python github_query.py generate-release-changelog "${{ inputs.repo }}" "${{ inputs.base_branch }}" "${{ inputs.query_parameters }}" "${{ inputs.date }}" "${{ inputs.changelog_labels }}") delimiter="$(openssl rand -hex 8)" { echo "changelog<<${delimiter}" diff --git a/github_query.py b/github_query.py index 3cd1eb6..5b764aa 100644 --- a/github_query.py +++ b/github_query.py @@ -15,9 +15,10 @@ def cli() -> None: @cli.command() @click.argument('repo_name', type=click.STRING) +@click.argument('base_branch', type=click.STRING) @click.argument('query_tags', type=click.STRING) @click.argument('latest_release_date', type=click.STRING) -def pr_labels(latest_release_date: str, query_tags: str, repo_name: str) -> None: +def pr_labels(latest_release_date: str, query_tags: str, base_branch: str, repo_name: str) -> None: """Get a list of all version relevant PR labels. latest_release_date (str): datatime string\n @@ -26,7 +27,7 @@ def pr_labels(latest_release_date: str, query_tags: str, repo_name: str) -> None """ query_tags_list: List[str] = conversion_logic.csv_string_to_list(input=query_tags) - pr_result: List[dict[str, str]] = queries.query_merged_prs(latest_release_date, query_tags_list, repo_name) + pr_result: List[dict[str, str]] = queries.query_merged_prs(latest_release_date, query_tags_list, base_branch, repo_name) pr_labels: List[str] = conversion_logic.filter_unique_labels(pr_data=pr_result) if not pr_labels: @@ -38,9 +39,10 @@ def pr_labels(latest_release_date: str, query_tags: str, repo_name: str) -> None @cli.command() @click.argument('repo_name', type=click.STRING) +@click.argument('base_branch', type=click.STRING) @click.argument('query_tags', type=click.STRING) @click.argument('latest_release_date', type=click.STRING) -def version_increment(latest_release_date: str, query_tags: str, repo_name: str): +def version_increment(latest_release_date: str, query_tags: str, base_branch: str, repo_name: str) -> None: """Output a calculated version increment suggestion. latest_release_date (str): datetime string\n @@ -49,7 +51,7 @@ def version_increment(latest_release_date: str, query_tags: str, repo_name: str) """ query_tags_list: list[str] = conversion_logic.csv_string_to_list(query_tags) - pr_result: list[dict[str, str]] = queries.query_merged_prs(latest_release_date, query_tags_list, repo_name) + pr_result: list[dict[str, str]] = queries.query_merged_prs(latest_release_date, query_tags_list, base_branch, repo_name) pr_labels: conversion_logic.List[str] = conversion_logic.filter_unique_labels(pr_data=pr_result) patch_repo_var_list: conversion_logic.List[str] = conversion_logic.csv_string_to_list(queries.get_repo_var(repo=repo_name, var_name="PATCH_BUMP_LABEL")) minor_repo_var_list: conversion_logic.List[str] = conversion_logic.csv_string_to_list(queries.get_repo_var(repo=repo_name, var_name="MINOR_BUMP_LABEL")) @@ -60,10 +62,11 @@ def version_increment(latest_release_date: str, query_tags: str, repo_name: str) @cli.command() @click.argument('repo_name', type=click.STRING) +@click.argument('base_branch', type=click.STRING) @click.argument('query_tags', type=click.STRING) @click.argument('latest_release_date', type=click.STRING) @click.argument('changelog_labels', type=click.STRING) -def generate_release_changelog(latest_release_date: str, query_tags: str, repo_name: str, changelog_labels: str) -> None: +def generate_release_changelog(latest_release_date: str, query_tags: str, base_branch: str, repo_name: str, changelog_labels: str) -> None: """Output a markdown formatted changelog. latest_release_date (str): datetime string\n @@ -72,7 +75,7 @@ def generate_release_changelog(latest_release_date: str, query_tags: str, repo_n """ query_tags_list: list[str] = conversion_logic.csv_string_to_list(query_tags) - pr_result: list[dict[str, str]] = queries.query_merged_prs(latest_release_date, query_tags_list, repo_name) + pr_result: list[dict[str, str]] = queries.query_merged_prs(latest_release_date, query_tags_list, base_branch, repo_name) changelog_labels_result: list[str] = conversion_logic.csv_string_to_list(changelog_labels) pr_filtered: list[conversion_logic.Changelog] = conversion_logic.filter_changes_per_label(pr_data=pr_result, changelog_label_list=changelog_labels_result) markdown_changelog: str = conversion_logic.format_changelog_markdown(changes=pr_filtered, changelog_label_list=changelog_labels_result) diff --git a/src/queries.py b/src/queries.py index 88159ee..44e2fd3 100644 --- a/src/queries.py +++ b/src/queries.py @@ -2,12 +2,13 @@ import subprocess -def query_merged_prs(latest_release_date: str, query_tags: list[str], repo_name: str) -> list[dict[str, str]]: +def query_merged_prs(latest_release_date: str, query_tags: list[str], base_branch: str, repo_name: str) -> list[dict[str, str]]: """Run gh pull request query. Args: latest_release_date (str): datetime string query_tags (str): csv string + base_branch (str): PRs merged into this branch repo_name (str): repo name as Returns: @@ -18,6 +19,7 @@ def query_merged_prs(latest_release_date: str, query_tags: list[str], repo_name: [ "gh", "pr", "list", "--state", "merged", + "--base", base_branch, "--search", f'merged:>={latest_release_date}', "--json", ','.join(query_tags), "--repo", repo_name