Skip to content

Commit

Permalink
use send-email action
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Dec 29, 2023
1 parent c420f10 commit 699f37b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 236 deletions.
1 change: 0 additions & 1 deletion .github/scripts/python/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ verify_ssl = true
name = "pypi"

[packages]
requests = "==2.31.0"

[dev-packages]
black = "==23.1.0"
Expand Down
133 changes: 2 additions & 131 deletions .github/scripts/python/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 10 additions & 90 deletions .github/scripts/python/handle_new_contributor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,12 @@
import subprocess
from email.utils import parseaddr

import requests

# Global settings.
CONTRIBUTING_FILE_NAME = "CONTRIBUTING.md"
CONTRIBUTING_FILE_PATH = f"../../../{CONTRIBUTING_FILE_NAME}"
CONTRIBUTORS_HEADER = "### 👨\u200d💻 Contributors 👩\u200d💻"


def get_starter_info():
"""Gets the info needed to start this script.
Returns:
A tuple where the values are (the URL of the pull request, the
DotDigital API user's authorization).
"""

pr_url = os.getenv("PR_URL")
assert pr_url is not None, "Pull request URL environment variable not set."

# dd_api_user_email_address = os.getenv("DOTDIGITAL_API_USER_EMAIL_ADDRESS")
# assert (
# dd_api_user_email_address is not None
# ), "DotDigital API user email address environment variable not set."

# dd_api_user_password = os.getenv("DOTDIGITAL_API_USER_PASSWORD")
# assert (
# dd_api_user_password is not None
# ), "DotDigital API user password environment variable not set."

dd_api_user_auth = os.getenv("DOTDIGITAL_API_USER_AUTH")
assert (
dd_api_user_auth is not None
), "DotDigital API user authorization environment variable not set."

return pr_url, dd_api_user_auth


def fetch_main_branch():
"""Fetch main branch from origin."""

Expand Down Expand Up @@ -211,74 +180,25 @@ def get_email_address(diff_line_index: int, diff_line: str):
return signed_email_address


def send_verify_new_contributor_email(
pr_url: str,
dd_api_user_auth: str,
email_address: str,
):
"""Send an email to verify that the new contributor owns the email address.
https://developer.dotdigital.com/reference/send-transactional-email-using-a-triggered-campaign
Args:
pr_url: The URL of the pull request.
dd_api_user_auth: The DotDigital API user's authorization.
email_address: The new contributor's email address.
"""

response = requests.post(
url="https://r1-api.dotdigital.com/v2/email/triggered-campaign",
json={
"campaignId": 1506387,
"toAddresses": [
email_address,
],
"personalizationValues": [
{
"name": "PR_URL",
"value": pr_url,
},
],
},
headers={
"accept": "text/plain",
"authorization": dd_api_user_auth,
},
timeout=60,
)

assert response.ok, response.json()


def main():
"""Runs the scripts."""
def write_to_github_env(**env_vars):
"""Write the environment variables to GitHub's environment."""

with open(os.environ["GITHUB_ENV"], "a", encoding="utf-8") as github_env:
github_env.write(
"\n".join(
[
f"{key}={value}"
for key, value in {
"HELLO": "WORLD",
"FOO": "POW",
}.items()
]
)
"\n".join([f"{key}={value}" for key, value in env_vars.items()])
)

# pr_url, dd_api_user_auth = get_starter_info()

# fetch_main_branch()
def main():
"""Runs the scripts."""

fetch_main_branch()

# diff_line_index, diff_line = get_diff_line()
diff_line_index, diff_line = get_diff_line()

# email_address = get_email_address(diff_line_index, diff_line)
email_address = get_email_address(diff_line_index, diff_line)

# send_verify_new_contributor_email(
# pr_url,
# dd_api_user_auth,
# email_address="[email protected]",
# )
write_to_github_env(CONTRIBUTOR_EMAIL_ADDRESS=email_address)


if __name__ == "__main__":
Expand Down
25 changes: 11 additions & 14 deletions .github/workflows/contributing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,20 @@ jobs:
handle_new_contributor:
runs-on: ubuntu-latest
steps:
# - uses: ocadotechnology/codeforlife-workspace/.github/actions/python/setup-environment@new_contributor_validations # TODO: use @main
# with:
# python-version: ${{ env.PYTHON_VERSION }}
# working-directory: ${{ env.WORKING_DIR }}
# install-args: "--dev"
- uses: ocadotechnology/codeforlife-workspace/.github/actions/python/setup-environment@new_contributor_validations # TODO: use @main
with:
python-version: ${{ env.PYTHON_VERSION }}
working-directory: ${{ env.WORKING_DIR }}
install-args: "--dev"

# - name: 🏃 Run Script
# working-directory: ${{ env.WORKING_DIR }}
# run: pipenv run python handle_new_contributor.py
# env:
# PR_URL: ${{ github.event.pull_request.url }}
# DOTDIGITAL_API_USER_AUTH: ${{ secrets.DOTDIGITAL_API_USER_AUTH }}
- name: 🕵️ Validate New Contributor
working-directory: ${{ env.WORKING_DIR }}
run: pipenv run python handle_new_contributor.py

- name: 📧 Send Email
- name: 📧 Send Verification Email
uses: ocadotechnology/codeforlife-workspace/.github/actions/python/send-email@new_contributor_validations # TODO: use @main
with:
auth: ${{ secrets.DOTDIGITAL_API_USER_AUTH }}
to-addresses: '["[email protected]"]' #${{ env.TO_ADDRESSES }}
to-addresses: '["${{ env.CONTRIBUTOR_EMAIL_ADDRESS }}"]'
campaign-id: 1506387
personalization-values: '[{"name": "PR_URL", "value": "https://www.codeforlife.education/"}]'
personalization-values: '[{"name": "PR_URL", "value": "${{ github.event.pull_request.url }}"}]'

0 comments on commit 699f37b

Please sign in to comment.