Add CI workflow and apply ruff formatting (#6)

This commit is contained in:
Adam Moussa 2026-05-08 15:48:06 -04:00 • committed by GitHub
parent a128efa726
commit 1a30e2b438
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 64 additions and 28 deletions

10
.github/workflows/ci.yaml vendored Normal file
View file

@ -0,0 +1,10 @@
name: CI
on:
pull_request:
branches: [main]
jobs:
ci:
uses: Sea-Haven-Industries/.github/.github/workflows/ci-python-sam.yaml@main
with:
source-dirs: "src"

View file

@ -40,24 +40,36 @@ def handler(event, context):
is_origin = from_channel == SUBMITTED_CHANNEL
token = get_bot_token()
history = slack_get("conversations.history", token, {
history = slack_get(
"conversations.history",
token,
{
"channel": from_channel,
"latest": message_ts,
"limit": 1,
"inclusive": "true",
})
},
)
original_text = history["messages"][0]["text"]
permalink_resp = slack_get("chat.getPermalink", token, {
permalink_resp = slack_get(
"chat.getPermalink",
token,
{
"channel": from_channel,
"message_ts": message_ts,
})
},
)
permalink = permalink_resp["permalink"]
text = REACT_HINT_RE.sub("", original_text).strip()
next_stage = STAGES.get(to_channel)
next_label = next_stage["label"] if next_stage else None
react_line = f"\n\n_React_ :white_check_mark: _to advance to {next_label}_" if next_label else ""
react_line = (
f"\n\n_React_ :white_check_mark: _to advance to {next_label}_"
if next_label
else ""
)
permalink_line = (
f"\n\n📎 *Original Submission:* <{permalink}|View Original Message>"
if is_origin
@ -65,26 +77,38 @@ def handler(event, context):
)
full_text = f"{text}{permalink_line}{react_line}"
slack_post("chat.postMessage", token, {
slack_post(
"chat.postMessage",
token,
{
"channel": to_channel,
"text": full_text,
"mrkdwn": True,
"unfurl_links": False,
"unfurl_media": False,
})
},
)
if is_origin:
slack_post("chat.postMessage", token, {
slack_post(
"chat.postMessage",
token,
{
"channel": from_channel,
"thread_ts": message_ts,
"text": f"➡️ Advanced to {label}",
})
},
)
print(f"Advanced user submission to {label} (origin preserved)")
else:
slack_post("chat.delete", token, {
slack_post(
"chat.delete",
token,
{
"channel": from_channel,
"ts": message_ts,
})
},
)
print(f"Advanced to {label} and deleted previous copy")

View file

@ -85,7 +85,9 @@ def verify_signature(body: str, timestamp: str, signature: str) -> bool:
secret = get_signing_secret()
secret_len = len(secret)
base = f"v0:{timestamp}:{body}".encode("utf-8")
expected = "v0=" + hmac.new(secret.encode("utf-8"), base, hashlib.sha256).hexdigest()
expected = (
"v0=" + hmac.new(secret.encode("utf-8"), base, hashlib.sha256).hexdigest()
)
ok = hmac.compare_digest(expected, signature)
if not ok:
print(