-
Notifications
You must be signed in to change notification settings - Fork 1
/
bugreporter.py
91 lines (74 loc) · 3.12 KB
/
bugreporter.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from slack_sdk import WebClient
import requests
import datetime
# Slack BOT token
SLACK_BOT_TOKEN = "##SLACKBOT_TOKEN##"
CHANNEL = "##CHANNEL_NAME##"
slack_client = WebClient(token=SLACK_BOT_TOKEN)
# JIRA API details
jira_domain = "##JIRA_DOMAIN_URL##"
browse_path = "/browse"
rest_path = "/rest/api/2"
search_api = "/search"
user_search_api = "/user/search"
api_url = jira_domain + rest_path + search_api
# JIRA credentials
username = "##JIRA_USERNAME##"
password = "##JIRA_PWD##" # API token or password
# Headers with basic authentication
headers = {
"Accept": "application/json"
}
# JIRA search query
jql_query = '##SEARCH_QUERY##'
# Map team members' username and email
eng_emailid_map = {
'##JIRA_USERNAME##':'##JIRA_MAILID##'
}
# Map team members' email and slack member id
eng_memberid_map = {
'##JIRA_MAILID##':'##SLACK_MEMBERID##',
}
# Update date
current_date = datetime.datetime.now()
result = "<!here> :alert: *Bug tickets for review - Week %s, %s/%s/%s*" % (current_date.isocalendar()[1], current_date.day, current_date.month, current_date.year)
slack_client.chat_postMessage(channel = CHANNEL, text = result)
for engineer in eng_emailid_map:
query = jql_query + engineer
# Parameters for the JQL query
params = {
"jql": query,
"maxResults": 50 # Change this value as per your requirement
}
# Make the API request
response = requests.get(api_url, auth=(username, password), headers=headers, params=params)
# Check if the request was successful
if response.status_code == 200:
data = response.json()
result = ":information_desk_person: " + "<@" + eng_memberid_map[eng_emailid_map[engineer]] + ">\n"
result_dict = {}
# Process the retrieved tickets
if "issues" in data:
issues = data["issues"]
for issue in issues:
# Fetch ticket summary, status, assginee
summary = issue["fields"]["summary"]
status = issue["fields"]["status"]["name"]
curr_assignee = issue["fields"]["assignee"]["name"]
assignee_name = issue["fields"]["assignee"]["displayName"]
# Do not add ticket to current engineer's list if the assignee is a team member
# Because the ticket needs to show up in the respective team member's list
if curr_assignee == engineer or curr_assignee not in eng_emailid_map:
key = jira_domain + browse_path + '/' + issue["key"]
result += "<" + key + "|" + issue["key"] + ">"
result += ' : ' + summary + ' `Status: ' + status + '` ' + ' `Assignee: ' + assignee_name + '`\n'
# Group tickets based on status
if status not in result_dict:
result_dict.setdefault(status, [])
result_dict[status].append(result)
else:
result += "No issues found :smile:\n"
# Post the report in slack
slack_client.chat_postMessage(channel = CHANNEL, text = result)
else:
print("Failed to retrieve issues. Status code:", response.status_code)