When you Exalate a Jira ticket to GitHub, it would not be assigned to any GitHub project. In this use case, we will control the allocation of the GitHub issue to a project board, but we will base this selection from what the user selects on the Jira ticket i.e. user will select the target GitHub project for the issue from his own ticket.
The following depicts what we are trying to achieve:
We have used two custom fields within the Jira issue for the user to make the relevant selections. Once the project and status are chosen on these custom fields, Exalate would allocate the corresponding GitHub issue to the relevant project, and assign it the correct status. In order for all this to happen, the following steps are necessary:
Jira needs to ensure that the value of these fields is being sent to GitHub. This can be done using the following lines in Jira Outgoing Script:
In GitHub, we would need to make several API calls in order to get the project assigned etc. So, we will start by adding the GroovyHttpClient code to our Incoming script on the GitHub side:
Now we can make the relevant API calls to achieve our use case. The first call (following code) will extract the contentId of the GitHub issue in order to use it in the subsequent GraphQL calls:
Next we run a GraphQL call to retrieve the projectId of the correct GitHub project. This will be done be retrieving a list of GitHub projects and then matching the names to see if there is a match for the project selected by the user from the Jira custom field:
We are now ready to add the GitHub issue to the correct project by utilizing the projectId and contentId (retrieved in the previous 2 steps). The API call also returns the itemId that corresponds to the issue's id within the project (and will be needed in sunsequent calls):
To deal with the issue status within the GitHub project/board, we need to work with the GraphQL calls again, and in order to do so we now need the fieldId of the status field itself and also the id of the status that we are trying to change to in the project:
The final step is to just change the ticket status: