go-jira icon indicating copy to clipboard operation
go-jira copied to clipboard

iterate over ProjectList

Open rsteube opened this issue 3 years ago • 8 comments

Describe the bug

My go skills might be lacking for this but i can't iterate over the the anonymous ProjectList slice. Attempts to cast it didn't work so far.

To Reproduce

projects, _, err := client.Project.GetList()
for project := range projects {
}

Expected behavior

Be able to iterate and access values.

Possible Solution

https://github.com/rsteube/go-jira/commit/86280631ea084fb9f0ca369237347b919dbf56b9

Your Environment

On-Premise: v8.16.1

Additional context

rsteube avatar May 20 '21 11:05 rsteube

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.

github-actions[bot] avatar May 20 '21 11:05 github-actions[bot]

Thanks @rsteube.

Which Jira Version + Type (On-Premise or Cloud) are you using?

andygrunwald avatar May 20 '21 12:05 andygrunwald

On-Premise: v8.16.1

rsteube avatar May 20 '21 13:05 rsteube

Hitting the same issue on Datacenter v8.16.1. Unfortunately I've not been able to test on older versions.

ihulsbus avatar Jun 01 '21 14:06 ihulsbus

It's rather a go problem as the underlying struct (Project) is anonymous and as far as i know can't be casted (maybe with reflection).

rsteube avatar Jun 01 '21 14:06 rsteube

A fresh view on the issue the next day made the issue quite apparent to me. Two possible solutions that work:

projects, _, err := jiraClient.Project.GetList()
if err != nil {
	fmt.Printf("encountered a api error %v\n", err)
}

for _, project := range *projects {
	fmt.Printf("key: %v\n", project.Key)
}

or

for i := 0; i < len(*projects); i++ {
	fmt.Printf("key: %v\n", (*projects)[i])
}

The key here is to dereference the pointer, and it should work.

ihulsbus avatar Jun 02 '21 08:06 ihulsbus

Now that's weird. Could swear i tried that and it just wouldn't compile. Anyway thanks and sorry for bothering you with this (duh!).

rsteube avatar Jun 02 '21 09:06 rsteube

Seems to be difficult for users. I reopen this to check if we can make it easier in the future versions.

andygrunwald avatar Jun 02 '21 14:06 andygrunwald

Hey,

I am very sorry that this issue has been open for a long time with no final solution. We work on this project in our spare time, and sometimes, other priorities take over. This is the typical open source dilemma.

However, there is news: We are kicking off v2 of this library 🚀

To provide visibility, we created the Road to v2 Milestone and calling for your feedback in https://github.com/andygrunwald/go-jira/issues/489

The development will take some time; however, I hope you can benefit from the changes. If you seek priority development for your issue + you like to sponsor it, please contact me.

What does this mean for my issue?

We will work on this issue indirectly. This means that during the development phase, we aim to tackle it. Maybe in a different way like it is currently handled. Please understand that this will take a while because we are running this in our spare time.

Final words

Thanks for using this library. If there is anything else you would like to tell us, let us know!

andygrunwald avatar Aug 21 '22 14:08 andygrunwald