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

マージトレインAPI

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

このAPIを使用して、マージトレインを操作します。

前提要件:

  • デベロッパーロール以上が必要です。

プロジェクトのマージトレインを一覧表示

リクエストされたプロジェクトのすべてのマージトレインを取得します:

GET /projects/:id/merge_trains
GET /projects/:id/merge_trains?scope=complete

結果のページネーションを制御するには、pageおよびper_page ページネーションパラメータを使用します。

属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
scope文字列いいえ指定されたスコープでフィルタリングされたマージトレインを返します。使用可能なスコープは、active(マージ対象)とcomplete(マージ済み)です。
sort文字列いいえascまたはdescの順にソートされたマージトレインを返します。デフォルトはdescです。
curl --request GET \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/merge_trains"

戻り値:

  • プロジェクトでマージトレインが利用できない場合は403: Forbidden
  • ユーザーがプライベートプロジェクトのメンバーでない場合は404: Not Found

レスポンス例:

[
  {
    "id": 110,
    "merge_request": {
      "id": 126,
      "iid": 59,
      "project_id": 20,
      "title": "Test MR 1580978354",
      "description": "",
      "state": "merged",
      "created_at": "2020-02-06T08:39:14.883Z",
      "updated_at": "2020-02-06T08:40:57.038Z",
      "web_url": "http://local.gitlab.test:8181/root/merge-train-race-condition/-/merge_requests/59"
    },
    "user": {
      "id": 1,
      "name": "Administrator",
      "username": "root",
      "state": "active",
      "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
      "web_url": "http://local.gitlab.test:8181/root"
    },
    "pipeline": {
      "id": 246,
      "sha": "bcc17a8ffd51be1afe45605e714085df28b80b13",
      "ref": "refs/merge-requests/59/train",
      "status": "success",
      "created_at": "2020-02-06T08:40:42.410Z",
      "updated_at": "2020-02-06T08:40:46.912Z",
      "web_url": "http://local.gitlab.test:8181/root/merge-train-race-condition/pipelines/246"
    },
    "created_at": "2020-02-06T08:39:47.217Z",
    "updated_at": "2020-02-06T08:40:57.720Z",
    "target_branch": "feature-1580973432",
    "status": "merged",
    "merged_at": "2020-02-06T08:40:57.719Z",
    "duration": 70
  }
]

マージトレイン内のマージリクエストを一覧表示

リクエストされたターゲットブランチのマージトレインに追加されたすべてのマージリクエストを取得します。

GET /projects/:id/merge_trains/:target_branch

結果のページネーションを制御するには、pageおよびper_page ページネーションパラメータを使用します。

サポートされている属性は以下のとおりです:

属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
target_branch文字列はいマージトレインのターゲットブランチ。
scope文字列いいえ指定されたスコープでフィルタリングされたマージトレインを返します。使用可能なスコープは、active(マージ対象)とcomplete(マージ済み)です。
sort文字列いいえascまたはdescの順にソートされたマージトレインを返します。デフォルトはdescです。

リクエスト例:

curl --request GET \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/597/merge_trains/main"

戻り値:

  • プロジェクトでマージトレインが利用できない場合は403: Forbidden
  • ユーザーがプライベートプロジェクトのメンバーでない場合は404: Not Found

レスポンス例:

[
  {
    "id": 267,
    "merge_request": {
      "id": 273,
      "iid": 1,
      "project_id": 597,
      "title": "My title 9",
      "description": null,
      "state": "opened",
      "created_at": "2022-10-31T19:06:05.725Z",
      "updated_at": "2022-10-31T19:06:05.725Z",
      "web_url": "http://localhost/namespace18/project21/-/merge_requests/1"
    },
    "user": {
      "id": 933,
      "username": "user12",
      "name": "Sidney Jones31",
      "state": "active",
      "avatar_url": "https://www.gravatar.com/avatar/6c8365de387cb3db10ecc7b1880203c4?s=80\u0026d=identicon",
      "web_url": "http://localhost/user12"
    },
    "pipeline": {
      "id": 273,
      "iid": 1,
      "project_id": 598,
      "sha": "b83d6e391c22777fca1ed3012fce84f633d7fed0",
      "ref": "main",
      "status": "pending",
      "source": "push",
      "created_at": "2022-10-31T19:06:06.231Z",
      "updated_at": "2022-10-31T19:06:06.231Z",
      "web_url": "http://localhost/namespace19/project22/-/pipelines/273"
    },
    "created_at": "2022-10-31T19:06:06.237Z",
    "updated_at":"2022-10-31T19:06:06.237Z",
    "target_branch":"main",
    "status":"idle",
    "merged_at":null,
    "duration":null
  }
]

マージトレイン上のマージリクエストのステータスを取得

リクエストされたマージリクエストのマージトレイン情報を取得します。

GET /projects/:id/merge_trains/merge_requests/:merge_request_iid

結果のページネーションを制御するには、pageおよびper_page ページネーションパラメータを使用します。

サポートされている属性は以下のとおりです:

属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
merge_request_iid整数はいマージリクエストの内部ID。

リクエスト例:

curl --request GET \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/597/merge_trains/merge_requests/1"

戻り値:

  • プロジェクトでマージトレインが利用できない場合は403: Forbidden
  • ユーザーがプライベートプロジェクトのメンバーでない場合は404: Not Found

レスポンス例:

{
  "id": 267,
  "merge_request": {
    "id": 273,
    "iid": 1,
    "project_id": 597,
    "title": "My title 9",
    "description": null,
    "state": "opened",
    "created_at": "2022-10-31T19:06:05.725Z",
    "updated_at": "2022-10-31T19:06:05.725Z",
    "web_url": "http://localhost/namespace18/project21/-/merge_requests/1"
  },
  "user": {
    "id": 933,
    "username": "user12",
    "name": "Sidney Jones31",
    "state": "active",
    "avatar_url": "https://www.gravatar.com/avatar/6c8365de387cb3db10ecc7b1880203c4?s=80\u0026d=identicon",
    "web_url": "http://localhost/user12"
  },
  "pipeline": {
    "id": 273,
    "iid": 1,
    "project_id": 598,
    "sha": "b83d6e391c22777fca1ed3012fce84f633d7fed0",
    "ref": "main",
    "status": "pending",
    "source": "push",
    "created_at": "2022-10-31T19:06:06.231Z",
    "updated_at": "2022-10-31T19:06:06.231Z",
    "web_url": "http://localhost/namespace19/project22/-/pipelines/273"
  },
  "created_at": "2022-10-31T19:06:06.237Z",
  "updated_at":"2022-10-31T19:06:06.237Z",
  "target_branch":"main",
  "status":"idle",
  "merged_at":null,
  "duration":null
}

マージトレインにマージリクエストを追加する

マージリクエストのターゲットブランチを対象とするマージトレインにマージリクエストを追加します。

POST /projects/:id/merge_trains/merge_requests/:merge_request_iid

サポートされている属性は以下のとおりです:

属性必須説明
id整数または文字列はいプロジェクトのIDまたはURLエンコードされたパス
merge_request_iid整数はいマージリクエストの内部ID。
auto_mergeブール値いいえtrueの場合、チェックに合格すると、マージリクエストがマージトレインに追加されます。falseまたは未指定の場合、マージリクエストはマージトレインに直接追加されます。
sha文字列いいえ存在する場合、SHAはソースブランチのHEADと一致している必要があります。一致しない場合、マージは失敗します。
squashブール値いいえtrueの場合、コミットはマージ時に単一のコミットにスカッシュされます。
when_pipeline_succeedsブール値いいえGitLab 17.11で非推奨になりました。代わりにauto_mergeを使用してください。

リクエスト例:

curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/597/merge_trains/merge_requests/1"

成功した場合、以下を返します:

  • マージリクエストがマージトレインにすぐに追加された場合は201 Created
  • マージリクエストがマージトレインに追加されるようにスケジュールされている場合は202 Accepted

