-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
23 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ verify_ssl = true | |
name = "pypi" | ||
|
||
[packages] | ||
requests = "==2.31.0" | ||
|
||
[dev-packages] | ||
black = "==23.1.0" | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.""" | ||
|
||
|
@@ -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__": | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }}"}]' |