-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgithub_parser.py
More file actions
54 lines (42 loc) · 1.46 KB
/
github_parser.py
File metadata and controls
54 lines (42 loc) · 1.46 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
54
"""GitHub context parsing utilities."""
import json
def parse_github_context(context_json: str) -> dict:
"""Parse GitHub Actions context.
Args:
context_json: JSON string of GitHub context
Returns:
Dict with repository, number, url, and event
Raises:
ValueError: If no issue or PR found in context
"""
context = json.loads(context_json)
# Extract number and URL
if "pull_request" in context["event"]:
number = context["event"]["pull_request"]["number"]
url = context["event"]["pull_request"]["html_url"]
elif "issue" in context["event"]:
number = context["event"]["issue"]["number"]
url = context["event"]["issue"]["html_url"]
else:
raise ValueError("No issue or PR found in context")
return {
"repository": context["repository"],
"number": number,
"url": url,
"event": context["event"],
}
def extract_command(context: dict) -> str:
"""Extract command from @cba mention or labels.
Args:
context: Parsed GitHub context from parse_github_context()
Returns:
Command string to execute
"""
# Check for @cba mention in comment
if "comment" in context["event"]:
body = context["event"]["comment"]["body"]
if "@cba" in body:
command = body.split("@cba", 1)[1].strip()
return command if command else "review this code"
# Default command
return "review this code"