|
@@ -1,21 +1,77 @@
|
1
|
1
|
import re
|
2
|
2
|
import html
|
|
3
|
+from utils import find_squad
|
|
4
|
+from auth import login, get_csrf_token, EDIT_MILESTONE_URL, session
|
3
|
5
|
|
4
|
|
-def get_milestone(session, edit_milestone_url):
|
|
6
|
+def update_milestone(pr_data):
|
|
7
|
+ login()
|
|
8
|
+ """Update milestone with PR title using CSRF token."""
|
|
9
|
+ csrf_token = get_csrf_token()
|
|
10
|
+ if not csrf_token:
|
|
11
|
+ print("Failed to get CSRF token.")
|
|
12
|
+ return False
|
|
13
|
+
|
|
14
|
+ meta = get_milestone(session)
|
|
15
|
+ content = create_milestone_content(meta.get("content"), pr_data)
|
|
16
|
+
|
|
17
|
+ print(f"Updating milestone with content:\n")
|
|
18
|
+
|
|
19
|
+ with open("content.md", "w") as file:
|
|
20
|
+ file.write(content)
|
|
21
|
+
|
|
22
|
+ payload = {
|
|
23
|
+ "_csrf": csrf_token,
|
|
24
|
+ "title": meta.get("title"),
|
|
25
|
+ "content": content,
|
|
26
|
+ "deadline": meta.get("deadline")
|
|
27
|
+ }
|
|
28
|
+ headers = {
|
|
29
|
+ "Content-Type": "application/x-www-form-urlencoded"
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+ response = session.post(EDIT_MILESTONE_URL, data=payload, headers=headers)
|
|
34
|
+
|
|
35
|
+ if response.status_code == 200:
|
|
36
|
+ print("Milestone updated successfully!")
|
|
37
|
+ return True
|
|
38
|
+ elif response.status_code == 401: # Unauthorized → Need to re-login
|
|
39
|
+ print("Session expired, re-logging in...")
|
|
40
|
+ if login():
|
|
41
|
+ return update_milestone(pr_data)
|
|
42
|
+ else:
|
|
43
|
+ print(f"Failed to update milestone: {response.status_code} - {response.text}")
|
|
44
|
+ return False
|
|
45
|
+
|
|
46
|
+def create_milestone_content(content, pr_data):
|
|
47
|
+ if content:
|
|
48
|
+ # From PR Data, get branch type, and username to assign it to identifier. like feature owi, then it should be
|
|
49
|
+ # in feature_lambda
|
|
50
|
+ type_task = pr_data.get("task_type")
|
|
51
|
+ squad = "sigma"
|
|
52
|
+ identifier = f'{type_task}_{squad}'
|
|
53
|
+ content = append_item_to_identifier(content, identifier, pr_data)
|
|
54
|
+ return f"{content}\n"
|
|
55
|
+ else:
|
|
56
|
+ return f"- [] {pr_data['title']}"
|
|
57
|
+
|
|
58
|
+def get_milestone(session):
|
5
|
59
|
"""Fetch milestone details."""
|
6
|
|
- response = session.get(edit_milestone_url)
|
|
60
|
+ response = session.get(EDIT_MILESTONE_URL)
|
7
|
61
|
if response.status_code == 200:
|
8
|
|
- title_match = re.search(r'<input[^>]*name=["\']title["\'][^>]*value=["\'](.*?)["\']', response.text, re.IGNORECASE)
|
|
62
|
+ title_match = re.search(r'<input[^>]*name=["\']title["\'][^>]*value=["\'](.* ?)["\']', response.text, re.IGNORECASE)
|
9
|
63
|
content_match = re.search(r'<textarea[^>]*name=["\']content["\'][^>]*>(.*?)</textarea>', response.text, re.IGNORECASE | re.DOTALL)
|
|
64
|
+ deadline_match = re.search(r'<input[^>]*name=["\']deadline["\'][^>]*value=["\'](.*?)["\']', response.text, re.IGNORECASE)
|
10
|
65
|
title = title_match.group(1) if title_match else None
|
11
|
66
|
content = content_match.group(1).strip() if content_match else None
|
12
|
|
- return {'title': title, 'content': content}
|
|
67
|
+ deadline = deadline_match.group(1) if deadline_match else None
|
|
68
|
+ return {'title': title, 'content': content, 'deadline': deadline}
|
13
|
69
|
else:
|
14
|
70
|
print(f"Failed to fetch milestone: {response.status_code}")
|
15
|
71
|
return None
|
16
|
72
|
|
17
|
73
|
def append_item_to_identifier(encoded_content, identifier, new_item):
|
18
|
|
- """Append a new item to the block identified by the given identifier."""
|
|
74
|
+ # Extract the block delimited by the identifier markers
|
19
|
75
|
content = html.unescape(encoded_content)
|
20
|
76
|
block_pattern = rf'(<!--\s*{identifier}\s*-->)(.*?)(<!--\s*/{identifier}\s*-->)'
|
21
|
77
|
block_match = re.search(block_pattern, content, re.DOTALL)
|
|
@@ -23,12 +79,18 @@ def append_item_to_identifier(encoded_content, identifier, new_item):
|
23
|
79
|
print(f"Block with identifier '{identifier}' not found.")
|
24
|
80
|
return False
|
25
|
81
|
|
|
82
|
+ # Extract the parts of the block
|
26
|
83
|
start_marker = block_match.group(1)
|
27
|
84
|
block_content = block_match.group(2).strip()
|
28
|
85
|
end_marker = block_match.group(3)
|
29
|
86
|
|
|
87
|
+ # Append the new item to the block content
|
30
|
88
|
formatted_item = f"- [x] {new_item['username']}: [{new_item['title']}]({new_item['link_evoluz']})"
|
31
|
89
|
updated_block_content = f"{block_content}\n{formatted_item}"
|
32
|
90
|
|
|
91
|
+ # Reconstruct the content with the updated block
|
33
|
92
|
updated_content = f"{start_marker}\n{updated_block_content}\n{end_marker}"
|
34
|
|
- return updated_content
|
|
93
|
+ content = content.replace(block_match.group(0), updated_content)
|
|
94
|
+
|
|
95
|
+ print(f"New item appended to '{identifier}' block.")
|
|
96
|
+ return content
|