Skip to content

Commit

Permalink
send test email
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Dec 29, 2023
1 parent 44a81ed commit d923343
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
16 changes: 12 additions & 4 deletions .github/actions/python/send-email/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ def get_settings():
A tuple with the values (region, auth, timeout).
"""

region = json.loads(os.getenv("REGION", ""))
region = os.getenv("REGION", "")
assert region != "", "Region path parameter not set."
raise Exception(region)

auth = os.getenv("AUTH", "")
assert auth != "", "Authorization header not set."
Expand All @@ -48,13 +47,20 @@ def get_json_body() -> JsonBody:

body: JsonBody = {}

def set_value(env_key: str, body_key: str, required: bool):
def set_value(
env_key: str,
body_key: str,
required: bool,
json_loads: bool = True,
):
"""Helper to parse environment variables into body parameters.
Args:
env_key: The key of the environment variable.
body_key: The key of the body parameter.
required: If this value is required in the request.
json_loads: If the value should be parsed as a JSON object. Strings
don't need to be parsed as JSON.
"""

raw_value = os.getenv(env_key, "")
Expand All @@ -63,7 +69,7 @@ def set_value(env_key: str, body_key: str, required: bool):
assert raw_value != "", f'"{env_key}" environment variable not set.'

if raw_value != "":
body[body_key] = json.loads(raw_value)
body[body_key] = json.loads(raw_value) if json_loads else raw_value

set_value(
env_key="TO_ADDRESSES",
Expand All @@ -84,6 +90,7 @@ def set_value(env_key: str, body_key: str, required: bool):
env_key="FROM_ADDRESS",
body_key="fromAddress",
required=False,
json_loads=False,
)
set_value(
env_key="CAMPAIGN_ID",
Expand All @@ -99,6 +106,7 @@ def set_value(env_key: str, body_key: str, required: bool):
env_key="METADATA",
body_key="metadata",
required=False,
json_loads=False,
)
set_value(
env_key="ATTACHMENTS",
Expand Down
6 changes: 3 additions & 3 deletions .github/actions/python/send-email/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ runs:
working-directory: ${{ github.action_path }}
run: pipenv run python .
env:
REGION: '"${{ inputs.region }}"'
REGION: ${{ inputs.region }}
AUTH: ${{ inputs.auth }}
TIMEOUT: ${{ inputs.timeout }}
TO_ADDRESSES: ${{ inputs.to-addresses }}
CC_ADDRESSES: ${{ inputs.cc-addresses }}
BCC_ADDRESSES: ${{ inputs.bcc-addresses }}
FROM_ADDRESS: "${{ inputs.from-address }}"
FROM_ADDRESS: ${{ inputs.from-address }}
CAMPAIGN_ID: ${{ inputs.campaign-id }}
PERSONALIZATION_VALUES: ${{ inputs.personalization-values }}
METADATA: "${{ inputs.metadata }}"
METADATA: ${{ inputs.metadata }}
ATTACHMENTS: ${{ inputs.attachments }}
7 changes: 4 additions & 3 deletions .github/workflows/contributing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
- name: 📧 Send Email
uses: ocadotechnology/codeforlife-workspace/.github/actions/python/send-email@new_contributor_validations # TODO: use @main
with:
auth: ""
to-addresses: ""
campaign-id: 123
auth: ${{ secrets.DOTDIGITAL_API_USER_AUTH }}
to-addresses: '["stefan.kairinos@ocado.com"]' #${{ env.TO_ADDRESSES }}
campaign-id: 1506387
personalization-values: '[{"name": "PR_URL", "value": "https://www.codeforlife.education/"}]'

0 comments on commit d923343

Please sign in to comment.