Skip to content

Commit de5e4dc

Browse files
committed
get the lambda arn
1 parent 2953af7 commit de5e4dc

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

packages/slackBotFunction/app/slack/slack_handlers.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
constants,
2020
)
2121
from app.services.dynamo import get_state_information
22-
from app.utils.handler_utils import is_duplicate_event, trigger_async_processing, respond_with_eyes
22+
from app.utils.handler_utils import (
23+
is_duplicate_event,
24+
trigger_async_processing,
25+
respond_with_eyes,
26+
trigger_pull_request_processing,
27+
)
2328
from app.slack.slack_events import store_feedback
2429

2530
logger = get_logger()
@@ -139,16 +144,20 @@ def mention_handler(event, ack, body, client):
139144
return
140145

141146
if cleaned.lower().startswith(constants.PULL_REQUEST_PREFIX):
142-
pull_request_id, extracted_message = _extract_pull_request_id(cleaned)
143-
logger.debug(f"Handling message for pull request {pull_request_id}", extra={"pull_request_id": pull_request_id})
144147
try:
148+
pull_request_id, extracted_message = _extract_pull_request_id(cleaned)
149+
pull_request_lambda_arn = trigger_pull_request_processing(pull_request_id)
150+
logger.debug(
151+
f"Handling message for pull request {pull_request_id}",
152+
extra={"pull_request_id": pull_request_id, "pull_request_lambda_arn": pull_request_lambda_arn},
153+
)
145154
client.chat_postMessage(
146155
channel=channel_id,
147-
text=f"Handling message for pull request {pull_request_id}",
156+
text=f"Handling message for pull request {pull_request_id} by calling {pull_request_lambda_arn}",
148157
thread_ts=thread_root,
149158
)
150159
except Exception as e:
151-
logger.error(f"Failed to post channel feedback ack: {e}", extra={"error": traceback.format_exc()})
160+
logger.error(f"Can not find pull request details: {e}", extra={"error": traceback.format_exc()})
152161
return
153162

154163
# Normal mention -> async processing

packages/slackBotFunction/app/utils/handler_utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,17 @@ def respond_with_eyes(bot_token, event):
6767
client.reactions_add(channel=channel, timestamp=ts, name="eyes")
6868
except Exception:
6969
logger.warning("Failed to respond with eyes", extra={"error": traceback.format_exc()})
70+
71+
72+
def trigger_pull_request_processing(pull_request_id: str):
73+
cf = boto3.client("cloudformation")
74+
# lambda_client = boto3.client("lambda")
75+
try:
76+
response = cf.describe_stacks(StackName=f"epsam-pr-{pull_request_id}")
77+
outputs = {o["OutputKey"]: o["OutputValue"] for o in response["Stacks"][0]["Outputs"]}
78+
79+
pull_request_lambda_arn = outputs.get("SlackBotLambdaArn")
80+
return pull_request_lambda_arn
81+
except Exception as e:
82+
logger.error("Failed to get cloudformation output", extra={"error": traceback.format_exc()})
83+
raise e

0 commit comments

Comments
 (0)