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..c46ffa584 100644 --- a/scripts/confirm-environment-owner/owner-notification.py +++ b/scripts/confirm-environment-owner/owner-notification.py @@ -10,35 +10,60 @@ # Using argparse instead of sys.argv. +EMAIL_BODY_TEMPLATE = """ +Hello, + +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. """ + 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 fileds 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) - # This list are the parameters being added which are used by the gov notify template. + # Prepare the dynamic subject + subject = f"Modernisation Platform – Review & confirm owner contact details – {env_name}" + + # This list is the parameters being used populate the email. 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(