Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Confirm contacts notification to use generic template #8989

Merged
merged 4 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/confirm-contacts-for-environments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
37 changes: 31 additions & 6 deletions scripts/confirm-environment-owner/owner-notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading