- 保護されたブランチのリスト
- 単一のプロテクトブランチまたはワイルドカードプロテクトブランチを取得します。
- リポジトリブランチの保護
- リポジトリブランチの保護解除
- ブランチ1つに対してコードオーナーの承認が必要
保護ブランチAPI
注:この機能は GitLab 9.5 で導入されました。
有効なアクセスレベル
アクセスレベルはProtectedRefAccess.allowed_access_levels
メソッドで定義されています。現在、これらのレベルは認識されています:
0 => No access
30 => Developer access
40 => Maintainer access
60 => Admin access
保護されたブランチのリスト
プロジェクトから protected ブランチの一覧を取得します。
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": "master",
"push_access_levels": [
{
"access_level": 40,
"access_level_description": "Maintainers"
}
],
"merge_access_levels": [
{
"access_level": 40,
"access_level_description": "Maintainers"
}
],
"code_owner_approval_required": "false"
},
...
]
GitLabStarter、Bronze以上のユーザーには、user_id
とgroup_id
パラメータも表示されます:
回答例
[
{
"id": 1,
"name": "master",
"push_access_levels": [
{
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"merge_access_levels": [
{
"access_level": null,
"user_id": null,
"group_id": 1234,
"access_level_description": "Example Merge Group"
}
],
"code_owner_approval_required": "false"
},
...
]
単一のプロテクトブランチまたはワイルドカードプロテクトブランチを取得します。
単一のプロテクトブランチまたはワイルドカードのプロテクトブランチを取得します。
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/master"
回答例
{
"id": 1,
"name": "master",
"push_access_levels": [
{
"access_level": 40,
"access_level_description": "Maintainers"
}
],
"merge_access_levels": [
{
"access_level": 40,
"access_level_description": "Maintainers"
}
],
"code_owner_approval_required": "false"
}
GitLabStarter、Bronze以上のユーザーには、user_id
とgroup_id
パラメータも表示されます:
回答例
{
"id": 1,
"name": "master",
"push_access_levels": [
{
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"merge_access_levels": [
{
"access_level": null,
"user_id": null,
"group_id": 1234,
"access_level_description": "Example Merge Group"
}
],
"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
| 整数/文字列 | はい | 認証されたユーザーが所有するプロジェクトのIDまたはURLエンコードされたパス |
name
| 列 | はい | ブランチの名前またはワイルドカード |
push_access_level
| 列 | いいえ | プッシュできるアクセスレベル (デフォルト:40 , メンテナーのアクセスレベル)
|
merge_access_level
| 列 | いいえ | マージできるアクセスレベル (デフォルト:40 , メンテナーのアクセスレベル)
|
unprotect_access_level
| 列 | いいえ | 保護解除を許可するアクセスレベル (デフォルト:40 , メンテナーのアクセスレベル)
|
allowed_to_push
| アレイ | いいえ | プッシュが許可されるアクセスレベルの配列。 |
allowed_to_merge
| アレイ | いいえ | マージが許可されるアクセスレベルの配列。 |
allowed_to_unprotect
| アレイ | いいえ | 保護解除を許可するアクセスレベルの配列。 |
code_owner_approval_required
| ブーリアン | いいえ |
CODEOWNERS ファイルの項目と一致した場合に、このブランチへのプッシュを防ぎます。
|
回答例
{
"id": 1,
"name": "*-stable",
"push_access_levels": [
{
"access_level": 30,
"access_level_description": "Developers + Maintainers"
}
],
"merge_access_levels": [
{
"access_level": 30,
"access_level_description": "Developers + Maintainers"
}
],
"unprotect_access_levels": [
{
"access_level": 40,
"access_level_description": "Maintainers"
}
],
"code_owner_approval_required": "false"
}
GitLabStarter、Bronze以上のユーザーには、user_id
とgroup_id
パラメータも表示されます:
回答例
{
"id": 1,
"name": "*-stable",
"push_access_levels": [
{
"access_level": 30,
"user_id": null,
"group_id": null,
"access_level_description": "Developers + Maintainers"
}
],
"merge_access_levels": [
{
"access_level": 30,
"user_id": null,
"group_id": null,
"access_level_description": "Developers + Maintainers"
}
],
"unprotect_access_levels": [
{
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"code_owner_approval_required": "false"
}
ユーザー/グループレベルでのアクセス例
allowed_to_push
/allowed_to_merge
/allowed_to_unprotect
配列の要素は、{user_id: integer}
,{group_id: integer}
または{access_level: integer}
の形式を取る必要があります。 各ユーザはプロジェクトにアクセスする必要があり、各グループはこのプロジェクトを共有する必要があります。 これらのアクセスレベルは、保護されたブランチへのアクセスをより細かく制御することができ、GitLab 10.3 EE でAPI に追加されました。
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": [
{
"access_level": null,
"user_id": 1,
"group_id": null,
"access_level_description": "Administrator"
}
],
"merge_access_levels": [
{
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"unprotect_access_levels": [
{
"access_level": 40,
"user_id": null,
"group_id": null,
"access_level_description": "Maintainers"
}
],
"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
| 列 | はい | ブランチの名前 |
ブランチ1つに対してコードオーナーの承認が必要
指定されたブランチ保護ブランチの「コードオーナーの承認が必要」オプションを更新します。
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"
属性 | タイプ | 必須 | 説明 |
---|---|---|---|
id
| 整数/文字列 | はい | 認証されたユーザーが所有するプロジェクトのIDまたはURLエンコードされたパス |
name
| 列 | はい | ブランチの名前 |
code_owner_approval_required
| ブーリアン | いいえ |
CODEOWNERS ファイルの項目と一致した場合に、このブランチへのプッシュを防ぎます。
|