|
@@ -7,6 +7,7 @@ app = Flask(__name__)
|
7
|
7
|
# Config
|
8
|
8
|
LOGIN_URL = "http://localhost:7777/user/login"
|
9
|
9
|
EDIT_MILESTONE_URL = "http://localhost:7777/setyotontowi/experiments/milestones/1/edit"
|
|
10
|
+EVOLUZ_URL = "http://192.168.1.33:5050/apps/team/detail?"
|
10
|
11
|
USERNAME = "setyotontowi"
|
11
|
12
|
PASSWORD = "nasipadang"
|
12
|
13
|
|
|
@@ -101,7 +102,10 @@ def create_milestone_content(pr_data):
|
101
|
102
|
if content:
|
102
|
103
|
# From PR Data, get branch type, and username to assign it to identifier. like feature owi, then it should be
|
103
|
104
|
# in feature_lambda
|
104
|
|
- content['content'] = append_item_to_identifier(content['content'], 'feature_sigma', pr_data)
|
|
105
|
+ type_task = pr_data.get("task_type")
|
|
106
|
+ squad = "sigma"
|
|
107
|
+ identifier = f'{type_task}_{squad}'
|
|
108
|
+ content['content'] = append_item_to_identifier(content['content'], identifier, pr_data)
|
105
|
109
|
return f"{content['content']}\n"
|
106
|
110
|
else:
|
107
|
111
|
return f"- [] {pr_data['title']}"
|
|
@@ -136,7 +140,8 @@ def append_item_to_identifier(encoded_content, identifier, new_item):
|
136
|
140
|
end_marker = block_match.group(3)
|
137
|
141
|
|
138
|
142
|
# Append the new item to the block content
|
139
|
|
- formatted_item = f"- [x] {new_item['username']}: [{new_item['title']}]({new_item['branch']})"
|
|
143
|
+ formatted_item = f"- [x] {new_item['username']}: [{new_item['title']}]({new_item['link_evoluz']})"
|
|
144
|
+ print(formatted_item)
|
140
|
145
|
updated_block_content = f"{block_content}\n{formatted_item}"
|
141
|
146
|
|
142
|
147
|
# Reconstruct the content with the updated block
|
|
@@ -146,6 +151,65 @@ def append_item_to_identifier(encoded_content, identifier, new_item):
|
146
|
151
|
print(f"New item appended to '{identifier}' block.")
|
147
|
152
|
return content
|
148
|
153
|
|
|
154
|
+def find_username_id(username):
|
|
155
|
+ """
|
|
156
|
+ Finds the ID for a given username from the username_id file.
|
|
157
|
+
|
|
158
|
+ Args:
|
|
159
|
+ username (str): The username to look up.
|
|
160
|
+ file_path (str): Path to the username_id file.
|
|
161
|
+
|
|
162
|
+ Returns:
|
|
163
|
+ str: The ID of the username, or None if not found.
|
|
164
|
+ """
|
|
165
|
+ try:
|
|
166
|
+ with open("username_id", "r", encoding="utf-8") as file:
|
|
167
|
+ for line in file:
|
|
168
|
+ if line.strip(): # Skip empty lines
|
|
169
|
+ user, user_id = line.strip().split(":")
|
|
170
|
+ if user == username:
|
|
171
|
+ return user_id
|
|
172
|
+ print(f"Username '{username}' not found.")
|
|
173
|
+ return None
|
|
174
|
+ except FileNotFoundError:
|
|
175
|
+ print(f"File not found: {file_path}")
|
|
176
|
+ return None
|
|
177
|
+ except Exception as e:
|
|
178
|
+ print(f"An error occurred: {e}")
|
|
179
|
+ return None
|
|
180
|
+
|
|
181
|
+def generate_evoluz_link(username_id, task_id) :
|
|
182
|
+ team_id = f"teamID={username_id}"
|
|
183
|
+ update_team_id = f"updateTeamId={task_id}"
|
|
184
|
+
|
|
185
|
+ full_url = f"{EVOLUZ_URL}{team_id}&{update_team_id}"
|
|
186
|
+ return full_url
|
|
187
|
+
|
|
188
|
+def find_task_type(branch_name) :
|
|
189
|
+ """
|
|
190
|
+ Extracts the branch type and task ID from the branch name.
|
|
191
|
+
|
|
192
|
+ Args:
|
|
193
|
+ branch_name (str): The branch name (e.g., "feature/1234_task_name").
|
|
194
|
+
|
|
195
|
+ Returns:
|
|
196
|
+ dict: A dictionary with 'branch_type' and 'task_id', or None if invalid format.
|
|
197
|
+ """
|
|
198
|
+ try:
|
|
199
|
+ # Split the branch name by "/"
|
|
200
|
+ parts = branch_name.split("/")
|
|
201
|
+ if len(parts) >= 2:
|
|
202
|
+ branch_type = parts[0] # The first part is the branch type
|
|
203
|
+ task = parts[1]
|
|
204
|
+ task_id = task.split("_")[0] # The second part is the task ID
|
|
205
|
+ return {"task_type": branch_type, "task_id": task_id}
|
|
206
|
+ else:
|
|
207
|
+ print(f"Invalid branch name format: {branch_name}")
|
|
208
|
+ return None
|
|
209
|
+ except Exception as e:
|
|
210
|
+ print(f"Error extracting task type: {e}")
|
|
211
|
+ return None
|
|
212
|
+
|
149
|
213
|
@app.route('/webhook', methods=['POST'])
|
150
|
214
|
def handle_webhook():
|
151
|
215
|
if request.method != 'POST':
|
|
@@ -162,11 +226,17 @@ def handle_webhook():
|
162
|
226
|
|
163
|
227
|
pr_title = pr.get('title')
|
164
|
228
|
pr_username = pr.get('user').get('username')
|
|
229
|
+ pr_username_id = find_username_id(pr_username)
|
165
|
230
|
pr_branch = pr.get('head_branch')
|
|
231
|
+ pr_branch_data = find_task_type(pr_branch)
|
|
232
|
+
|
166
|
233
|
pr_data = {
|
167
|
234
|
'title': pr_title,
|
168
|
|
- 'username': pr_username,
|
169
|
|
- 'branch': pr_branch
|
|
235
|
+ 'username': pr_username.capitalize(),
|
|
236
|
+ 'branch': pr_branch,
|
|
237
|
+ 'task_type': pr_branch_data.get("task_type"),
|
|
238
|
+ 'user_id': find_username_id(pr_username),
|
|
239
|
+ 'link_evoluz': generate_evoluz_link(pr_username_id, pr_branch_data.get("task_id"))
|
170
|
240
|
}
|
171
|
241
|
|
172
|
242
|
print(f"Received PR: {pr_title}")
|