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

unmarshal array error on IssueSearchService #2

Closed
5 tasks done
ctreminiom opened this issue Mar 4, 2021 · 2 comments · Fixed by #3
Closed
5 tasks done

unmarshal array error on IssueSearchService #2

ctreminiom opened this issue Mar 4, 2021 · 2 comments · Fixed by #3
Assignees
Labels
bug Something isn't working Jira Software Cloud

Comments

@ctreminiom
Copy link
Owner

ctreminiom commented Mar 4, 2021

go-atlassian version

v1.0.0

go-atlassian component

  • Jira Software Cloud
  • Jira Agile Cloud
  • Jira Service Management Cloud
  • Confluence Cloud
  • Atlassian Admin Cloud

Describe the bug 🐛

The Search Get/Post methods are not able to unmarshal the response body when one issue contains more than 2 components assigned and it's returning the following error:

bash error: json: cannot unmarshal array into Go struct field IssueFieldsScheme.issues.fields.components of type jira.ProjectComponentScheme

To Reproduce 🚧

  1. Go to the Jira Cloud UI issue details view
  2. Edit the issue adding N+1 components.
  3. Search issues using the library with all fields
  4. Loop the IssueSearchScheme struct

Expected behavior ✅

Render the issue components.

Screenshots:page_facing_up:

If applicable, add screenshots to help explain your problem.

Additional context

The component tab is not a slice of structs so if the issue contains more than 1 component, the method breaks

Components *ProjectComponentScheme json:"components,omitempty"

Add any other context about the problem here.

Code snippet

package main

import (
	"context"
	"github.com/ctreminiom/go-atlassian/jira"
	"log"
	"os"
)

func main() {

	var (
		host  = os.Getenv("HOST")
		mail  = os.Getenv("MAIL")
		token = os.Getenv("TOKEN")
	)

	jiraCloud, err := jira.New(nil, host)
	if err != nil {
		return
	}

	jiraCloud.Auth.SetBasicAuth(mail, token)
	jiraCloud.Auth.SetUserAgent("curl/7.54.0")

	var (
		jql    = "order by created DESC"
		fields = []string{"all"}
		expand = []string{"changelog", "renderedFields", "names", "schema", "transitions", "operations", "editmeta"}
	)

	issues, response, err := atlassian.Issue.Search.Get(context.Background(), jql, fields, expand, 0, 50, "")
	if err != nil {
		if response != nil {
			log.Println("Response HTTP Response", string(response.BodyAsBytes))
		}
		log.Fatal(err)
	}

	log.Println("Response HTTP Code", response.StatusCode)
	log.Println("HTTP Endpoint Used", response.Endpoint)

}
@ctreminiom ctreminiom added bug Something isn't working Jira Software Cloud labels Mar 4, 2021
@ctreminiom ctreminiom self-assigned this Mar 4, 2021
@ctreminiom ctreminiom assigned ctreminiom and unassigned ctreminiom Mar 4, 2021
@create-issue-branch
Copy link

@ctreminiom ctreminiom changed the title unmarshal array into Go struct field IssueFieldsScheme.issues.fields.components unmarshal array error on IssueSearchService Mar 4, 2021
@ctreminiom ctreminiom assigned ctreminiom and unassigned ctreminiom Mar 4, 2021
@create-issue-branch
Copy link

ctreminiom added a commit that referenced this issue Mar 4, 2021
@ctreminiom ctreminiom linked a pull request Mar 4, 2021 that will close this issue
@ctreminiom ctreminiom moved this to Released in Roadmap Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Jira Software Cloud
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant