jira: Build request's data as dictionary to create/edit issues.

Build data in `make_create_json` and `make_edit_json` methods
as dictionary to send as JSON payload.
This commit is contained in:
novokrest 2018-06-11 07:51:22 +03:00 committed by showell
parent 24a157cd37
commit a17bd77b71
5 changed files with 83 additions and 37 deletions

View file

@ -6,7 +6,17 @@
"Authorization": "Basic ZXhhbXBsZUBleGFtcGxlLmNvbTpxd2VydHkhMTIz", "Authorization": "Basic ZXhhbXBsZUBleGFtcGxlLmNvbTpxd2VydHkhMTIz",
"Content-type": "application/json" "Content-type": "application/json"
}, },
"data": "{\"fields\": {\"summary\": \"Testing\",\"project\": { \"key\": \"TEST\" },\"issuetype\": { \"name\": \"Task\" }}}" "data": {
"fields": {
"summary": "Testing",
"project": {
"key": "TEST"
},
"issuetype": {
"name": "Task"
}
}
}
}, },
"response": { "response": {
"key": "TEST-16" "key": "TEST-16"

View file

@ -6,7 +6,26 @@
"Authorization": "Basic ZXhhbXBsZUBleGFtcGxlLmNvbTpxd2VydHkhMTIz", "Authorization": "Basic ZXhhbXBsZUBleGFtcGxlLmNvbTpxd2VydHkhMTIz",
"Content-type": "application/json" "Content-type": "application/json"
}, },
"data": "{\"fields\": {\"summary\": \"Testing\",\"project\": { \"key\": \"TEST\" },\"issuetype\": { \"name\": \"Task\" },\"description\": \"This is a test description\",\"assignee\": { \"name\": \"testuser\" },\"priority\": { \"name\": \"Medium\" },\"labels\": [\"issues\",\"testing\"],\"duedate\": \"2018-06-11\"}}" "data": {
"fields": {
"summary": "Testing",
"project": {
"key": "TEST"
},
"issuetype": {
"name": "Task"
}
,"description": "This is a test description",
"assignee": {
"name": "testuser"
},
"priority": {
"name": "Medium"
},
"labels": ["issues","testing"],
"duedate": "2018-06-11"
}
}
}, },
"response": { "response": {
"errors": { "errors": {

View file

@ -6,7 +6,11 @@
"Authorization": "Basic ZXhhbXBsZUBleGFtcGxlLmNvbTpxd2VydHkhMTIz", "Authorization": "Basic ZXhhbXBsZUBleGFtcGxlLmNvbTpxd2VydHkhMTIz",
"Content-type": "application/json" "Content-type": "application/json"
}, },
"data": "{\"fields\": {\"description\": \"description\"}}" "data": {
"fields": {
"description": "description"
}
}
}, },
"response": { "response": {
}, },

View file

