Skip to content

APIs for managing group level integrations

What does this MR do and why?

The GitLab API allows interaction with service integrations on a project level only, not on a group level. See #328496. Hence we've added APIs that support group-level integrations in this MR.

Screenshots or screen recordings

Screenshot_from_2024-09-28_20-48-46

How to set up and validate locally

  1. (Assuming a group exists) Generate an access token with appropriate permissions for a group you would like to test with. In my tests, I generated a group level PAT token with an owner role.
  2. Store the access token in a bash variable, I used GITLAB_ACCESS_TOKEN:
export GITLAB_ACCESS_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxx
  1. Find the ID of the group you are testing - this can be found as "Group ID" in the groups general settings
  • image
  1. using this ID (I'm using 35 for my ID below), run various curl commands in the command line that correspond to API operations that exist in a project:

Create an integration:

curl --request PUT --header "Private-Token: $GITLAB_ACCESS_TOKEN" --header "Content-Type: application/json" --data '{\n       "token": "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11",\n       "room": "@mychannel",\n       "active": true,\n       "notify_only_broken_pipelines": true,\n       "branches_to_be_notified": "all",\n       "push_events": true,\n       "issues_events": true,\n       "confidential_issues_events": false,\n       "merge_requests_events": true,\n       "tag_push_events": true,\n       "note_events": true,\n       "confidential_note_events": false,\n       "pipeline_events": true,\n       "wiki_page_events": true\n     }' "http://localhost:3000/api/v4/groups/35/integrations/telegram"\n

(Note: telegram, like many other integrations will require manual activation through the UI. You will not see it in the index before this manual activation. To activate, go to the group integrations in the group settings, click the "Configure" on the target integration, and check the "active" checkbox when you land on the integration config page)

image

Get an index of group integrations:

curl --header "Private-Token: $GITLAB_ACCESS_TOKEN" "http://localhost:3000/api/v4/groups/35/integrations"

Delete an integration:

curl --request DELETE --header "Private-Token: $GITLAB_ACCESS_TOKEN" "http://localhost:3000/api/v4/groups/35/integrations/telegram"\n

With each command, check to see that the group integrations in the UI are responding accordingly.

You might also try creating some integrations that are forbidden through the API, such as slack:

curl --request PUT --header "Private-Token: $GITLAB_ACCESS_TOKEN" --header "Content-Type: application/json" --data '{"webhook": "https://hooks.slack.com/services/...", "username": "gitlab", "channel": "#general"}' "http://localhost:3000/api/v4/groups/35/integrations/slack"

This should result in an error:

{"message":"You cannot create the Slack notifications integration from the API"}
Edited by Van Anderson

Merge request reports

Loading