Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
19 changes: 8 additions & 11 deletions press/api/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,13 @@ def setup(site):


@frappe.whitelist(allow_guest=True)
def get_analytics(**data):
def get_analytics(month: int, status: str, site: str, key: str):
"""
send data for a specific month
"""
month = data.get("month")
year = datetime.now().year
last_day = calendar.monthrange(year, int(month))[1]
Comment thread
balamurali27 marked this conversation as resolved.
status = data.get("status")
site = data.get("site")
subscription_key = data.get("key")
subscription_key = key

for value in (site, subscription_key):
if not value or not isinstance(value, str):
Expand Down Expand Up @@ -207,25 +204,25 @@ def check_recipients(recipients: str | list[str]):


@frappe.whitelist(allow_guest=True)
def send_mime_mail(**data):
def send_mime_mail(data: str):
"""
send api request to mailgun
"""
files = frappe._dict(frappe.request.files)
data = json.loads(data["data"])
data_dict = json.loads(data)

validate_plan(data["sk_mail"])
validate_plan(data_dict["sk_mail"])

api_key, domain = frappe.db.get_value("Press Settings", None, ["mailgun_api_key", "root_domain"])

message: bytes = files["mime"].read()
check_spam(message)
check_recipients(data["recipients"])
check_recipients(data_dict["recipients"])

resp = requests.post(
f"https://api.mailgun.net/v3/{domain}/messages.mime",
auth=("api", f"{api_key}"),
data={"to": data["recipients"], "v:sk_mail": data["sk_mail"]},
data={"to": data_dict["recipients"], "v:sk_mail": data_dict["sk_mail"]},
files={"message": message},
)

Expand All @@ -234,7 +231,7 @@ def send_mime_mail(**data):
if resp.status_code == 400:
err_msg: str = resp.json().get("message", "Invalid request")
frappe.throw(f"Something went wrong with sending emails: {err_msg}", InvalidEmail)
log_error("Email Delivery Service: Sending error", response=resp.text, data=data, message=message)
log_error("Email Delivery Service: Sending error", response=resp.text, data=data_dict, message=message)
frappe.throw(
"Something went wrong with sending emails. Please try again later or raise a support ticket with support.frappe.io",
EmailSendError,
Expand Down
12 changes: 6 additions & 6 deletions press/api/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def repositories(installation, token):


@frappe.whitelist()
def repository(owner, name, installation=None):
def repository(owner: str, name: str, installation: str | None = None):
token = ""
if not installation:
token = frappe.db.get_value("Press Settings", "github_access_token")
Expand Down Expand Up @@ -218,7 +218,7 @@ def repository(owner, name, installation=None):


@frappe.whitelist()
def app(owner, repository, branch, installation=None):
def app(owner: str, repository: str, branch: str, installation: str | None = None):
headers = get_auth_headers(installation)
response = requests.get(
f"https://api.github.com/repos/{owner}/{repository}/branches/{branch}",
Expand Down Expand Up @@ -262,7 +262,7 @@ def app(owner, repository, branch, installation=None):


@frappe.whitelist()
def branches(owner, name, installation=None, app_source=None):
def branches(owner: str, name: str, installation: str | None = None, app_source: str | None = None):
"""
Return ALL branches for the repo, following GitHub pagination.
"""
Expand All @@ -271,7 +271,7 @@ def branches(owner, name, installation=None, app_source=None):

headers = get_auth_headers(installation)

out = []
out: list[dict] = []
page = 1
while True:
resp = requests.get(
Expand Down Expand Up @@ -368,7 +368,7 @@ def _get_app_name_and_title_from_hooks(
branch_info,
headers,
tree,
) -> tuple[str, str] | None:
) -> tuple[str, str]:
reason_for_invalidation = f"Files {frappe.bold('hooks.py or patches.txt')} not found."
for directory, files in tree.items():
if not files:
Expand Down Expand Up @@ -405,7 +405,7 @@ def _get_app_name_and_title_from_hooks(
break

frappe.throw(f"Not a valid Frappe App! {reason_for_invalidation}")
return None
raise # for mypy: NoReturn
Comment thread
balamurali27 marked this conversation as resolved.


def _generate_files_tree(files):
Expand Down
2 changes: 1 addition & 1 deletion press/api/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def get_targets_method_rate_limit() -> int:

@frappe.whitelist(allow_guest=True)
@rate_limit(limit=get_targets_method_rate_limit, seconds=MONITORING_ENDPOINT_RATE_LIMIT_WINDOW_SECONDS)
def targets(token=None):
def targets(token: str | None = None):
if not token:
frappe.throw_permission_error()
monitor_token = frappe.db.get_single_value("Press Settings", "monitor_token", cache=True)
Expand Down
Loading