Skip to content

Commit

Permalink
Add base branch parameter for filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
philnewm committed Nov 26, 2024
1 parent 4faa94e commit 9f88ae4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
12 changes: 8 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ inputs:
repo:
description: Repository to query data from in the format of <owner>/<repo-name>
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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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}"
Expand Down
15 changes: 9 additions & 6 deletions github_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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"))
Expand All @@ -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
Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <owner><repo>
Returns:
Expand All @@ -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
Expand Down

0 comments on commit 9f88ae4

Please sign in to comment.