正式なドキュメントは英語版であり、この日本語訳はAI支援翻訳により作成された参考用のものです。日本語訳の一部の内容は人間によるレビューがまだ行われていないため、翻訳のタイミングにより英語版との間に差異が生じることがあります。最新かつ正確な情報については、英語版をご参照ください。

グループレベルの保護ブランチAPI

  • プラン: Premium、Ultimate
  • 提供形態: GitLab Self-Managed

このAPIを使用して、グループ内のすべてのプロジェクトに継承される保護ブランチの設定を管理します。グループの保護ブランチは、有効なアクセスレベルのみをサポートします。個々のユーザーとグループは指定できません。

保護ブランチの設定は、トップレベルグループにのみ限定されます。

有効なアクセスレベル

アクセスレベルは、ProtectedRefAccess.allowed_access_levelsメソッドで定義されています。これらのレベルは認識されます:

0  => No access
30 => Developer access
40 => Maintainer access
60 => Admin access

保護ブランチをリスト表示

グループから保護ブランチのリストを取得します。ワイルドカードが設定されている場合、そのワイルドカードに一致するブランチの正確な名前ではなく、ワイルドカードが返されます。

GET /groups/:id/protected_branches
属性必須説明
id整数または文字列はいグループのIDまたはURLエンコードされたパス
search文字列いいえ検索対象となる保護ブランチの名前またはその一部。
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整数または文字列はいグループのIDまたはURLエンコードされたパス
name文字列はいブランチまたはワイルドカードの名前。
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
}

リポジトリブランチを保護

ワイルドカード保護ブランチを使用して、単一のリポジトリブランチを保護します。

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整数または文字列はいグループのIDまたはURLエンコードされたパス
name文字列はいブランチまたはワイルドカードの名前。
allow_force_pushブール値いいえプッシュアクセス権を持つすべてのユーザーが強制プッシュできるようにします。デフォルト: false
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}の形式のハッシュで記述されます。
code_owner_approval_requiredブール値いいえCODEOWNERSファイル内の項目に一致する場合、このブランチへのプッシュを禁止します。デフォルト: false
merge_access_level整数いいえマージが許可されるアクセスレベル。デフォルト: 40、メンテナーロール。
push_access_level整数いいえプッシュが許可されるアクセスレベル。デフォルト: 40、メンテナーロール。
unprotect_access_level整数いいえ保護解除が許可されるアクセスレベル。デフォルト: 40、メンテナーロール。

レスポンス例:

{
  "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
}

リポジトリブランチの保護を解除

指定された保護ブランチまたはワイルドカード保護ブランチの保護を解除します。

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整数または文字列はいグループのIDまたはURLエンコードされたパス
name文字列はいブランチの名前

レスポンス例:

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

保護ブランチを更新

保護ブランチを更新します。

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整数または文字列はいグループのIDまたはURLエンコードされたパス
name文字列はいブランチの名前
allow_force_pushブール値いいえ有効にすると、このブランチにプッシュできるメンバーも強制プッシュできます。
allowed_to_push配列いいえプッシュアクセスレベルの配列。それぞれハッシュで記述されます。
allowed_to_merge配列いいえマージアクセスレベルの配列。それぞれハッシュで記述されます。
allowed_to_unprotect配列いいえ保護解除アクセスレベルの配列。それぞれハッシュで記述されます。
code_owner_approval_requiredブール値いいえCODEOWNERSファイル内の項目に一致する場合、このブランチへのプッシュを禁止します。デフォルト: false

allowed_to_pushallowed_to_merge、およびallowed_to_unprotect配列内の要素は、{access_level: integer}の形式を取る必要があります。各アクセスレベルは、有効なアクセスレベルから有効な値である必要があります。

  • アクセスレベルを更新するには、それぞれのハッシュで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>" \
  --url "https://gitlab.example.com/api/v4/groups/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>" \
  --url "https://gitlab.example.com/api/v4/groups/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>" \
  --url "https://gitlab.example.com/api/v4/groups/22034114/protected_branches/main"

レスポンス例:

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