mirror of
https://github.com/Sea-Haven-Industries/expense-approval-bot.git
synced 2026-05-18 20:20:14 +00:00
Add CI workflow and apply ruff formatting (#6)
This commit is contained in:
parent
a128efa726
commit
1a30e2b438
3 changed files with 64 additions and 28 deletions
10
.github/workflows/ci.yaml
vendored
Normal file
10
.github/workflows/ci.yaml
vendored
Normal 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"
|
||||||
|
|
@ -40,24 +40,36 @@ def handler(event, context):
|
||||||
is_origin = from_channel == SUBMITTED_CHANNEL
|
is_origin = from_channel == SUBMITTED_CHANNEL
|
||||||
token = get_bot_token()
|
token = get_bot_token()
|
||||||
|
|
||||||
history = slack_get("conversations.history", token, {
|
history = slack_get(
|
||||||
"channel": from_channel,
|
"conversations.history",
|
||||||
"latest": message_ts,
|
token,
|
||||||
"limit": 1,
|
{
|
||||||
"inclusive": "true",
|
"channel": from_channel,
|
||||||
})
|
"latest": message_ts,
|
||||||
|
"limit": 1,
|
||||||
|
"inclusive": "true",
|
||||||
|
},
|
||||||
|
)
|
||||||
original_text = history["messages"][0]["text"]
|
original_text = history["messages"][0]["text"]
|
||||||
|
|
||||||
permalink_resp = slack_get("chat.getPermalink", token, {
|
permalink_resp = slack_get(
|
||||||
"channel": from_channel,
|
"chat.getPermalink",
|
||||||
"message_ts": message_ts,
|
token,
|
||||||
})
|
{
|
||||||
|
"channel": from_channel,
|
||||||
|
"message_ts": message_ts,
|
||||||
|
},
|
||||||
|
)
|
||||||
permalink = permalink_resp["permalink"]
|
permalink = permalink_resp["permalink"]
|
||||||
|
|
||||||
text = REACT_HINT_RE.sub("", original_text).strip()
|
text = REACT_HINT_RE.sub("", original_text).strip()
|
||||||
next_stage = STAGES.get(to_channel)
|
next_stage = STAGES.get(to_channel)
|
||||||
next_label = next_stage["label"] if next_stage else None
|
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 = (
|
permalink_line = (
|
||||||
f"\n\n📎 *Original Submission:* <{permalink}|View Original Message>"
|
f"\n\n📎 *Original Submission:* <{permalink}|View Original Message>"
|
||||||
if is_origin
|
if is_origin
|
||||||
|
|
@ -65,26 +77,38 @@ def handler(event, context):
|
||||||
)
|
)
|
||||||
full_text = f"{text}{permalink_line}{react_line}"
|
full_text = f"{text}{permalink_line}{react_line}"
|
||||||
|
|
||||||
slack_post("chat.postMessage", token, {
|
slack_post(
|
||||||
"channel": to_channel,
|
"chat.postMessage",
|
||||||
"text": full_text,
|
token,
|
||||||
"mrkdwn": True,
|
{
|
||||||
"unfurl_links": False,
|
"channel": to_channel,
|
||||||
"unfurl_media": False,
|
"text": full_text,
|
||||||
})
|
"mrkdwn": True,
|
||||||
|
"unfurl_links": False,
|
||||||
|
"unfurl_media": False,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
if is_origin:
|
if is_origin:
|
||||||
slack_post("chat.postMessage", token, {
|
slack_post(
|
||||||
"channel": from_channel,
|
"chat.postMessage",
|
||||||
"thread_ts": message_ts,
|
token,
|
||||||
"text": f"➡️ Advanced to {label}",
|
{
|
||||||
})
|
"channel": from_channel,
|
||||||
|
"thread_ts": message_ts,
|
||||||
|
"text": f"➡️ Advanced to {label}",
|
||||||
|
},
|
||||||
|
)
|
||||||
print(f"Advanced user submission to {label} (origin preserved)")
|
print(f"Advanced user submission to {label} (origin preserved)")
|
||||||
else:
|
else:
|
||||||
slack_post("chat.delete", token, {
|
slack_post(
|
||||||
"channel": from_channel,
|
"chat.delete",
|
||||||
"ts": message_ts,
|
token,
|
||||||
})
|
{
|
||||||
|
"channel": from_channel,
|
||||||
|
"ts": message_ts,
|
||||||
|
},
|
||||||
|
)
|
||||||
print(f"Advanced to {label} and deleted previous copy")
|
print(f"Advanced to {label} and deleted previous copy")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,9 @@ def verify_signature(body: str, timestamp: str, signature: str) -> bool:
|
||||||
secret = get_signing_secret()
|
secret = get_signing_secret()
|
||||||
secret_len = len(secret)
|
secret_len = len(secret)
|
||||||
base = f"v0:{timestamp}:{body}".encode("utf-8")
|
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)
|
ok = hmac.compare_digest(expected, signature)
|
||||||
if not ok:
|
if not ok:
|
||||||
print(
|
print(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue