Questions for Confluence license has expired.

Please purchase a new license to continue using Questions for Confluence.

Sync asignee from Jira to Github

 
1
0
-1

We are looking to sync assignee from Jira to assignee to Github.

Is there a way to match assignee based on their full name? And is there a way to match assignee based on multiple emails?

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      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)


      1. James Linder

        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)



      2. Juan Grases

        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.

      3. James Linder

        Thanks for your answer Juan.


        I've figured out what was happening.


        1. I initially was setting assignee = nodeHelper.getUserByUsername("myGitHubUserName") . That never set the assignee in GitHub.

        2. 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.

      CommentAdd your comment...