Hello. I'm Matsumoto from the Media System Development Department on the 17th day of mediba advent calendar 2016.
At mediba, multiple teams use atlassian's JIRA for project management. I also use it to manage tasks that occur on a regular basis, but I publish a story every time and publish subtasks for members ... Because it's sober and sometimes inadvertently forgotten, I tried to simplify the work by using the API.
--Create weekly periodical report issues using JIRA API and create as many subtask issues as there are members --The issue is created every Monday and the deadline for reporting is Thursday of the same week.
import
import
import requests
import json
import datetime
There are two authentication methods to use JIRA's API, this time using Basic HTTP.
Create an authentication key using BASE64 encoding.
Authentication
import base64
auth_str = 'JIRA account:JIRA password'
authkey = base64.encodestring(auth_str.encode("utf8")).decode("ascii")
For parameter analysis such as issue type, acquire and refer to existing issues.
Get issue
issue_data = requests.get(
'https://JIRA URL/rest/api/2/issue/Issue ID you want to get',
headers={'Content-Type': 'application/json',
'Authorization': 'Authentication key created on Basic}'})
You can access the API by including the authentication key in the header information. From the response, get the information needed to create the issue.
--Priority = priority 3 is medium --Issue type = issue type 5 is a subtask
I think this area will change depending on the JIRA settings.
First, prepare the parameters to be used in the request.
Parameters
#Person in charge of child issue
assignee = ['Person in charge 1 ID', 'ID of person in charge 2', 'ID of person in charge 3']
#Report deadline
duedate = str(datetime.date.today() + datetime.timedelta(3))
This is a request to add an issue.
Add issue
addissue = requests.post(
'https://JIRA URL/rest/api/2/issue/',
json.dumps({
"fields": {
'project': {
'key': 'Project key'
},
'assignee': {
'name': 'Person in charge of parent issue'
},
'reporter': {
'name': 'Reporter of parent issue'
},
'priority': {
'id': '3'
},
'issuetype': {
'id': '10001'
},
'labels': 'Label name',
'summary':'Summary',
'description': description,
'duedate': duedate,
}
}),
headers={'Content-Type': 'application/json',
'Authorization': 'Basic authentication key}'}
)
Now that the parent issue is added, add the child issue as a subtask. Since the ID of the parent issue is required for parent, the one obtained from the previous request result will be used.
Add issue
for name in assignee:
addsub = requests.post(
'https://JIRA URL/rest/api/2/issue/',
json.dumps({
"fields": {
'project': {'key': 'Project key'},
'summary': summary + '_' + name,
'assignee': {
'name': name
},
'reporter': {
'name': 'Parent ticket reporter'
},
'priority': {
'id': '3'
},
'parent': {
'id': addissue.json()['id']
},
'issuetype': {
'id': '5'
},
'labels': 'Label name',
'description': description,
'duedate': duedate,
}
}),
headers={'Content-Type': 'application/json',
'Authorization': 'Basic authentication key}'}
)
The above, the response of the execution result.
response
{'id': '42601',
'key': 'Project key-452',
'self': 'https://JIRA URL/rest/api/2/issue/42601'}
'42601'
{'id': '42602',
'key': 'Project key-453',
'self': 'https://JIRA URL/rest/api/2/issue/42602'}
{'id': '42603',
'key': 'Project key-454',
'self': 'https://JIRA URL/rest/api/2/issue/42603'}
{'id': '42604',
'key': 'Project key-455',
'self': 'https://JIRA URL/rest/api/2/issue/42604'}
Actually access JIRA, confirm that the parent issue and child issue have been added normally, and finish.
Once you know the parameters, it will work easily just by requesting the API, so if you are using JIRA, why not consider it? Of course, curl can be used instead. Tomorrow 18th will be "Remote Development Initiatives" by Mr. Sone.
Recommended Posts