From f210450922526a1c7b92a3a880ba29be7091e748 Mon Sep 17 00:00:00 2001 From: Matthias Goerens Date: Thu, 16 Oct 2025 15:16:25 +0200 Subject: [PATCH] Get metadata from submission object This is a follow-up of #456 that also removes unused code Signed-off-by: Matthias Goerens --- .../check-locks-on-owners-submission.yml | 20 ++----- .github/workflows/mercury_bot.yml | 16 +---- .github/workflows/owners-redhat.yml | 2 +- scripts/setup.cfg | 1 - scripts/src/pullrequest/check_for_owners.py | 4 ++ scripts/src/pullrequest/prartifact.py | 60 ------------------- 6 files changed, 13 insertions(+), 90 deletions(-) diff --git a/.github/workflows/check-locks-on-owners-submission.yml b/.github/workflows/check-locks-on-owners-submission.yml index a36c6699..eb88d8b7 100644 --- a/.github/workflows/check-locks-on-owners-submission.yml +++ b/.github/workflows/check-locks-on-owners-submission.yml @@ -69,16 +69,6 @@ jobs: console.log(`setting output: net-new-owners-file=${ownersFile.status == 'added'}`); core.setOutput('net-new-owners-file', ownersFile.status == 'added'); - - name: Add category/organization/chart-name from modified file to GITHUB_OUTPUT - id: gather-metadata - env: - API_URL: ${{ github.event.pull_request._links.self.href }} - BOT_TOKEN: ${{ secrets.BOT_TOKEN }} - run: | - ./ve1/bin/extract-metadata-from-pr \ - --emit-to-github-output \ - "${API_URL}" - # Only used to assert content of the OWNERS file. - name: Checkout Pull Request uses: actions/checkout@v4 @@ -94,8 +84,8 @@ jobs: id: fact-check env: PR_FILES: ${{ steps.check_for_owners.outputs.pr_files }} - CHART_NAME: ${{ steps.gather-metadata.outputs.chart-name }} - ORGANIZATION: ${{ steps.gather-metadata.outputs.organization }} + CHART_NAME: ${{ steps.check_for_owners.outputs.chart-name }} + ORGANIZATION: ${{ steps.check_for_owners.outputs.organization }} run: | file=$(yq .0 <<< ${PR_FILES}) owner_contents_chart_name=$(yq '.chart.name' ${file}) @@ -125,7 +115,7 @@ jobs: id: determine-lock-status uses: ./.github/actions/check-chart-locks with: - chart-name: ${{ steps.gather-metadata.outputs.chart-name }} + chart-name: ${{ steps.check_for_owners.outputs.chart-name }} fail-workflow-if-locked: 'false' - name: Comment on PR if chart is locked @@ -143,7 +133,7 @@ jobs: | chart name | lock path | | - | - | - | ${{ steps.gather-metadata.outputs.chart-name }} | ${{ steps.determine-lock-status.outputs.locked-to-path }} | + | ${{ steps.check_for_owners.outputs.chart-name }} | ${{ steps.determine-lock-status.outputs.locked-to-path }} | This OWNERS file is being ${{ steps.populate-file-mod-type.outputs.net-new-owners-file == 'true' && '**created**' || '**modified**'}} in this pull request. @@ -162,7 +152,7 @@ jobs: The OWNERS file contributed here has a chart name that is **AVAILABLE**! - The chart name '${{ steps.gather-metadata.outputs.chart-name }}' does not appear in our lockfile. + The chart name '${{ steps.check_for_owners.outputs.chart-name }}' does not appear in our lockfile. After reviewing this pull request, please re-run this workflow once more before merging. diff --git a/.github/workflows/mercury_bot.yml b/.github/workflows/mercury_bot.yml index 8f1c54f0..bc4e8f18 100644 --- a/.github/workflows/mercury_bot.yml +++ b/.github/workflows/mercury_bot.yml @@ -63,16 +63,6 @@ jobs: console.log(`setting output: net-new-owners-file=${ownersFile.status == 'added'}`); core.setOutput('net-new-owners-file', ownersFile.status == 'added'); - - name: Add category/organization/chart-name from modified file to GITHUB_OUTPUT - id: gather-metadata - env: - API_URL: ${{ github.event.pull_request._links.self.href }} - BOT_TOKEN: ${{ secrets.BOT_TOKEN }} - run: | - ./ve1/bin/extract-metadata-from-pr \ - --emit-to-github-output \ - "${API_URL}" - # Only used to assert content of the OWNERS file. - name: Checkout Pull Request uses: actions/checkout@v4 @@ -91,8 +81,8 @@ jobs: id: fact-check env: PR_FILES: ${{ steps.check_for_owners.outputs.pr_files }} - CHART_NAME: ${{ steps.gather-metadata.outputs.chart-name }} - ORGANIZATION: ${{ steps.gather-metadata.outputs.organization }} + CHART_NAME: ${{ steps.check_for_owners.outputs.chart-name }} + ORGANIZATION: ${{ steps.check_for_owners.outputs.organization }} run: | file=$(yq .0 <<< ${PR_FILES}) owner_contents_chart_name=$(yq '.chart.name' ${file}) @@ -122,7 +112,7 @@ jobs: id: determine-lock-status uses: ./.github/actions/check-chart-locks with: - chart-name: ${{ steps.gather-metadata.outputs.chart-name }} + chart-name: ${{ steps.check_for_owners.outputs.chart-name }} fail-workflow-if-locked: 'false' # Do not merge net-new OWNERS files for locked chart names. Allow a diff --git a/.github/workflows/owners-redhat.yml b/.github/workflows/owners-redhat.yml index 4ccf27e2..a088b747 100644 --- a/.github/workflows/owners-redhat.yml +++ b/.github/workflows/owners-redhat.yml @@ -55,7 +55,7 @@ jobs: working-directory: scripts run: | make venv.tools - + - name: Gather Metadata id: gather-metadata env: diff --git a/scripts/setup.cfg b/scripts/setup.cfg index d18100a1..44ca735f 100644 --- a/scripts/setup.cfg +++ b/scripts/setup.cfg @@ -34,7 +34,6 @@ console_scripts = chart-repo-manager = chartrepomanager.chartrepomanager:main chart-pr-review = chartprreview.chartprreview:main validate-submission = submission.validate:main - pr-artifact = pullrequest.prartifact:main pr-comment = pullrequest.prepare_pr_comment:main sa-for-chart-testing = saforcharttesting.saforcharttesting:main check-auto-merge = checkautomerge.checkautomerge:main diff --git a/scripts/src/pullrequest/check_for_owners.py b/scripts/src/pullrequest/check_for_owners.py index bd1de272..86b7f6cf 100644 --- a/scripts/src/pullrequest/check_for_owners.py +++ b/scripts/src/pullrequest/check_for_owners.py @@ -65,6 +65,10 @@ def main(): ) sys.exit(30) + gitutils.add_output("category", s.chart.category) + gitutils.add_output("organization", s.chart.organization) + gitutils.add_output("chart-name", s.chart.name) + if __name__ == "__main__": main() diff --git a/scripts/src/pullrequest/prartifact.py b/scripts/src/pullrequest/prartifact.py index 14c366f0..bc3754e3 100644 --- a/scripts/src/pullrequest/prartifact.py +++ b/scripts/src/pullrequest/prartifact.py @@ -1,32 +1,13 @@ -import argparse import os import sys - import requests -sys.path.append("../") -from reporegex import matchers -from tools import gitutils - pr_files = [] pr_labels = [] xRateLimit = "X-RateLimit-Limit" xRateRemain = "X-RateLimit-Remaining" -# TODO(baijum): Move this code under chartsubmission.chart module -def get_modified_charts(api_url): - files = get_modified_files(api_url) - pattern, _, _ = matchers.get_file_match_compiled_patterns() - for file in files: - match = pattern.match(file) - if match: - category, organization, chart, version = match.groups() - return category, organization, chart, version - - return "", "", "", "" - - def get_modified_files(api_url): """Populates and returns the list of files modified by this the PR @@ -91,44 +72,3 @@ def get_labels(api_url): pr_labels.append(label["name"]) return pr_labels - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument( - "-d", - "--directory", - dest="directory", - type=str, - required=False, - help="artifact directory for archival", - ) - parser.add_argument( - "-n", - "--pr-number", - dest="number", - type=str, - required=False, - help="current pull request number", - ) - parser.add_argument( - "-u", - "--api-url", - dest="api_url", - type=str, - required=True, - help="API URL for the pull request", - ) - parser.add_argument( - "-f", "--get-files", dest="get_files", default=False, action="store_true" - ) - - args = parser.parse_args() - if args.get_files: - pr_files = get_modified_files(args.api_url) - print(f"[INFO] files in pr: {pr_files}") - gitutils.add_output("pr_files", pr_files) - - -if __name__ == "__main__": - main()