go-jira
go-jira copied to clipboard
Add support to the Get User API functions for Key and Username
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.:
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.
Any chance of this getting fixed/merged? I've run into the same problem... AccountID == ""
, causing a panic due to a nil pointer.
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?
@JalonSolov Can you elaborate this a bit more? E.g. with a code sample or even an alternative PR?
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.