-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjira.py
More file actions
76 lines (58 loc) · 2.45 KB
/
jira.py
File metadata and controls
76 lines (58 loc) · 2.45 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
70
71
72
73
74
75
76
from typing import List
import requests
from datetime import datetime, timezone
from dateutil.parser import parse as date_parse
from src.issue_wrapper.wrapper import Wrapper, Pagination, CommentMeta
class JiraIssueWrapper(Wrapper):
def __init__(self, url: str):
response = requests.get(url)
response.raise_for_status()
self.issue_data = response.json()
def issue_title(self) -> str:
return self.issue_data["fields"]["summary"]
def issue_key(self) -> str:
return self.issue_data["key"]
def issue_description(self) -> str:
return self.issue_data["fields"]["description"]
def issue_created_at(self) -> datetime:
return date_parse(self.issue_data["fields"]["created"])
def issue_closed_at(self) -> datetime:
date_str = self.issue_data["fields"].get("resolutiondate")
if date_str is None:
return datetime.now(timezone.utc)
else:
return date_parse(date_str)
def issue_author(self) -> str:
return self.issue_data["fields"]["creator"].get(
"displayName"
) or self.issue_data["fields"]["creator"].get("name")
def issue_comments(self, pagination: Pagination) -> List[CommentMeta]:
comments = self.issue_data["fields"]["comment"]["comments"]
comments = comments[pagination.offset : pagination.offset + pagination.limit]
comment_meta_list = []
for comment in comments:
comment_meta = CommentMeta(
author=self.get_comment_author(comment),
body=comment["body"],
created_at=comment["created"],
)
comment_meta_list.append(comment_meta)
return comment_meta_list
def issue_participants(self) -> List[str]:
participants = set()
creator = self.issue_author()
if creator:
participants.add(creator)
for comment in self.issue_data["fields"]["comment"]["comments"]:
author = self.get_comment_author(comment)
if author:
participants.add(author)
assignee = self.issue_data["fields"].get("assignee")
if assignee:
name = assignee.get("displayName") or assignee.get("name")
if name:
participants.add(name)
return list(participants)
@staticmethod
def get_comment_author(comment) -> str:
return comment["author"].get("displayName") or comment["author"].get("name")