보호된 브랜치 API
유효한 접근 수준
접근 수준은 ProtectedRefAccess.allowed_access_levels
메서드에서 정의됩니다. 다음 수준이 인식됩니다:
0 => 접근 불가
30 => 개발자 접근
40 => 유지 관리 접근
60 => 관리자 접근
보호된 브랜치 목록
- 배포 키 정보 소개됨 GitLab 16.0.
프로젝트에서 UI에 정의된 대로 보호된 브랜치의 목록을 가져옵니다. 와일드카드가 설정된 경우, 그와 일치하는 브랜치의 정확한 이름 대신 반환됩니다.
GET /projects/:id/protected_branches
속성 | 타입 | 필수 | 설명 |
---|---|---|---|
id |
integer/string | 예 | 프로젝트의 ID 또는 URL 인코딩된 경로 |
search |
string | 아니요 | 검색할 보호된 브랜치의 이름 또는 이름의 일부 |
다음 예제에서 프로젝트 ID는 5
입니다.
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/protected_branches"
다음 예제 응답에는:
- ID가
100
및101
인 두 개의 보호된 브랜치가 포함됩니다. - ID가
1001
,1002
,1003
인push_access_levels
. - ID가
2001
,2002
인merge_access_levels
.
[
{
"id": 100,
"name": "main",
"push_access_levels": [
{
"id": 1001,
"access_level": 40,
"access_level_description": "유지 관리"
},
{
"id": 1002,
"access_level": 40,
"access_level_description": "배포 키",
"deploy_key_id": 1
}
],
"merge_access_levels": [
{
"id": 2001,
"access_level": 40,
"access_level_description": "유지 관리"
}
],
"allow_force_push":false,
"code_owner_approval_required": false
},
{
"id": 101,
"name": "release/*",
"push_access_levels": [
{
"id": 1003,
"access_level": 40,
"access_level_description": "유지 관리"
}
],
"merge_access_levels": [
{
"id": 2002,
"access_level": 40,
"access_level_description": "유지 관리"
}
],
"allow_force_push":false,
"code_owner_approval_required": false
},
...
]
GitLab Premium 또는 Ultimate 사용자는 user_id
, group_id
및 inherited
매개변수도 확인할 수 있습니다. inherited
매개변수가 존재하는 경우, 해당 설정이 프로젝트의 그룹에서 상속되었음을 의미합니다.
다음 예제 응답에는:
- ID가
100
인 하나의 보호된 브랜치가 포함됩니다. - ID가
1001
,1002
인push_access_levels
. - ID가
2001
인merge_access_levels
.
[
{
"id": 101,
"name": "main",
"push_access_levels": [
{
"id": 1001,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "유지 관리"
},
{
"id": 1002,
"access_level": 40,
"access_level_description": "배포 키",
"deploy_key_id": 1,
"user_id": null,
"group_id": null
}
],
"merge_access_levels": [
{
"id": 2001,
"access_level": null,
"user_id": null,
"group_id": 1234,
"access_level_description": "예제 병합 그룹"
}
],
"allow_force_push":false,
"code_owner_approval_required": false,
"inherited": true
},
...
]
단일 보호 브랜치 또는 와일드카드 보호 브랜치 가져오기
단일 보호 브랜치 또는 와일드카드 보호 브랜치를 가져옵니다.
GET /projects/:id/protected_branches/:name
속성 | 유형 | 필수 | 설명 |
---|---|---|---|
id |
integer/string | 예 | 프로젝트의 ID 또는 URL 인코딩된 경로 |
name |
string | 예 | 브랜치 이름 또는 와일드카드 |
다음 예제에서 프로젝트 ID는 5
이고 브랜치 이름은 main
입니다:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/protected_branches/main"
예시 응답:
{
"id": 101,
"name": "main",
"push_access_levels": [
{
"id": 1001,
"access_level": 40,
"access_level_description": "Maintainers"
}
],
"merge_access_levels": [
{
"id": 2001,
"access_level": 40,
"access_level_description": "Maintainers"
}
],
"allow_force_push":false,
"code_owner_approval_required": false
}
GitLab Premium 또는 Ultimate 사용자는 user_id
및 group_id
매개변수도 확인할 수 있습니다:
예시 응답:
{
"id": 101,
"name": "main",
"push_access_levels": [
{
"id": 1001,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"merge_access_levels": [
{
"id": 2001,
"access_level": null,
"user_id": null,
"group_id": 1234,
"access_level_description": "Example Merge Group"
}
],
"allow_force_push":false,
"code_owner_approval_required": false
}
리포지토리 브랜치 보호
deploy_key_id
구성 도입됨 GitLab 17.5에서.
단일 리포지토리 브랜치 또는 와일드카드 보호 브랜치를 사용하여 여러 프로젝트 리포지토리 브랜치를 보호합니다.
POST /projects/:id/protected_branches
속성 | 유형 | 필수 | 설명 |
---|---|---|---|
id |
integer/string | 예 | 프로젝트의 ID 또는 URL 인코딩된 경로. |
name |
string | 예 | 브랜치 이름 또는 와일드카드. |
allow_force_push |
boolean | 아니요 | 활성화되면, 이 브랜치에 푸시할 수 있는 멤버는 강제 푸시도 할 수 있습니다. (기본값: false ) |
allowed_to_merge |
array | 아니요 | 머지 접근 수준 배열, 각 항목은 {user_id: integer} , {group_id: integer} , 또는 {access_level: integer} 형식의 해시로 설명됩니다. Premium 및 Ultimate 전용. |
allowed_to_push |
array | 아니요 | 푸시 접근 수준 배열, 각 항목은 {user_id: integer} , {group_id: integer} , {deploy_key_id: integer} , 또는 {access_level: integer} 형식의 해시로 설명됩니다. Premium 및 Ultimate 전용. |
allowed_to_unprotect |
array | 아니요 | 언프로텍트 접근 수준 배열, 각 항목은 {user_id: integer} , {group_id: integer} , 또는 {access_level: integer} 형식의 해시로 설명됩니다. 접근 수준 No access 는 이 필드에서 사용할 수 없습니다. Premium 및 Ultimate 전용. |
code_owner_approval_required |
boolean | 아니요 |
CODEOWNERS 파일에서 항목과 일치하면 이 브랜치에 대한 푸시를 방지합니다. (기본값: false) Premium 및 Ultimate 전용. |
merge_access_level |
integer | 아니요 | 머지를 허용하는 접근 수준. (기본값: 40 , Maintainer 역할). |
push_access_level |
integer | 아니요 | 푸시를 허용하는 접근 수준. (기본값: 40 , Maintainer 역할) |
unprotect_access_level |
integer | 아니요 | 언프로텍트를 허용하는 접근 수준. (기본값: 40 , Maintainer 역할) |
다음 예제에서 프로젝트 ID는 5
이고 브랜치 이름은 *-stable
입니다.
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/protected_branches?name=*-stable&push_access_level=30&merge_access_level=30&unprotect_access_level=40"
예시 응답에는 다음이 포함됩니다:
- ID가
101
인 보호된 브랜치. - ID가
1001
인push_access_levels
. - ID가
2001
인merge_access_levels
. - ID가
3001
인unprotect_access_levels
.
{
"id": 101,
"name": "*-stable",
"push_access_levels": [
{
"id": 1001,
"access_level": 30,
"access_level_description": "Developers + Maintainers"
}
],
"merge_access_levels": [
{
"id": 2001,
"access_level": 30,
"access_level_description": "Developers + Maintainers"
}
],
"unprotect_access_levels": [
{
"id": 3001,
"access_level": 40,
"access_level_description": "Maintainers"
}
],
"allow_force_push":false,
"code_owner_approval_required": false
}
GitLab Premium 또는 Ultimate 사용자는 user_id
및 group_id
매개변수도 확인할 수 있습니다:
다음 예시 응답에는 다음이 포함됩니다:
- ID가
101
인 보호된 브랜치. - ID가
1001
인push_access_levels
. - ID가
2001
인merge_access_levels
. - ID가
3001
인unprotect_access_levels
.
{
"id": 1,
"name": "*-stable",
"push_access_levels": [
{
"id": 1001,
"access_level": 30,
"user_id": null,
"group_id": null,
"access_level_description": "Developers + Maintainers"
}
],
"merge_access_levels": [
{
"id": 2001,
"access_level": 30,
"user_id": null,
"group_id": null,
"access_level_description": "Developers + Maintainers"
}
],
"unprotect_access_levels": [
{
"id": 3001,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"allow_force_push":false,
"code_owner_approval_required": false
}
사용자 / 그룹 수준 접근 예제
allowed_to_push
/ allowed_to_merge
/ allowed_to_unprotect
배열의 요소는
형태 {user_id: integer}
, {group_id: integer}
또는 {access_level: integer}
이어야 합니다.
각 사용자는 프로젝트에 접근할 수 있어야 하며, 각 그룹은 이 프로젝트를 공유해야 합니다.
이 접근 수준은 보호된 브랜치 접근을 더 세분화하여 제어할 수 있습니다.
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/protected_branches?name=*-stable&allowed_to_push%5B%5D%5Buser_id%5D=1"
다음 예제 응답에는 다음이 포함됩니다:
- ID가
101
인 보호된 브랜치. - ID가
1001
인push_access_levels
. - ID가
2001
인merge_access_levels
. - ID가
3001
인unprotect_access_levels
.
{
"id": 101,
"name": "*-stable",
"push_access_levels": [
{
"id": 1001,
"access_level": null,
"user_id": 1,
"group_id": null,
"access_level_description": "Administrator"
}
],
"merge_access_levels": [
{
"id": 2001,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"unprotect_access_levels": [
{
"id": 3001,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"allow_force_push":false,
"code_owner_approval_required": false
}
배포 키 접근 예제
- 도입됨 GitLab 17.5에서.
allowed_to_push
배열의 요소는 {user_id: integer}
, {group_id: integer}
,
{deploy_key_id: integer}
또는 {access_level: integer}
형태여야 합니다.
배포 키는 귀하의 프로젝트에 대해 활성화되어야 하며, 귀하의 프로젝트 리포지토리에 대한 쓰기 권한이 있어야 합니다.
기타 요구 사항은 보호된 브랜치에 푸시할 수 있도록 배포 키 허용을 참조하십시오.
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/protected_branches?name=*-stable&allowed_to_push[][deploy_key_id]=1"
다음 예제 응답에는 다음이 포함됩니다:
- ID가
101
인 보호된 브랜치. - ID가
1001
인push_access_levels
. - ID가
2001
인merge_access_levels
. - ID가
3001
인unprotect_access_levels
.
{
"id": 101,
"name": "*-stable",
"push_access_levels": [
{
"id": 1001,
"access_level": null,
"user_id": null,
"group_id": null,
"deploy_key_id": 1,
"access_level_description": "Deploy"
}
],
"merge_access_levels": [
{
"id": 2001,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"unprotect_access_levels": [
{
"id": 3001,
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"allow_force_push":false,
"code_owner_approval_required": false
}
예제: 푸시 및 병합 접근 허용
- GitLab Premium으로 13.9에서 이동되었습니다.
예제 요청:
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}
]
}'
"https://gitlab.example.com/api/v4/projects/5/protected_branches"
다음 예제 응답에는 다음이 포함됩니다:
- ID
105
인 보호된 브랜치. - ID
1001
이 있는push_access_levels
. - ID
2001
및2002
가 있는merge_access_levels
. - ID
3001
이 있는unprotect_access_levels
.
{
"id": 105,
"name": "main",
"push_access_levels": [
{
"id": 1001,
"access_level": 30,
"access_level_description": "개발자 + 유지관리자",
"user_id": null,
"group_id": null
}
],
"merge_access_levels": [
{
"id": 2001,
"access_level": 30,
"access_level_description": "개발자 + 유지관리자",
"user_id": null,
"group_id": null
},
{
"id": 2002,
"access_level": 40,
"access_level_description": "유지관리자",
"user_id": null,
"group_id": null
}
],
"unprotect_access_levels": [
{
"id": 3001,
"access_level": 40,
"access_level_description": "유지관리자",
"user_id": null,
"group_id": null
}
],
"allow_force_push":false,
"code_owner_approval_required": false
}
저장소 브랜치 보호 해제
주어진 보호된 브랜치 또는 와일드카드 보호 브랜치를 보호 해제합니다.
DELETE /projects/:id/protected_branches/:name
속성 | 유형 | 필수 | 설명 |
---|---|---|---|
id |
정수/문자열 | 예 | 프로젝트의 ID 또는 URL 인코딩된 경로 |
name |
문자열 | 예 | 브랜치의 이름 |
다음 예제에서 프로젝트 ID는 5
이고 브랜치 이름은 *-stable
입니다.
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/protected_branches/*-stable"
보호된 브랜치 업데이트
보호된 브랜치를 업데이트합니다.
PATCH /projects/:id/protected_branches/:name
속성 | 유형 | 필수 | 설명 |
---|---|---|---|
id |
정수/문자열 | 예 | 프로젝트의 ID 또는 URL 인코딩된 경로. |
name |
문자열 | 예 | 브랜치의 이름 또는 와일드카드. |
allow_force_push |
불리언 | 아니오 | 활성화되면, 이 브랜치에 푸시할 수 있는 멤버가 강제 푸시도 할 수 있습니다. |
allowed_to_merge |
배열 | 아니오 | 병합 접근 수준의 배열로, 각 수준은 {user_id: 정수} , {group_id: 정수} , 또는 {access_level: 정수} 형태로 설명됩니다. Premium 및 Ultimate 전용. |
allowed_to_push |
배열 | 아니오 | 푸시 접근 수준의 배열로, 각 수준은 {user_id: 정수} , {group_id: 정수} , {deploy_key_id: 정수} , 또는 {access_level: 정수} 형태로 설명됩니다. Premium 및 Ultimate 전용. |
allowed_to_unprotect |
배열 | 아니오 | 보호 해제 접근 수준의 배열로, 각 수준은 {user_id: 정수} , {group_id: 정수} , {access_level: 정수} , 또는 {id: 정수, _destroy: true} 형태로 설명되어 기존 접근 수준을 파괴합니다. 접근 수준 No access 는 이 필드에서 사용할 수 없습니다. Premium 및 Ultimate 전용. |
code_owner_approval_required |
불리언 | 아니오 |
CODEOWNERS 파일과 일치하는 항목이 있을 경우 이 브랜치에 대한 푸시를 방지합니다. Premium 및 Ultimate 전용. |
다음 예제에서 프로젝트 ID는 5
이고 브랜치 이름은 feature-branch
입니다.
curl --request PATCH --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/protected_branches/feature-branch?allow_force_push=true&code_owner_approval_required=true"
allowed_to_push
, allowed_to_merge
, allowed_to_unprotect
배열의 요소는 user_id
, group_id
또는 access_level
중 하나여야 하며 다음 형식을 취합니다: {user_id: 정수}
, {group_id: 정수}
또는 {access_level: 정수}
.
allowed_to_push
에는 {deploy_key_id: 정수}
형식의 추가 요소가 포함됩니다.
업데이트하려면:
-
user_id
: 업데이트된 사용자가 프로젝트에 접근할 수 있도록 해야 합니다. 해당 해시에서access_level
의id
도 전달해야 합니다. -
group_id
: 업데이트된 그룹이 이 프로젝트를 공유하고 있어야 합니다. 해당 해시에서access_level
의id
도 전달해야 합니다. -
deploy_key_id
: 배포 키가 귀하의 프로젝트에 대해 활성화되어 있어야 하며, 프로젝트 저장소에 대한 쓰기 접근이 있어야 합니다.
삭제하려면:
-
_destroy
를true
로 설정하여야 합니다. 다음 예제를 참조하십시오.
예시: push_access_level
레코드 생성
curl --header 'Content-Type: application/json' --request PATCH \
--data '{"allowed_to_push": [{"access_level": 40}]}' \
--header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.example.com/api/v4/projects/22034114/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 --header 'Content-Type: application/json' --request PATCH \
--data '{"allowed_to_push": [{"id": 12, "access_level": 0}]}' \
--header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/22034114/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 --header 'Content-Type: application/json' --request PATCH \
--data '{"allowed_to_push": [{"id": 12, "_destroy": true}]}' \
--header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/22034114/protected_branches/main"
예시 응답:
{
"name": "main",
"push_access_levels": []
}