その他の発生しうる応答:

  • マージに失敗した場合は400 Bad Request
  • 認証が必要な場合は401 Unauthorized
  • プロジェクトでマージトレインが利用できない場合は403 Forbidden
  • プロジェクトまたはマージリクエストが見つからない場合は404 Not Found
  • 競合するリソースがある場合は409 Conflict

成功すると、レスポンスには次の属性が含まれます:

属性説明
created_at日時マージトレインが作成されたときのタイムスタンプ。
duration整数秒単位の期間、または完了していない場合はnull
id整数マージトレインのID。
merge_requestオブジェクトマージリクエストの詳細。
merge_request.created_at日時マージリクエストが作成された時点のタイムスタンプ。
merge_request.description文字列マージリクエストの説明。
merge_request.id整数マージリクエストのID。
merge_request.iid整数マージリクエストの内部ID。
merge_request.project_id整数マージリクエストを含むプロジェクトのID。
merge_request.state文字列マージリクエストの状態。
merge_request.title文字列マージリクエストのタイトル。
merge_request.updated_at日時マージリクエストの最終更新時のタイムスタンプ。
merge_request.web_url文字列マージリクエストのWeb URL。
merged_at日時マージリクエストがマージされたときのタイムスタンプ。マージされていない場合はnull
pipelineオブジェクトパイプラインの詳細
pipeline.created_at日時パイプラインの作成時のタイムスタンプ。
pipeline.id整数パイプラインのID。
pipeline.iid整数パイプラインの内部ID。
pipeline.project_id整数パイプラインを含むプロジェクトのID。
pipeline.ref文字列パイプラインのGit参照。
pipeline.sha文字列パイプラインをトリガーしたコミットのSHA。
pipeline.source文字列パイプライントリガーのソース。
pipeline.status文字列パイプラインのステータス。
pipeline.updated_at日時パイプラインの最終更新時のタイムスタンプ。
pipeline.web_url文字列パイプラインのWeb URL。
status文字列マージトレインのステータス。使用可能な値:idlemergedstalefreshmergingskip_merged
target_branch文字列ターゲットブランチの名前。
updated_at日時マージトレインの最終更新時のタイムスタンプ。
userオブジェクトマージトレインにマージリクエストを追加したユーザー。
user.avatar_url文字列ユーザーのアバターURL。
user.id整数ユーザーのID。
user.name文字列ユーザー名。
user.state文字列ユーザーアカウントの状態。
user.username文字列ユーザーのユーザー名。
user.web_url文字列ユーザープロフィールのWeb URL。

レスポンス例:

[
  {
    "id": 267,
    "merge_request": {
      "id": 273,
      "iid": 1,
      "project_id": 597,
      "title": "My title 9",
      "description": null,
      "state": "opened",
      "created_at": "2022-10-31T19:06:05.725Z",
      "updated_at": "2022-10-31T19:06:05.725Z",
      "web_url": "http://localhost/namespace18/project21/-/merge_requests/1"
    },
    "user": {
      "id": 933,
      "username": "user12",
      "name": "Sidney Jones31",
      "state": "active",
      "avatar_url": "https://www.gravatar.com/avatar/6c8365de387cb3db10ecc7b1880203c4?s=80\u0026d=identicon",
      "web_url": "http://localhost/user12"
    },
    "pipeline": {
      "id": 273,
      "iid": 1,
      "project_id": 598,
      "sha": "b83d6e391c22777fca1ed3012fce84f633d7fed0",
      "ref": "main",
      "status": "pending",
      "source": "push",
      "created_at": "2022-10-31T19:06:06.231Z",
      "updated_at": "2022-10-31T19:06:06.231Z",
      "web_url": "http://localhost/namespace19/project22/-/pipelines/273"
    },
    "created_at": "2022-10-31T19:06:06.237Z",
    "updated_at":"2022-10-31T19:06:06.237Z",
    "target_branch":"main",
    "status":"idle",
    "merged_at":null,
    "duration":null
  }
]