GItLab
Integration GitLab with Cremit
See below for instructions on how to integrate Cremit’s solution with GitLab.
-
Navigate to the Access Tokens page On the left menu of the group page, go to Settings → Access Tokens.
-
Create a new token Click the Add new token button in the top right corner of the Group Access Tokens page.
-
Fill out the token name and expiration date, then select "Developer" or higher role. For Select Scopes, select read_api and click “Create group access token”
-
Copy the generated as it will be used in the next steps of integration settings.
Confluence-Cremit Integration Setup
-
Log in to Cremit's dashboard, click "Integration" on the left side menu, and then select "GitLab".
-
Fill in the fields: Enter the hostname of your GitLab instance. Group Access Token: Paste the group access token generated earlier. Label: Enter a label to identify the integration. And finally, click “Submit” to complete the integration
-
Complete the integration Click Submit to add the source integration.
Granting multiple project access to a group (Optional)Copied!
If you need to grant access to multiple projects to a specific group at once, follow these steps:
3.1 Generating a user access token
-
Log in to GitLab, go to user menu → 'Preferences' → 'Access Tokens'.
-
Click 'Add new token', enter a token name, select the 'api' scope, and create the token.
-
Securely store the generated token.
3.2 Preparing and running the script
-
Ensure Python and pip are installed.
-
Install the requests module:
$ pip install requests
-
Save the provided script as 'invite_group_to_all_visible_repositories.py'
import sys import re import json from requests import post, get host = sys.argv[1] token = sys.argv[2] group_name = sys.argv[3] if(host.endswith("/")): host = host[:-1] headers = { "Authorization": f"Bearer {token}" } def get_groups(): response = get(f"{host}/api/v4/groups?search={group_name}", headers=headers) return response.json() groups = get_groups() print(json.dumps(groups)) name_matched_groups = [group for group in groups if group["name"] == group_name] if len(name_matched_groups) == 0: print(f"couldn't find group that has name {group_name}") sys.exit(1) group = name_matched_groups[0] group_name = group["name"] payload = { "group_access": 10, "group_id": group["id"] } NEXT_PAGE_PATTERN = re.compile("<(.+)>; rel=\"next\"") def get_projects(): projects = [] response = get(f"{host}/api/v4/projects?order_by=id&sort=asc", headers=headers) projects.extend(response.json()) if "Link" in response.headers: match_result = NEXT_PAGE_PATTERN.search(response.headers["Link"]) if(match_result): next_page_url = match_result[1] else: next_page_url = None else: next_page_url = None while next_page_url: response = get(next_page_url, headers=headers) if "Link" in response.headers: match_result = NEXT_PAGE_PATTERN.search(response.headers["Link"]) if(match_result): next_page_url = match_result[1] else: next_page_url = None else: next_page_url = None projects.extend(response.json()) return projects for project in get_projects(): project_id = project["id"] project_name = project["name"] share_proejct_endpoint = host + f"/api/v4/projects/{project_id}/share" response = post(share_proejct_endpoint, json=payload, headers=headers) if response.status_code == 201: print(f"proejct {project_name} is shared with group {group_name}")</(.+)>
-
Run the script with the following command:
$ python invite_group_to_all_visible_repositories.py {GitLab_host} {user_access_token} {group_name_to_invite}
3.3 Verifying access grant
Check if the group has been successfully invited in each project's 'Manage' → 'Members' → 'Groups' menu.
Important NotesCopied!
-
All access tokens are confidential information and should be managed securely.
-
Tokens should only be used for authorized integration purposes.
-
The 'read_api' permission is essential for querying the list of accessible projects.
-
When granting multiple project permissions to a group, it only applies to projects accessible by the user.w for instructions on how to integrate Cremit’s solution with GitLab.