그룹 수준 보호된 브랜치 API
GitLab v19.5Offering: GitLab Self-Managed
요약
이 API를 사용해 그룹 내 모든 프로젝트가 상속하는 보호된 브랜치 설정을 관리합니다. 그룹의 보호된 브랜치 설정은 최상위 그룹에서만 사용할 수 있습니다. 액세스 레벨은 ProtectedRefAccess.allowed_access_levels 메서드에 정의되어 있습니다.
히스토리
- GitLab 17.6에서 정식 출시되었습니다. 기능 플래그
group_protected_branches가 제거되었습니다.
이 API를 사용해 그룹 내 모든 프로젝트가 상속하는 보호된 브랜치 설정을 관리합니다. 그룹의 보호된 브랜치는 유효한 액세스 레벨만 지원하며, GitLab Ultimate에서는 커스텀 역할도 지원합니다. 개별 사용자와 그룹은 지정할 수 없습니다.
그룹의 보호된 브랜치 설정은 최상위 그룹에서만 사용할 수 있습니다.
유효한 액세스 레벨#
액세스 레벨은 ProtectedRefAccess.allowed_access_levels 메서드에 정의되어 있습니다.
인식되는 레벨은 다음과 같습니다.
0 => No access
30 => Developer access
40 => Maintainer access
60 => Admin access
보호된 브랜치 목록 조회#
그룹의 보호된 브랜치 목록을 가져옵니다. 와일드카드가 설정되어 있으면 해당 와일드카드와 일치하는 브랜치의 정확한 이름 대신 와일드카드가 반환됩니다.
GET /groups/:id/protected_branches
| 속성 | 유형 | 필수 | 설명 |
|---|---|---|---|
id |
integer or string | 예 | 그룹의 ID 또는 URL 인코딩된 경로입니다. |
search |
string | 아니요 | 검색할 보호된 브랜치의 이름 또는 이름 일부입니다. |
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/5/protected_branches"
응답 예시:
[
{
"id": 1,
"name": "main",
"push_access_levels": [
{
"id": 1,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"merge_access_levels": [
{
"id": 1,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"allow_force_push":false,
"code_owner_approval_required": false
},
{
"id": 1,
"name": "release/*",
"push_access_levels": [
{
"id": 1,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"merge_access_levels": [
{
"id": 1,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"allow_force_push":false,
"code_owner_approval_required": false
},
...
]
단일 보호된 브랜치 또는 와일드카드 보호된 브랜치 조회#
단일 보호된 브랜치 또는 와일드카드 보호된 브랜치를 가져옵니다.
GET /groups/:id/protected_branches/:name
| 속성 | 유형 | 필수 | 설명 |
|---|---|---|---|
id |
integer or string | 예 | 그룹의 ID 또는 URL 인코딩된 경로입니다. |
name |
string | 예 | 브랜치 또는 와일드카드의 이름입니다. |
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/5/protected_branches/main"
응답 예시:
{
"id": 1,
"name": "main",
"push_access_levels": [
{
"id": 1,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"merge_access_levels": [
{
"id": 1,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"allow_force_push":false,
"code_owner_approval_required": false
}
리포지터리 브랜치 보호#
히스토리
- GitLab 19.2에서
custom_roles_for_protected_branches라는 기능 플래그와 함께member_role_id파라미터가 도입되었습니다. 기본적으로 비활성화되어 있습니다. - GitLab 19.4에서 정식 출시되었습니다. 기능 플래그
custom_roles_for_protected_branches가 제거되었습니다.
와일드카드 보호된 브랜치를 사용해 단일 리포지터리 브랜치를 보호합니다.
POST /groups/:id/protected_branches
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/5/protected_branches?name=*-stable&push_access_level=30&merge_access_level=30&unprotect_access_level=40"
| 속성 | 유형 | 필수 | 설명 |
|---|---|---|---|
id |
integer or string | 예 | 그룹의 ID 또는 URL 인코딩된 경로입니다. |
name |
string | 예 | 브랜치 또는 와일드카드의 이름입니다. |
allow_force_push |
boolean | 아니요 | 푸시 권한이 있는 모든 사용자에게 강제 푸시를 허용합니다. 기본값: false. |
allowed_to_merge |
array | 아니요 | 머지를 허용할 액세스 레벨의 배열이며, 각 항목은 {access_level: integer} 또는 {member_role_id: integer} 형태의 해시로 기술합니다. member_role_id는 Ultimate 에서만 사용할 수 있습니다. |
allowed_to_push |
array | 아니요 | 푸시를 허용할 액세스 레벨의 배열이며, 각 항목은 {access_level: integer} 또는 {member_role_id: integer} 형태의 해시로 기술합니다. member_role_id는 Ultimate 에서만 사용할 수 있습니다. |
allowed_to_unprotect |
array | 아니요 | 보호 해제를 허용할 액세스 레벨의 배열이며, 각 항목은 {access_level: integer} 또는 {member_role_id: integer} 형태의 해시로 기술합니다. member_role_id는 Ultimate 에서만 사용할 수 있습니다. |
code_owner_approval_required |
boolean | 아니요 | CODEOWNERS 파일의 항목과 일치하면 이 브랜치로의 푸시를 차단합니다. 기본값: false. |
merge_access_level |
integer | 아니요 | 머지를 허용할 액세스 레벨입니다. 기본값: 40, Maintainer 권한. 커스텀 역할은 지원하지 않습니다. 대신 member_role_id와 함께 allowed_to_merge를 사용합니다. |
push_access_level |
integer | 아니요 | 푸시를 허용할 액세스 레벨입니다. 기본값: 40, Maintainer 권한. 커스텀 역할은 지원하지 않습니다. 대신 member_role_id와 함께 allowed_to_push를 사용합니다. |
unprotect_access_level |
integer | 아니요 | 보호 해제를 허용할 액세스 레벨입니다. 기본값: 40, Maintainer 권한. 커스텀 역할은 지원하지 않습니다. 대신 member_role_id와 함께 allowed_to_unprotect를 사용합니다. |
응답 예시:
{
"id": 1,
"name": "*-stable",
"push_access_levels": [
{
"id": 1,
"access_level": 30,
"user_id": null,
"group_id": null,
"access_level_description": "Developers + Maintainers"
}
],
"merge_access_levels": [
{
"id": 1,
"access_level": 30,
"user_id": null,
"group_id": null,
"access_level_description": "Developers + Maintainers"
}
],
"unprotect_access_levels": [
{
"id": 1,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"allow_force_push":false,
"code_owner_approval_required": false
}
액세스 레벨을 사용하는 예제#
액세스 레벨로 그룹의 보호된 브랜치를 구성합니다.
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--data '{
"name": "main",
"allowed_to_push": [{"access_level": 30}],
"allowed_to_merge": [{
"access_level": 30
},{
"access_level": 40
}
]}' \
--url "https://gitlab.example.com/api/v4/groups/5/protected_branches"
응답 예시:
{
"id": 5,
"name": "main",
"push_access_levels": [
{
"id": 1,
"access_level": 30,
"access_level_description": "Developers + Maintainers",
"user_id": null,
"group_id": null
}
],
"merge_access_levels": [
{
"id": 1,
"access_level": 30,
"access_level_description": "Developers + Maintainers",
"user_id": null,
"group_id": null
},
{
"id": 2,
"access_level": 40,
"access_level_description": "Maintainers",
"user_id": null,
"group_id": null
}
],
"unprotect_access_levels": [
{
"id": 1,
"access_level": 40,
"access_level_description": "Maintainers",
"user_id": null,
"group_id": null
}
],
"allow_force_push":false,
"code_owner_approval_required": false
}
커스텀 역할을 사용하는 예제#
member_role_id를 사용하면 커스텀 역할이 그룹의 보호된 브랜치로 머지하도록 허용할 수 있습니다.
해당 커스텀 역할은 보호된 브랜치와 같은 최상위 그룹에 속해야 합니다.
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--data '{
"name": "main",
"allowed_to_merge": [{"member_role_id": 42}],
"push_access_level": 40
}' \
--url "https://gitlab.example.com/api/v4/groups/5/protected_branches"
응답 예시:
{
"id": 5,
"name": "main",
"push_access_levels": [
{
"id": 1,
"access_level": 40,
"access_level_description": "Maintainers",
"user_id": null,
"group_id": null
}
],
"merge_access_levels": [
{
"id": 1,
"access_level": 30,
"access_level_description": "Lead Developer",
"user_id": null,
"group_id": null,
"member_role_id": 42,
"member_role_name": "Lead Developer"
}
],
"allow_force_push":false,
"code_owner_approval_required": false
}
리포지터리 브랜치 보호 해제#
지정한 보호된 브랜치 또는 와일드카드 보호된 브랜치의 보호를 해제합니다.
DELETE /groups/:id/protected_branches/:name
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/5/protected_branches/*-stable"
| 속성 | 유형 | 필수 | 설명 |
|---|---|---|---|
id |
integer or string | 예 | 그룹의 ID 또는 URL 인코딩된 경로입니다. |
name |
string | 예 | 브랜치의 이름입니다. |
응답 예시:
{
"name": "main",
"push_access_levels": [
{
"id": 12,
"access_level": 40,
"access_level_description": "Maintainers",
"user_id": null,
"group_id": null
}
]
}
보호된 브랜치 업데이트#
히스토리
- GitLab 19.2에서
custom_roles_for_protected_branches라는 기능 플래그와 함께member_role_id파라미터가 도입되었습니다. 기본적으로 비활성화되어 있습니다. - GitLab 19.5에서 정식 출시되었습니다. 기능 플래그
custom_roles_for_protected_branches가 제거되었습니다.
보호된 브랜치를 업데이트합니다.
PATCH /groups/:id/protected_branches/:name
curl --request PATCH \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/5/protected_branches/feature-branch?allow_force_push=true&code_owner_approval_required=true"
| 속성 | 유형 | 필수 | 설명 |
|---|---|---|---|
id |
integer or string | 예 | 그룹의 ID 또는 URL 인코딩된 경로입니다. |
name |
string | 예 | 브랜치의 이름입니다. |
allow_force_push |
boolean | 아니요 | 활성화하면 이 브랜치로 푸시할 수 있는 멤버가 강제 푸시도 할 수 있습니다. |
allowed_to_push |
array | 아니요 | 푸시 액세스 레벨의 배열이며, 각 항목은 해시로 기술합니다. |
allowed_to_merge |
array | 아니요 | 머지 액세스 레벨의 배열이며, 각 항목은 해시로 기술합니다. |
allowed_to_unprotect |
array | 아니요 | 보호 해제 액세스 레벨의 배열이며, 각 항목은 해시로 기술합니다. |
code_owner_approval_required |
boolean | 아니요 | CODEOWNERS 파일의 항목과 일치하면 이 브랜치로의 푸시를 차단합니다. 기본값: false. |
allowed_to_push, allowed_to_merge, allowed_to_unprotect 배열의 요소는 {access_level: integer} 형태이거나,
GitLab Ultimate에서는 커스텀 역할을 허용하기 위해
{member_role_id: integer} 형태여야 합니다.
각 액세스 레벨은 유효한 액세스 레벨 중 하나여야 합니다.
member_role_id가 참조하는 커스텀 역할은 보호된 브랜치와 같은 최상위 그룹에 속해야 합니다.
- 액세스 레벨을 업데이트하려면 해당 해시에
access_level의id도 함께 전달해야 합니다. - 액세스 레벨을 삭제하려면
_destroy를true로 전달해야 합니다. 다음 예제를 참고합니다.
예제: push_access_level 레코드 생성#
curl --request PATCH \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--data '{"allowed_to_push": [{"access_level": 40}]}' \
--url "https://gitlab.example.com/api/v4/groups/5/protected_branches/main"
응답 예시:
{
"name": "main",
"push_access_levels": [
{
"id": 12,
"access_level": 40,
"access_level_description": "Maintainers",
"user_id": null,
"group_id": null
}
]
}
예제: push_access_level 레코드 업데이트#
curl --request PATCH \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--data '{"allowed_to_push": [{"id": 12, "access_level": 0}]}' \
--url "https://gitlab.example.com/api/v4/groups/5/protected_branches/main"
응답 예시:
{
"name": "main",
"push_access_levels": [
{
"id": 12,
"access_level": 0,
"access_level_description": "No One",
"user_id": null,
"group_id": null
}
]
}
예제: push_access_level 레코드 삭제#
curl --request PATCH \
--header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--data '{"allowed_to_push": [{"id": 12, "_destroy": true}]}' \
--url "https://gitlab.example.com/api/v4/groups/5/protected_branches/main"
응답 예시:
{
"name": "main",
"push_access_levels": []
}