From a167195d986fe15be2183bb09be940bf11b65c7d Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Thu, 16 Jan 2025 16:41:54 +0000 Subject: [PATCH 1/4] Update Confirm contacts notification to use generic template --- .../confirm-contacts-for-environments.yml | 2 +- .../owner-notification.py | 38 ++++++++++++++----- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/.github/workflows/confirm-contacts-for-environments.yml b/.github/workflows/confirm-contacts-for-environments.yml index 203fbe0c0..21d2655ab 100644 --- a/.github/workflows/confirm-contacts-for-environments.yml +++ b/.github/workflows/confirm-contacts-for-environments.yml @@ -11,7 +11,7 @@ env: GITHUB_REPO: ${{ github.repository }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} API_KEY: ${{ secrets.GOV_UK_NOTIFY_API_KEY }} - TEMPLATE_ID: "93afef96-ea0b-470f-bd20-edf44e0acdb9" + TEMPLATE_ID: "1f0f5ccc-0f67-4ee2-942f-6e48804828ea" PERIOD: "6" # This variable determines the number of months we look back for created dates. For production it will be 6. defaults: diff --git a/scripts/confirm-environment-owner/owner-notification.py b/scripts/confirm-environment-owner/owner-notification.py index 1eb240152..1893b2661 100644 --- a/scripts/confirm-environment-owner/owner-notification.py +++ b/scripts/confirm-environment-owner/owner-notification.py @@ -3,22 +3,35 @@ import argparse from notifications_python_client.notifications import NotificationsAPIClient -# Sends an email to the environment owner using Gov Notify with the following parameters: -# - The environment name -# - The owner email address -# - A link to the github issue generated by the calling script. +EMAIL_BODY_TEMPLATE = """ +Hello, -# Using argparse instead of sys.argv. +We are contacting you with a request that you confirm whether the contact details we hold in the tag.owner field for the ((environment)) environment are correct. + +The owner email address we have is ((owner)). We will use this should we ever need to contact you regarding the environment. + +You can confirm this by either: + +- Letting us know using the [#ask-modernisation-platform](https://moj.enterprise.slack.com/archives/C01A7QK5VM1) slack channel, +- Add a comment to the GitHub [issue](((link))), including the new email address if it has changed. +- Create a PR with the updated email address and contact us via the [#ask-modernisation-platform](https://moj.enterprise.slack.com/archives/C01A7QK5VM1) slack channel and we will review it. + +Thank you in advance for taking the time to confirm this information. + +Regards, + +Modernisation Platform Team +""" def send_email(env_name, issue_url, email_address): """ Sends an email notification using the Notify service. - Args: env_name: The name of the environment. issue_url: The URL of the issue to include in the email. email_address: The email address of the owner. """ + # Retrieve the API key and template ID from environment variables api_key = os.environ.get("API_KEY") template_id = os.environ.get("TEMPLATE_ID") if not api_key or not template_id: @@ -27,18 +40,23 @@ def send_email(env_name, issue_url, email_address): client = NotificationsAPIClient(api_key=api_key) - print("The are the data fileds defined in the Notify template which are used in the email:") + print("The are the data fields defined in the Notify template which are used in the email:") print(env_name) print(email_address) print(issue_url) + # Prepare the dynamic subject + subject = f"Modernisation Platform – Review & confirm owner contact details – {env_name}" + # This list are the parameters being added which are used by the gov notify template. personalisation = { "environment": env_name, "owner": email_address, - "link": issue_url + "link": issue_url, + "subject": subject, + "message": EMAIL_BODY_TEMPLATE.replace("((environment))", env_name).replace("((owner))", email_address).replace("((link))", issue_url) } - + # Send the email try: response = client.send_email_notification( @@ -46,7 +64,7 @@ def send_email(env_name, issue_url, email_address): template_id=template_id, personalisation=personalisation ) - print(f"Email successfully sent to {email_address}. Response: {response}") + print(f"Email successfully sent to {email_address}. Response ID: {response['id']}") except Exception as e: print(f"Failed to send email: {e}") sys.exit(1) From a3b9fbd831706938584b195dc10174145c5c7bee Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Fri, 17 Jan 2025 08:52:08 +0000 Subject: [PATCH 2/4] fix typo --- scripts/confirm-environment-owner/owner-notification.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/confirm-environment-owner/owner-notification.py b/scripts/confirm-environment-owner/owner-notification.py index 1893b2661..21d9e8fe0 100644 --- a/scripts/confirm-environment-owner/owner-notification.py +++ b/scripts/confirm-environment-owner/owner-notification.py @@ -31,16 +31,16 @@ def send_email(env_name, issue_url, email_address): issue_url: The URL of the issue to include in the email. email_address: The email address of the owner. """ - # Retrieve the API key and template ID from environment variables + api_key = os.environ.get("API_KEY") template_id = os.environ.get("TEMPLATE_ID") if not api_key or not template_id: print("Error: API_KEY and TEMPLATE_ID must be set in environment variables.") sys.exit(1) - + client = NotificationsAPIClient(api_key=api_key) - print("The are the data fields defined in the Notify template which are used in the email:") + print("These are the data fields defined in the Notify template which are used in the email:") print(env_name) print(email_address) print(issue_url) @@ -64,7 +64,7 @@ def send_email(env_name, issue_url, email_address): template_id=template_id, personalisation=personalisation ) - print(f"Email successfully sent to {email_address}. Response ID: {response['id']}") + print(f"Email successfully sent to {email_address}. Response: {response}") except Exception as e: print(f"Failed to send email: {e}") sys.exit(1) From 305ad1a05301f832a1d25afc651ba5328932e349 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Fri, 17 Jan 2025 09:03:19 +0000 Subject: [PATCH 3/4] update comments --- scripts/confirm-environment-owner/owner-notification.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/confirm-environment-owner/owner-notification.py b/scripts/confirm-environment-owner/owner-notification.py index 21d9e8fe0..316a346f1 100644 --- a/scripts/confirm-environment-owner/owner-notification.py +++ b/scripts/confirm-environment-owner/owner-notification.py @@ -40,7 +40,7 @@ def send_email(env_name, issue_url, email_address): client = NotificationsAPIClient(api_key=api_key) - print("These are the data fields defined in the Notify template which are used in the email:") + print("These are the data fields being passed in to populate the email:") print(env_name) print(email_address) print(issue_url) @@ -48,7 +48,7 @@ def send_email(env_name, issue_url, email_address): # Prepare the dynamic subject subject = f"Modernisation Platform – Review & confirm owner contact details – {env_name}" - # This list are the parameters being added which are used by the gov notify template. + # This list is the parameters being used populate the email. personalisation = { "environment": env_name, "owner": email_address, From 608a3d3e6097c17cd915bcab53b55874cd3eb340 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Fri, 17 Jan 2025 09:05:17 +0000 Subject: [PATCH 4/4] re-add missing comments --- scripts/confirm-environment-owner/owner-notification.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/confirm-environment-owner/owner-notification.py b/scripts/confirm-environment-owner/owner-notification.py index 316a346f1..c46ffa584 100644 --- a/scripts/confirm-environment-owner/owner-notification.py +++ b/scripts/confirm-environment-owner/owner-notification.py @@ -3,6 +3,13 @@ import argparse from notifications_python_client.notifications import NotificationsAPIClient +# Sends an email to the environment owner using Gov Notify with the following parameters: +# - The environment name +# - The owner email address +# - A link to the github issue generated by the calling script. + +# Using argparse instead of sys.argv. + EMAIL_BODY_TEMPLATE = """ Hello,