-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathdeploy.py
More file actions
70 lines (56 loc) · 2.34 KB
/
Copy pathdeploy.py
File metadata and controls
70 lines (56 loc) · 2.34 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import configparser
import subprocess
from config import API_URL
from interactive import getActiveIteration
from commands.create_issue import createIssue
from interactive import selectLabels
def process_report(text, minutes):
# Get the incident project ID from config
try:
incident_project_id = config.get('DEFAULT', 'incident_project_id')
except (configparser.NoOptionError, configparser.NoSectionError):
print("Error: incident_project_id not found in config.ini")
print("Please add your incident project ID to configs/config.ini under [DEFAULT] section:")
print("incident_project_id = your_project_id_here")
return
issue_title = f"Incident Report: {text}"
selected_label = selectLabels('Department')
incident_settings = {
'labels': ['incident', 'report'],
'onlyIssue': True,
'type': 'incident'
}
if selected_label:
incident_settings['labels'].append(selected_label)
try:
# Create the incident issue
iteration = getActiveIteration()
created_issue = createIssue(issue_title, incident_project_id, False, False, iteration, incident_settings)
issue_iid = created_issue['iid']
closeOpenedIssue(issue_iid, incident_project_id)
print(f"Incident issue #{issue_iid} created successfully.")
print(f"Title: {issue_title}")
# Add time tracking to the issue
time_tracking_command = [
"glab", "api",
f"/projects/{incident_project_id}/issues/{issue_iid}/add_spent_time",
"-f", f"duration={minutes}m"
]
try:
subprocess.run(time_tracking_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(f"Added {minutes} minutes to issue time tracking.")
except subprocess.CalledProcessError as e:
print(f"Error adding time tracking: {str(e)}")
except Exception as e:
print(f"Error creating incident issue: {str(e)}")
def closeOpenedIssue(issue_iid, project_id):
issue_command = [
"glab", "api",
f"/projects/{project_id}/issues/{issue_iid}",
'-X', 'PUT',
'-f', 'state_event=close'
]
try:
subprocess.run(issue_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except subprocess.CalledProcessError as e:
print(f"Error closing issue: {str(e)}")