Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create issue with parent by parent issue key (without parent issue ID) #426

Closed
pirtleshell opened this issue Dec 8, 2021 · 2 comments

Comments

@pirtleshell
Copy link

Describe the bug

I'd like to be able to create an issue that is a subtask of a different issue. The Jira API supports setting the parent by issue ID or by issue key. However, the way the IssueFields.Parent struct marshals to JSON when only a Key is present prevents Jira from being able to find the issue by key.

To Reproduce

Attempt to create an issue with a parent using only the Key of the parent issue, excluding the ID. The problem can be seen by marshaling an Issue to json:

// attempt to create a subissue on TEST-42
issue := jira.Issue{
	Fields: &jira.IssueFields{
		Summary:     "My Test Issue",
		Description: "This issue marshalls to JSON with a parent that Jira does not like.",
		Type:        jira.IssueType{Name: "Subtask"},
		Project:     jira.Project{Key: "TEST"},
		Parent:      &jira.Parent{Key: "TEST-42"},
	},
}
// marshall it to JSON
j, _ := json.Marshal(issue)
fmt.Println(string(j))

output:

{
  "fields": {
    "description": "This issue marshalls to JSON with a parent that Jira does not like.",
    "issuetype": { "name": "Subtask" },
    "parent": {
      "id": "",  // <-- this empty string prevents Jira from finding the parent ticket
      "key": "TEST-42"
    },
    "project": { "key": "TEST" },
    "summary": "My Test Issue"
  }
}

When the above issue is passed to client.Issue.Create, Jira responds with {"errorMessages":[],"errors":{"parent":"Could not find issue by id or key."}} despite the fact that the parent ticket (TEST-42) exists.

Expected behavior

The above Parent struct should marshal to { "key": "TEST-42" } (no id). When that payload is passed to Jira it correctly finds the parent issue.

Possible Solution

I recognize this may be a limitation of the way go marshals structs to json. Ideally, Parent would contain pointers to strings so that they could be nil and then be correctly omitted by json.Marshal.

Your Environment

  • go-jira version (git tag or sha): v1.14.0
  • Go version (go version): 1.16.6
  • Jira type (cloud or on-premise): cloud

Additional context

I am open to other solutions. I am able to create the issue as a subtask by including the ID, it is just one more piece of information i'd rather not carry around. Thank you for your time and great client!

@pirtleshell pirtleshell changed the title Unable to set parent by key (without issue ID) Unable to create issue with parent by parent issue key (without parent issue ID) Dec 8, 2021
@github-actions
Copy link

github-actions bot commented Dec 8, 2021

Hi! Thank you for taking the time to create your first issue! Really cool to see you here for the first time. Please give us a bit of time to review it.

@cmcpasserby
Copy link
Contributor

@pirtleshell string pointers are not needed, was just a case of the struct tags for Parent missing there omitempty entries. see changes in #435

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants