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
|
||||
token = get_bot_token()
|
||||
|
||||
history = slack_get("conversations.history", token, {
|
||||
"channel": from_channel,
|
||||
"latest": message_ts,
|
||||
"limit": 1,
|
||||
"inclusive": "true",
|
||||
})
|
||||
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, {
|
||||
"channel": from_channel,
|
||||
"message_ts": message_ts,
|
||||
})
|
||||
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, {
|
||||
"channel": to_channel,
|
||||
"text": full_text,
|
||||
"mrkdwn": True,
|
||||
"unfurl_links": False,
|
||||
"unfurl_media": False,
|
||||
})
|
||||
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, {
|
||||
"channel": from_channel,
|
||||
"thread_ts": message_ts,
|
||||
"text": f"➡️ Advanced to {label}",
|
||||
})
|
||||
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, {
|
||||
"channel": from_channel,
|
||||
"ts": message_ts,
|
||||
})
|
||||
slack_post(
|
||||
"chat.delete",
|
||||
token,
|
||||
{
|
||||
"channel": from_channel,
|
||||
"ts": message_ts,
|
||||
},
|
||||
)
|
||||
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_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(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue