Dec-24-2022, 09:30 AM
Hello forum,
I am having the current hurdle working with dictionaries.
Concrete: I am trying to add variable amounts of components to a JIRA issue.
Example:
If "Linux" is selected, I want to have the distribution added as second component as well.
Result in components: "Linux", "Mint"
JIRA required to have the following structure
I need to have this structure depending on what is selected before as having empty variables is not valid for the cases having only one component.
If e.g. "Windows" is selected I want to have this structure:
I tried the following:
response text = {"errorMessages":[],"errors":{"components":"expected Object"}}
How can I get this fixed?
If this is necessary, here is an example how to import an issue to JIRA with python
I am having the current hurdle working with dictionaries.
Concrete: I am trying to add variable amounts of components to a JIRA issue.
Example:
If "Linux" is selected, I want to have the distribution added as second component as well.
Result in components: "Linux", "Mint"
JIRA required to have the following structure
[{ "name" : "component" }]or for multiple components
[{ "name" : "component" }, { "name" : "component" }]What works is something like:
[{ "name" : VARIABLE }]or
[{ "name" : VARIABLE }, { "name" : SECOND_VARIABLE }]What is now my problem:
I need to have this structure depending on what is selected before as having empty variables is not valid for the cases having only one component.
If e.g. "Windows" is selected I want to have this structure:
[{ "name" : VARIABLE }]and if "Linux" is selected, I want to have this structure:
[{ "name" : VARIABLE }, { "name" : SECOND_VARIABLE }]Filling the variables is no issue at all, only "building" the dictionaries within if-clauses beforehand and moving them as variable in this structure is an issue.
I tried the following:
if var_LinuxDistro == 1: components_list = '{ "name" : "Linux" }, { "name" : "'+VARIABLE+'" }' else: components_list = '{ "name" : "'+VARIABLE+'" }'and took this components to the creation part:
issue_dict = { 'project': {'key': 'Project'}, 'summary': 'Testing issue from Python', 'description': 'Ticket description.', 'issuetype': {'name': 'Issue'}, 'components': [components_list], }Leading to an error
response text = {"errorMessages":[],"errors":{"components":"expected Object"}}
How can I get this fixed?
If this is necessary, here is an example how to import an issue to JIRA with python
issue_dict = { 'project': {'key': 'Project'}, 'summary': 'Testing issue from Python', 'description': 'Ticket description.', 'issuetype': {'name': 'Issue'}, 'components': [{'name': 'Issue'}, {'name': 'Issue'}], } new_issue = jira_connection.create_issue(fields=issue_dict)