보호된 브랜치 API

Tier: Free, Premium, Ultimate Offering: GitLab.com, Self-managed, GitLab Dedicated

유효한 액세스 레벨

액세스 레벨은 ProtectedRefAccess.allowed_access_levels 메서드에서 정의됩니다. 현재 이러한 레벨들이 인식됩니다:

0  => 액세스 없음
30 => 개발자 액세스
40 => 유지자 액세스
60 => 관리자 액세스

보호된 브랜치 목록

프로젝트에서 UI에서 정의된대로 보호된 브랜치 목록을 가져옵니다. 와일드카드가 설정된 경우, 해당 와일드카드와 일치하는 브랜치의 정확한 이름 대신 반환됩니다.

GET /projects/:id/protected_branches
속성 유형 필수 여부 설명
id 정수/문자열 인증된 사용자가 소유한 프로젝트의 ID 또는 URL 인코딩된 경로
search 문자열 아니요 검색할 보호된 브랜치의 이름 또는 일부분
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/protected_branches"

예시 응답:

[
  {
    "id": 1,
    "name": "main",
    "push_access_levels": [
      {
        "id":  1,
        "access_level": 40,
        "access_level_description": "유지자"
      },
      {
        "id": 2,
        "access_level": 40,
        "access_level_description": "배포 키",
        "deploy_key_id": 1
      }
    ],
    "merge_access_levels": [
      {
        "id":  1,
        "access_level": 40,
        "access_level_description": "유지자"
      }
    ],
    "allow_force_push":false,
    "code_owner_approval_required": false
  },
  {
    "id": 1,
    "name": "release/*",
    "push_access_levels": [
      {
        "id":  1,
        "access_level": 40,
        "access_level_description": "유지자"
      }
    ],
    "merge_access_levels": [
      {
        "id":  1,
        "access_level": 40,
        "access_level_description": "유지자"
      }
    ],
  ...
]

GitLab Premium 또는 Ultimate를 사용하는 사용자는 user_idgroup_idinherited 매개변수도 볼 수 있습니다. inherited 매개변수가 있는 경우, 설정이 프로젝트 그룹에서 상속되었음을 의미합니다.

예시 응답:

[
  {
    "id": 1,
    "name": "main",
    "push_access_levels": [
      {
        "id":  1,
        "access_level": 40,
        "user_id": null,
        "group_id": null,
        "access_level_description": "유지자"
      },
      {
        "id": 2,
        "access_level": 40
        "access_level_description": "배포 키",
        "deploy_key_id": 1,
        "user_id": null,
        "group_id": null
      }
    ],
    "merge_access_levels": [
      {
        "id":  1,
        "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 정수/문자열 인증된 사용자가 소유한 프로젝트의 ID 또는 URL 인코딩된 경로
name 문자열 브랜치 또는 와일드카드의 이름
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/protected_branches/main"

예시 응답:

{
  "id": 1,
  "name": "main",
  "push_access_levels": [
    {
      "id":  1,
      "access_level": 40,
      "access_level_description": "유지자"
    }
  ],
  "merge_access_levels": [
    {
      "id":  1,
      "access_level": 40,
      "access_level_description": "유지자"
    }
  ],
  "allow_force_push":false,
  "code_owner_approval_required": false
}

GitLab Premium 또는 Ultimate를 사용하는 사용자는 user_idgroup_id 매개변수도 볼 수 있습니다:

예시 응답:

{
  "id": 1,
  "name": "main",
  "push_access_levels": [
    {
      "id":  1,
      "access_level": 40,
      "user_id": null,
      "group_id": null,
      "access_level_description": "유지자"
    }
  ],
  "merge_access_levels": [
    {
      "id":  1,
      "access_level": null,
      "user_id": null,
      "group_id": 1234,
      "access_level_description": "예제 병합 그룹"
    }
  ],
  "allow_force_push":false,
  "code_owner_approval_required": false
}

저장소 브랜치 보호

와일드카드 보호된 브랜치를 사용하여 단일 저장소 브랜치 또는 여러 프로젝트 저장소 브랜치를 보호합니다.

POST /projects/:id/protected_branches
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 integer/string yes 인증된 사용자가 소유한 프로젝트의 ID 또는 URL-인코딩된 경로
name string yes 브랜치 또는 와일드카드의 이름
allow_force_push boolean no 활성화되면, 이 브랜치로 푸시할 수 있는 멤버는 강제 푸시도 할 수 있습니다. (기본값: false)
allowed_to_merge array no 각각 {user_id: integer}, {group_id: integer}, 또는 {access_level: integer} 형식의 해시로 설명된 병합 액세스 수준의 배열. 프리미엄 및 얼티밋 전용.
allowed_to_push array no 각각 {user_id: integer}, {group_id: integer}, 또는 {access_level: integer} 형식의 해시로 설명된 푸시 액세스 수준의 배열. 프리미엄 및 얼티밋 전용.
allowed_to_unprotect array no 각각 {user_id: integer}, {group_id: integer}, 또는 {access_level: integer} 형식의 해시로 설명된 언프로텍트 액세스 수준의 배열. 이 필드에 대해 No access 액세스 수준은 사용할 수 없습니다. 프리미엄 및 얼티밋 전용.
code_owner_approval_required boolean no 이 브랜치로 푸시하는 것을 금지하려면 CODEOWNERS 파일 항목과 일치하는 경우 (기본값: false) 프리미엄 및 얼티밋 전용.
merge_access_level integer no 병합할 수 있는 액세스 수준. (기본값: 40, 관리자 역할)
push_access_level integer no 푸시할 수 있는 액세스 수준. (기본값: 40, 관리자 역할)
unprotect_access_level integer no 언프로텍트할 수 있는 액세스 수준. (기본값: 40, 관리자 역할)

예시 응답:

{
  "id": 1,
  "name": "*-stable",
  "push_access_levels": [
    {
      "id":  1,
      "access_level": 30,
      "access_level_description": "개발자 + 유지보수자"
    }
  ],
  "merge_access_levels": [
    {
      "id":  1,
      "access_level": 30,
      "access_level_description": "개발자 + 유지보수자"
    }
  ],
  "unprotect_access_levels": [
    {
      "id":  1,
      "access_level": 40,
      "access_level_description": "유지보수자"
    }
  ],
  "allow_force_push":false,
  "code_owner_approval_required": false
}

GitLab 프리미엄 또는 얼티밋 사용자는 user_idgroup_id 매개변수도 확인합니다.

예시 응답:

{
  "id": 1,
  "name": "*-stable",
  "push_access_levels": [
    {
      "id":  1,
      "access_level": 30,
      "user_id": null,
      "group_id": null,
      "access_level_description": "개발자 + 유지보수자"
    }
  ],
  "merge_access_levels": [
    {
      "id":  1,
      "access_level": 30,
      "user_id": null,
      "group_id": null,
      "access_level_description": "개발자 + 유지보수자"
    }
  ],
  "unprotect_access_levels": [
    {
      "id":  1,
      "access_level": 40,
      "user_id": null,
      "group_id": null,
      "access_level_description": "유지보수자"
    }
  ],
  "allow_force_push":false,
  "code_owner_approval_required": false
}

사용자 / 그룹 레벨 액세스 예시

Tier: 프리미엄, 얼티밋 Offering: GitLab.com, Self-managed, GitLab Dedicated

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": 1,
  "name": "*-stable",
  "push_access_levels": [
    {
      "id":  1,
      "access_level": null,
      "user_id": 1,
      "group_id": null,
      "access_level_description": "관리자"
    }
  ],
  "merge_access_levels": [
    {
      "id":  1,
      "access_level": 40,
      "user_id": null,
      "group_id": null,
      "access_level_description": "유지보수자"
    }
  ],
  "unprotect_access_levels": [
    {
      "id":  1,
      "access_level": 40,
      "user_id": null,
      "group_id": null,
      "access_level_description": "유지보수자"
    }
  ],
  "allow_force_push":false,
  "code_owner_approval_required": false
}

allow to push 및 allow to merge 액세스가 포함된 예제

세부 정보: Tier: 프리미엄, 얼티밋 Offering: GitLab.com, 자체 관리, GitLab 전용

  • 13.9에서 GitLab 프리미엄으로 이전되었습니다.

예제 요청:

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": 5,
    "name": "main",
    "push_access_levels": [
        {
            "id": 1,
            "access_level": 30,
            "access_level_description": "개발자 + 유지보수자",
            "user_id": null,
            "group_id": null
        }
    ],
    "merge_access_levels": [
        {
            "id": 1,
            "access_level": 30,
            "access_level_description": "개발자 + 유지보수자",
            "user_id": null,
            "group_id": null
        },
        {
            "id": 2,
            "access_level": 40,
            "access_level_description": "유지보수자",
            "user_id": null,
            "group_id": null
        }
    ],
    "unprotect_access_levels": [
        {
            "id": 1,
            "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
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/protected_branches/*-stable"
속성 유형 필수 여부 설명
id 정수/문자열 인증된 사용자가 소유한 프로젝트의 ID 또는 URL 인코딩된 경로
name 문자열 브랜치의 이름

보호된 브랜치 업데이트

보호된 브랜치를 업데이트합니다.

PATCH /projects/:id/protected_branches/:name
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"
속성 유형 필수 여부 설명
id 정수/문자열 인증된 사용자가 소유한 프로젝트의 ID 또는 URL 인코딩된 경로
name 문자열 브랜치 또는 와일드카드의 이름
allow_force_push 부울 아니오 활성화되면, 해당 브랜치로 푸시할 수 있는 멤버들이 강제로 푸시할 수도 있습니다.
allowed_to_merge 배열 아니오 머지 액세스 레벨의 배열이며, 각각 {user_id: integer}, {group_id: integer}, 또는 {access_level: integer} 형식의 해시로 설명됩니다. 프리미엄 및 얼티밋 전용.
allowed_to_push 배열 아니오 푸시 액세스 레벨의 배열이며, 각각 {user_id: integer}, {group_id: integer}, 또는 {access_level: integer} 형식의 해시로 설명됩니다. 프리미엄 및 얼티밋 전용.
allowed_to_unprotect 배열 아니오 보호 해제 액세스 레벨의 배열이며, 각각 {user_id: integer}, {group_id: integer}, {access_level: integer}, 또는 {id: integer, _destroy: true} 형식의 해시로 설명됩니다. 기존 액세스 레벨을 삭제하려면 _destroytrue로 전달해야 합니다. No access 액세스 레벨은 이 필드에 사용할 수 없습니다. 프리미엄 및 얼티밋 전용.
code_owner_approval_required 부울 아니오 브랜치가 CODEOWNERS 파일 항목과 일치하는 경우 푸시를 방지합니다. 프리미엄 및 얼티밋 전용.

allowed_to_push, allowed_to_mergeallowed_to_unprotect 배열의 요소는 user_id, group_id 또는 access_level 중 하나이어야 합니다. 각 요소는 {user_id: integer}, {group_id: integer} 또는 {access_level: integer} 형식을 따라야 하며 다음 예제를 참조하세요.

업데이트하려면:

  • user_id: 업데이트된 사용자가 프로젝트에 액세스 권한이 있는지 확인하세요. 또한 해당 해시 내의 access_levelid도 전달해야 합니다.
  • group_id: 업데이트된 그룹이 이 프로젝트를 공유했는지 확인하세요. 또한 해당 해시 내의 access_levelid도 전달해야 합니다.

삭제하려면:

  • _destroytrue로 전달해야 합니다. 다음 예제를 참조하세요.

예시: 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": []
}

관련 주제