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

Add support to the Get User API functions for Key and Username #635

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

prarit
Copy link

@prarit prarit commented Jun 12, 2023

What type of PR is this?

  • bug

Optionally add one or more of the following kinds if applicable:

  • api-change

What this PR does / why we need it:

Calling the GetWatchers() function results in a stacktrace [1]

This occurs because the Watchers api no longer returns an AccountID
for each Watcher and now returns a Key and a Username.  The Get User
functions also must be updated to support Key (by default) and Username.

Which issue(s) this PR fixes:

Fixes #634

Special notes for your reviewer:

Additional documentation e.g., usage docs, etc.:

Calling the GetWatchers() function results in a stacktrace [1]

This occurs because the Watchers api no longer returns an AccountID
for each Watcher and now returns a Key and a Username.  The Get User
functions also must be updated to support Key (by default) and Username.

Signed-off-by: Prarit Bhargava <[email protected]>

[1] panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6c0d48]

goroutine 1 [running]:
github.com/andygrunwald/go-jira/v2/onpremise.(*IssueService).GetWatchers(0xc000334030, {0x9c5eb0, 0xc000028120}, {0xc000029c18?, 0xc0002136a0?})
	/home/prarit/go/pkg/mod/github.com/andygrunwald/go-jira/[email protected]/onpremise/issue.go:1373 +0x208
gitlab.com/prarit/rhjira/cmd.GetWatches(0xc000242100)
	/home/prarit/Other/gitlab/rhjira/cmd/lib.go:72 +0x57
gitlab.com/prarit/rhjira/cmd.glob..func1(0xc6e4e0?, {0xc00019a230?, 0x1?, 0x1?})
	/home/prarit/Other/gitlab/rhjira/cmd/dump.go:265 +0x5d2
github.com/spf13/cobra.(*Command).execute(0xc6e4e0, {0xc00019a200, 0x1, 0x1})
	/home/prarit/go/pkg/mod/github.com/spf13/[email protected]/command.go:944 +0x847
github.com/spf13/cobra.(*Command).ExecuteC(0xc6e200)
	/home/prarit/go/pkg/mod/github.com/spf13/[email protected]/command.go:1068 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
	/home/prarit/go/pkg/mod/github.com/spf13/[email protected]/command.go:992
gitlab.com/prarit/rhjira/cmd.Execute(0xc000334030?)
	/home/prarit/Other/gitlab/rhjira/cmd/main.go:25 +0x3e
main.main()
	/home/prarit/Other/gitlab/rhjira/main.go:34 +0x15b

Signed-off-by: Prarit Bhargava <[email protected]>
Fix the issue and user tests to use the new user functions.

Signed-off-by: Prarit Bhargava <[email protected]>
@andygrunwald
Copy link
Owner

Thanks @prarit for this pr.
I am currently short on time for open-source contributions due to other/private obligations. This means the review of this PR can take a bit. Thanks for contributing to open source and thanks for understanding.

@JalonSolov
Copy link

Any chance of this getting fixed/merged? I've run into the same problem... AccountID == "", causing a panic due to a nil pointer.

@JalonSolov
Copy link

In looking at the code, it appears that there might be a simpler "fix" for this, which wouldn't rely on any particular fields other than the one that's always there: self.

The self field is a full URL to get the user info, so why not simply use it directly, instead of trying to find the info with any particular id/key/whatever?

@andygrunwald
Copy link
Owner

@JalonSolov Can you elaborate this a bit more? E.g. with a code sample or even an alternative PR?

@JalonSolov
Copy link

If you look at the JSON returned from GetWatchers, there are only 4 fields, none of them having to do with account ids, etc. However, the self field for each watcher is a link to get the user info (which also does not have an accountid listed).

I was looking through user.go, and in the comment for GetByAccountId it states that all other methods are deprecated... however, since there's no account id to use, that cannot work.

My suggestion is to simply use the URL in the self field to get the User info, which basically does a query on the username.

Alternatively, you can try duplicating the GetByAccountId function in user.go, but replace AccountId with Username, and change the endpoint to user?username=%s... which is exactly what's in the self field for each Watcher.

Note that this may be different between Cloud and OnPremise versions... our OnPremise JIRA install is v9.4.15, with the latest being v9.16.0, and I'm reporting what I've seen with our local install.

I'm looking into trying to do an alternative PR.

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

Successfully merging this pull request may close these issues.

Calling the GetWatchers() function results in a stacktrace
3 participants