Skip to content

Commit

Permalink
Merge pull request #2707 from wellcomecollection/workflow-dispatch-ev…
Browse files Browse the repository at this point in the history
…ent-from-suppression-script

Workflow dispatch event from suppression script
  • Loading branch information
agnesgaroux authored Sep 18, 2024
2 parents e11dcb7 + 628f2e8 commit cc5f117
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 116 deletions.
45 changes: 0 additions & 45 deletions scripts/generate_miro_image_suppressions_table.py

This file was deleted.

81 changes: 10 additions & 71 deletions scripts/miro_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import datetime
import functools
import itertools
import json
import sys
import re
import os

import boto3
import httpx
Expand All @@ -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
Expand Down Expand Up @@ -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("<table>\n")
outfile.write("<tr>\n")
outfile.write(" <th>Miro ID</th>\n")
outfile.write(" <th>Suppression date</th>\n")
outfile.write(" <th>Reason</th>\n")
outfile.write("</tr>\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("<tr>\n")
outfile.write(f' <td>{"<br>".join(ev["id"] for ev in events)}</td>\n')
outfile.write(f' <td>{date.strftime("%-d %B %Y")}</td>\n')
outfile.write(f" <td>{message}\n")
outfile.write("</tr>\n")

outfile.write("</table>\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):
Expand Down

0 comments on commit cc5f117

Please sign in to comment.