Answer by Francis Martens (Exalate) on 21 October 2020
Elinor Garcia-Garcia
This is certainly possible.
First you need to ensure that the assignee information is transported from Jira to Github, by specifying in the outgoing sync (normally it is already there)
Outgoing sync
replica.assignee = issue.assignee
On the incoming side you can use the nodeHelper.getUserByUserName to look up the user by name
Incoming sync - untested
issue.assignees = [nodeHelper.getUserByUsername(replica.assignee.displayName)]
You will need to search the exact syntax (no time now to look it up in detail)
Comments:
James Linder commented on 27 October 2020
Hi,
Iâm testing using nodeHelper.getUserByUsername()
in the GitHub incoming sync by hardcoding my GitHub username and itâs always coming back as `null`. In the docs for `nodeHelper.getUserByUsername()`, it says null is returned when the user name is not found or when the Exalate user has no âBrowse Usersâ permissions. How can I check whether the âBrowse Usersâ permission is given to the Exalate user? and how does one give that permission if itâs not set?
Alternatively, is there another way to create a user object for use in the `issue.assingnee` field?
This is the context in which I am using the function.
def userMap = [
"email1@example.com": "github-username-1",
"email2@example.com": "github-username-2"
]
def assignee = replica.assignee?.username
if (userMap.containsKey(assignee)) {
assignee = userMap[assignee]
}
issue.assignee = nodeHelper.getUserByUsername(assignee)
Juan Grases commented on 29 October 2020
Thatâs strange, the nodeHelper.getUserByUsername should be the way to go on exalate for github. I also wanted you to try to use issue.assignees (which is unique on github)
issue.assignees = [nodeHelper.getUserByUsername(âusernameâ)]
Even though we are documenting the issue.assignee should also work, I think it would be good if you try this way.
James Linder commented on 29 October 2020
Thanks for your answer Juan.
Iâve figured out what was happening.
- I initially was setting
assignee = nodeHelper.getUserByUsername("myGitHubUserName")
. That never set the assignee in GitHub.
- In the code above, I used
replica.assignee?.username
, but the username
field doesnât exist in replica.assignee
. The correct field to use is email
. So since there was never a value for username
, I was always putting a null
into the getUserByUsername
function. So when I had tried issue.assignees = [nodeHelper.getUserByUsername(replica.assignee?.username)]
, it never found a user.
Now that I know to set assignees
and use the email
field, I have it working.
The fully working code is:
def userMap = [
"email1@example.com": "github-username-1",
"email2@example.com": "github-username-2"
]
def assignee = replica.assignee?.email
if (userMap.containsKey(assignee)) {
assignee = userMap[assignee]
}
issue.assignees = [nodeHelper.getUserByUsername(assignee)]
Note: One thing that misled me about replica.assignee?.username
is the example on this doc page where it explicitly uses .username
. If there was an example specifically for the GitHub incoming sync, that would have saved me a lot of time.