-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlambda_function.py
More file actions
53 lines (45 loc) · 1.88 KB
/
lambda_function.py
File metadata and controls
53 lines (45 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import json
import urllib3
import os
http = urllib3.PoolManager()
POST_API_URL = "http://54.197.67.80:8080/process" # <-- replace this
def lambda_handler(event, context):
# GitHub sends the body as a string
try:
body = json.loads(event["body"])
except Exception as e:
print(f"Error parsing body: {e}")
return { "statusCode": 400, "body": "Bad Request" }
print(body)
# Basic filter: only respond to new issue comments
action = body.get("action")
comment = body.get("comment", {}).get("body", "").strip()
author_association = body.get("comment", {}).get("author_association", "")
print(f"Received comment: '{comment}' from {author_association}")
if action == "created" and comment == "/remote-dev" and author_association != "NONE":
# Trigger your POST request
print(body)
try:
owner = body["repository"]["owner"]["login"]
repo = body["repository"]["name"]
issue_heading = body["issue"].get("title", "")
issue_description = body["issue"].get("body", "")
data = {
"owner_name": owner,
"repo_name": repo,
"issue_number": str(body["issue"]["number"]),
"issue_description": issue_heading + " : " + issue_description,
"commenter": body["comment"]["user"]["login"]
}
print(f"POST request data: {data}")
r = http.request(
"POST",
POST_API_URL,
body=json.dumps(data).encode("utf-8"),
headers={ "Content-Type": "application/json" }
)
print(f"POST response: {r.status}")
except Exception as e:
print(f"POST request failed: {e}")
return { "statusCode": 500, "body": "Internal error" }
return { "statusCode": 200, "body": "OK" }