@ -6,7 +6,26 @@
"Authorization": "Basic ZXhhbXBsZUBleGFtcGxlLmNvbTpxd2VydHkhMTIz", "Authorization": "Basic ZXhhbXBsZUBleGFtcGxlLmNvbTpxd2VydHkhMTIz",
"Content-type": "application/json" "Content-type": "application/json"
}, },
"data": "{\"fields\": {\"summary\": \"Change the summary\",\"project\": { \"key\": \"TEST\" },\"issuetype\": { \"name\": \"Bug\" },\"description\": \"This is a test description\",\"assignee\": { \"name\": \"testuser\" },\"priority\": { \"name\": \"Low\" },\"labels\": [\"issues\",\"testing\"],\"duedate\": \"2018-06-11\"}}" "data": {
"fields": {
"summary": "Change the summary",
"project": {
"key": "TEST"
},
"issuetype": {
"name": "Bug"
},
"description": "This is a test description",
"assignee": {
"name": "testuser"
},
"priority": {
"name": "Low"
},
"labels": ["issues","testing"],
"duedate": "2018-06-11"
}
}
}, },
"response": { "response": {
"errors": { "errors": {

View file

@ -242,7 +242,7 @@ def make_jira_auth(username: str, password: str) -> str:
def make_create_json(summary: str, project_key: str, type_name: str, def make_create_json(summary: str, project_key: str, type_name: str,
description: Optional[str], assignee: Optional[str], description: Optional[str], assignee: Optional[str],
priority_name: Optional[str], labels: Optional[str], priority_name: Optional[str], labels: Optional[str],
due_date: Optional[str]) -> str: due_date: Optional[str]) -> Any:
'''Makes a JSON string for the Jira REST API editing endpoint based on '''Makes a JSON string for the Jira REST API editing endpoint based on
fields that could be edited. fields that could be edited.
@ -257,35 +257,34 @@ def make_create_json(summary: str, project_key: str, type_name: str,
comma-spaces. comma-spaces.
- due_date (optional): The Jira due date property. - due_date (optional): The Jira due date property.
''' '''
json = '{"fields": {' json_fields = {
'summary': summary,
json += '"summary": "' + summary + '",' 'project': {
json += '"project": { "key": "' + project_key + '" },' 'key': project_key
json += '"issuetype": { "name": "' + type_name + '" },' },
'issuetype': {
'name': type_name
}
}
if description: if description:
json += '"description": "' + description + '",' json_fields['description'] = description
if assignee: if assignee:
json += '"assignee": { "name": "' + assignee + '" },' json_fields['assignee'] = {'name': assignee}
if priority_name: if priority_name:
json += '"priority": { "name": "' + priority_name + '" },' json_fields['priority'] = {'name': priority_name}
if labels: if labels:
labels_list = labels.split(', ') json_fields['labels'] = labels.split(', ')
labels_json = '"' + '","'.join(labels_list) + '"'
json += '"labels": [' + labels_json + '],'
if due_date: if due_date:
json += '"duedate": "' + due_date + '",' json_fields['duedate'] = due_date
# Remove the trailing comma. json = {'fields': json_fields}
json = json[:-1]
json += '}}'
return json return json
def make_edit_json(summary: Optional[str], project_key: Optional[str], def make_edit_json(summary: Optional[str], project_key: Optional[str],
type_name: Optional[str], description: Optional[str], type_name: Optional[str], description: Optional[str],
assignee: Optional[str], priority_name: Optional[str], assignee: Optional[str], priority_name: Optional[str],
labels: Optional[str], due_date: Optional[str]) -> str: labels: Optional[str], due_date: Optional[str]) -> Any:
'''Makes a JSON string for the Jira REST API editing endpoint based on '''Makes a JSON string for the Jira REST API editing endpoint based on
fields that could be edited. fields that could be edited.
@ -300,31 +299,26 @@ def make_edit_json(summary: Optional[str], project_key: Optional[str],
comma-spaces. comma-spaces.
- due_date (optional): The Jira due date property. - due_date (optional): The Jira due date property.
''' '''
json = '{"fields": {' json_fields = {}
if summary: if summary:
json += '"summary": "' + summary + '",' json_fields['summary'] = summary
if project_key: if project_key:
json += '"project": { "key": "' + project_key + '" },' json_fields['project'] = {'key': project_key}
if type_name: if type_name:
json += '"issuetype": { "name": "' + type_name + '" },' json_fields['issuetype'] = {'name': type_name}
if description: if description:
json += '"description": "' + description + '",' json_fields['description'] = description
if assignee: if assignee:
json += '"assignee": { "name": "' + assignee + '" },' json_fields['assignee'] = {'name': assignee}
if priority_name: if priority_name:
json += '"priority": { "name": "' + priority_name + '" },' json_fields['priority'] = {'name': priority_name}
if labels: if labels:
labels_list = labels.split(', ') json_fields['labels'] = labels.split(', ')
labels_json = '"' + '","'.join(labels_list) + '"'
json += '"labels": [' + labels_json + '],'
if due_date: if due_date:
json += '"duedate": "' + due_date + '",' json_fields['duedate'] = due_date
# Remove the trailing comma. json = {'fields': json_fields}
json = json[:-1]
json += '}}'
return json return json