forked from hasadna/laws-fixes-extractor-and-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjira.py
53 lines (46 loc) · 1.89 KB
/
jira.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
import base64
import logging
import os
import requests
logger = logging.getLogger(__name__)
class JiraApi:
def __init__(self):
self.url = 'https://kolzchut.atlassian.net/rest/api/2/issue/'
self.user_name = os.environ['JIRA_API_USER']
api_token = os.environ['JIRA_API_TOKEN']
token = f'{self.user_name}:{api_token}'
bytes_token = bytes(token, encoding='utf8')
token = str(base64.b64encode(bytes_token).decode('utf8'))
logger.info(f'token: {token}')
self.headers = {
'authorization': f'Basic {token}',
}
def send(self, data):
for datum in data:
summary = datum['display_name'] if len(datum['display_name']) < 255 else f"{datum['display_name'][:250]}..."
payload = {
'fields': {
'project': {
'key': 'KOL',
},
'summary': summary,
'description': datum['description'],
'issuetype': {
'name': 'שינוי חקיקה (עברית)',
},
'reporter': self.user_name,
'customfield_11690': datum['published_date'],
'customfield_11689': datum['file_name'],
'customfield_11703': datum['display_name'],
}
}
logger.info(f'headers: {self.headers}')
res = requests.post(self.url, headers=self.headers, json=payload)
if res.status_code >= 300:
logger.error(f'status code: {res.status_code}')
logger.error(f'result: {res.content}')
logger.error(f'the file that failed is: {datum["file_name"]}')
break
else:
logger.info(f'status code: {res.status_code}')
logger.info(f'result: {res.content}')