그룹 수준 보호된 브랜치 API

Tier: Premium, Ultimate Offering: Self-Managed
  • 소개됨 GitLab 15.9에 플래그group_protected_branches와 함께. 기본적으로 비활성화됨.
  • 플래그 group_protected_branchesGitLab 15.11에서 allow_protected_branches_for_group로 이름 변경함.
Self-Managed형 GitLab에서는 기본적으로 이 기능을 사용할 수 없습니다. 사용하려면 관리자가 인증된 사용자 소유의 그룹의 URL-인코딩 경로 또는 ID를 나타내는 allow_protected_branches_for_group 피처 플래그를 활성화할 수 있습니다. GitLab.com 및 전담형 GitLab에서는 이 기능을 사용할 수 없습니다.

유효한 액세스 레벨

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

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

보호된 브랜치 디렉터리

그룹에서 보호된 브랜치 디렉터리을 가져옵니다. 와일드카드가 설정되어 있으면 해당 와일드카드와 일치하는 브랜치의 정확한 이름 대신 반환됩니다.

GET /groups/:id/protected_branches
속성 유형 필수 설명
id 정수 또는 문자열 인증된 사용자 소유의 그룹의 URL-인코딩 경로 또는 ID.
search 문자열 아니오 검색될 보호된 브랜치의 이름 또는 일부 이름.
curl --header "PRIVATE-TOKEN: <your_access_token>" \
     "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": 1234,
        "access_level_description": "유지 관리자"
      }
    ],
    "merge_access_levels": [
      {
        "id":  1,
        "access_level": 40,
        "user_id": null,
        "group_id": 1234,
        "access_level_description": "유지 관리자"
      }
    ],
    "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": "유지 관리자"
      }
    ],
    "merge_access_levels": [
      {
        "id":  1,
        "access_level": 40,
        "user_id": null,
        "group_id": 1234,
        "access_level_description": "유지 관리자"
      }
    ],
    "force_push로 허용": false,
    "code_owner_approval_required": false
  },
  ...
]

단일 보호된 브랜치 또는 와일드카드 보호된 브랜치 가져오기

단일 보호된 브랜치 또는 와일드카드 보호된 브랜치를 가져옵니다.

GET /groups/:id/protected_branches/:name
속성 유형 필수 설명
id 정수 또는 문자열 인증된 사용자 소유의 그룹의 URL-인코딩 경로 또는 ID.
name 문자열 브랜치 또는 와일드카드의 이름.
curl --header "PRIVATE-TOKEN: <your_access_token>" \
     "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": "유지 관리자"
    }
  ],
  "merge_access_levels": [
    {
      "id":  1,
      "access_level": null,
      "user_id": null,
      "group_id": 1234,
      "access_level_description": "예시 Merge 그룹"
    }
  ],
  "force_push로 허용": false,
  "`CODEOWNERS` 파일"](../user/project/codeowners/index.md) 항목과 일치하는 경우  브랜치로의 푸시를 방지합니다. 기본값: `false`. |
| `merge_access_level`             | 정수   | 아니오 | Merge할  있는 액세스 레벨. 기본값: `40`, 유지 관리자 역할.           |
| `push_access_level`              | 정수   | 아니오 | 푸시할  있는 액세스 레벨. 기본값: `40`, 유지 관리자 역할.          |
| `unprotect_access_level`         | 정수   | 아니오 | 언프로텍트할  있는 액세스 레벨. 기본값: `40`, 유지 관리자 역할.     |

예시 응답:

```json
{
  "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": "유지 관리자"
    }
  ],
  "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/groups/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
}

푸시 및 Merge 액세스가 있는 경우의 예시

예시 요청:

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/groups/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 /groups/:id/protected_branches/:name
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" \
     "https://gitlab.example.com/api/v4/groups/5/protected_branches/*-stable"
속성 유형 필수 설명
id 정수 또는 문자열 인증된 사용자가 소유한 그룹의 ID 또는 URL로 인코딩된 경로
name 문자열 브랜치 이름

예시 응답:

{
   "name": "main",
   "push_access_levels": [
      {
         "id": 12,
         "access_level": 40,
         "access_level_description": "유지자",
         "user_id": null,
         "group_id": null
      }
   ]
}

보호된 브랜치 업데이트

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

PATCH /groups/:id/protected_branches/:name
curl --request PATCH --header "PRIVATE-TOKEN: <your_access_token>" \
     "https://gitlab.example.com/api/v4/groups/5/protected_branches/feature-branch?allow_force_push=true&code_owner_approval_required=true"
속성 유형 필수 설명
id 정수 또는 문자열 인증된 사용자가 소유한 그룹의 ID 또는 URL로 인코딩된 경로
name 문자열 브랜치 이름
allow_force_push 부울 아니오 사용시, 이 브랜치로 푸시할 수 있는 멤버는 강제 푸시도 할 수 있습니다.
allowed_to_push 배열 아니오 각각을 해시로 설명한 푸시 액세스 레벨의 배열
allowed_to_merge 배열 아니오 각각을 해시로 설명한 Merge 액세스 레벨의 배열
allowed_to_unprotect 배열 아니오 각각을 해시로 설명한 보호 해제 액세스 레벨의 배열
code_owner_approval_required 부울 아니오 CODEOWNERS 파일과 일치하는 경우 이 브랜치로의 푸시 방지. 기본: false

allowed_to_push, allowed_to_merge, allowed_to_unprotect 배열의 요소는:

  • user_id, group_id, 또는 access_level 중 하나여야 합니다.
  • {user_id: integer}, {group_id: integer}, 또는 {access_level: integer} 형식을 취해야합니다.

업데이트하려면:

  • user_id: 업데이트된 사용자가 프로젝트에 액세스해야합니다. 또한 해당 해시의 id도 전달해야합니다.
  • group_id: 업데이트된 그룹이 이 프로젝트를 공유해야합니다. 또한 해당 해시의 id도 전달해야합니다.

삭제하려면:

  • _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/groups/22034114/protected_branches/main"

예시 응답:

{
   "name": "main",
   "push_access_levels": [
      {
         "id": 12,
         "access_level": 40,
         "access_level_description": "유지자",
         "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/groups/22034114/protected_branches/main"

예시 응답:

{
   "name": "main",
   "push_access_levels": [
      {
         "id": 12,
         "access_level": 0,
         "access_level_description": "아무도",
         "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/groups/22034114/protected_branches/main"

예시 응답:

{
   "name": "main",
   "push_access_levels": []
}