-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.py
More file actions
59 lines (45 loc) · 1.83 KB
/
Copy pathscript.py
File metadata and controls
59 lines (45 loc) · 1.83 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
#!/usr/bin/env python3
import datetime
import os
import requests
from requests.auth import HTTPBasicAuth
# Load JIRA API credentials and base URL from environment variables
jira_username = os.environ.get("JIRA_USERNAME", "")
jira_password = os.environ.get("JIRA_PASSWORD", "")
jira_base_url = os.environ.get("JIRA_BASE_URL", "https://your_jira_instance.atlassian.net")
# Set the JQL query to get the relevant issues (adjust the query as needed)
jql_query = "project = YOUR_PROJECT_KEY AND issuetype = Bug AND status = Resolved"
# Set the date format used by JIRA
jira_date_format = "%Y-%m-%dT%H:%M:%S.%f%z"
# Function to get issues from JIRA using the REST API
def get_jira_issues(jql):
url = f"{jira_base_url}/rest/api/3/search"
headers = {"Accept": "application/json"}
params = {"jql": jql, "fields": "created, resolutiondate"}
response = requests.get(
url,
headers=headers,
params=params,
auth=HTTPBasicAuth(jira_username, jira_password),
)
response.raise_for_status()
return response.json()["issues"]
# Function to calculate resolution time for a JIRA issue
def calculate_resolution_time(issue):
created_date = datetime.datetime.strptime(
issue["fields"]["created"], jira_date_format
)
resolution_date = datetime.datetime.strptime(
issue["fields"]["resolutiondate"], jira_date_format
)
resolution_time = (
resolution_date - created_date
).total_seconds() / 3600 # Calculate time in hours
return resolution_time
# Get the issues from JIRA
issues = get_jira_issues(jql_query)
# Calculate resolution time for each issue
resolution_times = [calculate_resolution_time(issue) for issue in issues]
# Calculate the Mean Time To Resolve (MTTR)
mttr = sum(resolution_times) / len(resolution_times)
print(f"Mean Time To Resolve (MTTR): {mttr:.2f} hours")