Add user as a collaborator in GitHub project
Adds a collaborator to an organisation project and sets their permission level. You must be an organisation owner or a project admin to add a collaborator in Github.
Assumption
A project in Github.
Custom field type Single Line Text. (our is customfield_10600)
Setup Authentication
Use either OAuth or Personal access tokens
Steps
Create a new Action by clicking Create button
Enter a name: Add user as a collaborator in GitHub project and click Create
Use Template Category Default with application/json template to get Content-Type set.
Select Method: PUT and URL: https://github.com/users/myuser/projects/1/collaborators/{{issue.customfield_10600}}
From the Github REST API we can read that to add a user to a project we need to do a PUT as described here: https://developer.github.com/v3/projects/collaborators/#add-user-as-a-collaboratorSelect Authentication method: Select one of the authentications that was created during the Setup Authentication step.
Add request headers, key:
Accept with value application/vnd.github.hellcat-preview+json
Accept with value application/vnd.github.v3+json
On the Body section add the following
{ "name":"{{issue.reporter.username}}" }Here we use the mustache syntax to grab the user name of the reporter.
Click Triggers tab
Select Issue RESOLVED event, in this example we will use the Issue Resolved event to indicate that the user shall be added.
On JQL Condition. When to execute the event(s) write Project = TESTB and to limit the trigger to the TESTB project
Click SAVE
(Optional) Click Test button (no issue key is needed) to and click Send, Then go Log Tab.
Result will have a response like the one below:
{
"name": "Warehouse",
"self": "http://localhost/rest/api/2/group?groupname=Warehouse",
"users": {
"size": 2,
"items": [],
"max-results": 50,
"start-index": 0,
"end-index": 0
},
"expand": "users"
}Optional steps to inform the reporter about being added is to create a chained action that comments the issue.