diff --git a/scripts/generate_miro_image_suppressions_table.py b/scripts/generate_miro_image_suppressions_table.py deleted file mode 100755 index 26058c17d2..0000000000 --- a/scripts/generate_miro_image_suppressions_table.py +++ /dev/null @@ -1,45 +0,0 @@ -import contextlib -import os -import subprocess -import tempfile - -from _common import git, get_secret_string - - -@contextlib.contextmanager -def working_directory(path): - """ - Changes the working directory to the given path, then returns to the - original directory when done. - """ - prev_cwd = os.getcwd() - os.chdir(path) - try: - yield - finally: - os.chdir(prev_cwd) - - -@contextlib.contextmanager -def cloned_repo(git_url): - """ - Clones the repository and changes the working directory to the cloned - repo. Cleans up the clone when it's done. - """ - with tempfile.TemporaryDirectory() as repo_dir: - git( - "clone", - git_url, - repo_dir, - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - ) - - with working_directory(repo_dir): - yield - - -def get_github_api_key(sess): - return get_secret_string( - sess, secret_id="builds/github_wecobot/scala_libs_pr_bumps" - ) diff --git a/scripts/miro_updates.py b/scripts/miro_updates.py index e6a4e8a180..20c73763b0 100644 --- a/scripts/miro_updates.py +++ b/scripts/miro_updates.py @@ -5,10 +5,10 @@ import datetime import functools -import itertools import json import sys import re +import os import boto3 import httpx @@ -22,7 +22,6 @@ get_date_from_index_name, get_dynamodb_items, ) -from generate_miro_image_suppressions_table import cloned_repo, get_github_api_key SESSION = get_session(role_arn="arn:aws:iam::760097843905:role/platform-developer") DYNAMO_CLIENT = SESSION.resource("dynamodb").meta.client @@ -408,77 +407,17 @@ def get_all_miro_suppression_events(): def update_miro_image_suppressions_doc(): - print("*** Updating the list of Miro image suppressions...") - api_key = get_github_api_key(SESSION) - - client = httpx.Client( - auth=("weco-bot", api_key), - event_hooks={"response": [lambda r: r.raise_for_status()]}, + print( + "*** Creating a workflow_dispatch event for update_miro_suppressions_doc.yml in repo wellcomecollection/private ***" ) - with cloned_repo("git@github.com:wellcomecollection/private.git"): - with open("miro-suppressions.md", "w") as outfile: - today = datetime.date.today() - - outfile.write("# Miro image suppressions\n\n") - outfile.write(f"Last updated {today.strftime('%-d %B %Y')}\n") - outfile.write( - "Note: this file is autogenerated by a script in the catalogue-pipeline repo; any manual edits will be overwritten.\n\n" - ) - - outfile.write("\n") - outfile.write("\n") - outfile.write(" \n") - outfile.write(" \n") - outfile.write(" \n") - outfile.write("\n") - - for (date, message), events in itertools.groupby( - sorted( - get_all_miro_suppression_events(), - key=lambda e: e["date"], - reverse=True, - ), - key=lambda e: (e["date"].date(), e["message"]), - ): - outfile.write("\n") - outfile.write(f' \n') - outfile.write(f' \n') - outfile.write(f" \n") - - outfile.write("
Miro IDSuppression dateReason
{"
".join(ev["id"] for ev in events)}
{date.strftime("%-d %B %Y")}{message}\n") - outfile.write("
\n") - - branch_name = f"miro-suppressions-{today.strftime('%Y-%m-%d')}" - - git("checkout", "-b", branch_name) - git("add", "miro-suppressions.md") - git("commit", "-m", "update miro-suppressions.md") - git("push", "origin", branch_name, "--force", "--quiet") - - r = client.post( - "https://api.github.com/repos/wellcomecollection/private/pulls", - headers={"Accept": "application/vnd.github+json"}, - json={ - "head": branch_name, - "base": "main", - "title": f"Update miro-suppressions.md for {today.strftime('%-d %B %Y')}", - "maintainer_can_modify": True, - "body": f"This is an auto-generated update of the Miro suppressions table.\n\nView rendered version: https://github.com/wellcomecollection/private/blob/{branch_name}/miro-suppressions.md", - }, - ) - - new_pr_number = r.json()["number"] - - r = client.post( - f"https://api.github.com/repos/wellcomecollection/private/pulls/{new_pr_number}/requested_reviewers", - headers={"Accept": "application/vnd.github.v3+json"}, - json={"team_reviewers": ["developers"]}, - ) - - print( - f"*** To approve these changes, visit https://github.com/wellcomecollection/private/pull/{new_pr_number}" - ) + # create a workflow_dispatch event to trigger the update_miro_suppressions_doc.yml workflow + # the Github CLI is required + os.system( + f"gh workflow run update_miro_suppressions_doc.yml " + f"--repo wellcomecollection/private " + f"--field committer='{git('config', 'user.name')} <{git('config', 'user.email')}>'" + ) def register_on_dlcs(origin_url, miro_id):