GitLab: редактирование описания запроса на слияние вызывает отправку запроса на слияние - PullRequest
10 голосов
/ 21 марта 2019

Для моего репозитория на GitLab у меня настроен Захват запроса на слияние , который запускает сборку на машине Jenkins CI.Перехватчики работают, как и ожидалось, при открытии запроса на слияние.

Веб-крючок настроен со следующими триггерами:

В последнее время, когда я редактирую описание запросов на слияние, затемловушка также уведомляет компьютер CI.
Вот пример запроса POST:

Заголовки запроса:

Content-Type: application/json
X-Gitlab-Event: Merge Request Hook

Тело запроса:

{
  "object_kind": "merge_request",
  "event_type": "merge_request",
  "user": {
    "name": "User Name",
    "username": "username",
    "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/145/avatar.png"
  },
  "project": {
    "id": 39,
    "name": "app",
    "description": "Lorem ipsum.",
    "web_url": "https://gitlab.example.com/projects/app",
    "avatar_url": "https://gitlab.example.com/uploads/-/system/project/avatar/39/app.png",
    "git_ssh_url": "git@gitlab.example.com:projects/app.git",
    "git_http_url": "https://gitlab.example.com/projects/app.git",
    "namespace": "projects",
    "visibility_level": 0,
    "path_with_namespace": "projects/app",
    "default_branch": "develop",
    "ci_config_path": null,
    "homepage": "https://gitlab.example.com/projects/app",
    "url": "git@gitlab.example.com:projects/app.git",
    "ssh_url": "git@gitlab.example.com:projects/app.git",
    "http_url": "https://gitlab.example.com/projects/app.git"
  },
  "object_attributes": {
    "assignee_id": null,
    "author_id": 5,
    "created_at": "2019-03-19 16:42:28 UTC",
    "description": "- s. https://fabric.io/development/projects/apps/com.example.app/issues/5974e5ffbe077a4dcc044254?time=last-thirty-days\r\n- Lorem ipsum.",
    "head_pipeline_id": 7473,
    "id": 9258,
    "iid": 844,
    "last_edited_at": "2019-03-20 09:00:21 UTC",
    "last_edited_by_id": 145,
    "merge_commit_sha": null,
    "merge_error": null,
    "merge_params": {
      "force_remove_source_branch": "1"
    },
    "merge_status": "can_be_merged",
    "merge_user_id": null,
    "merge_when_pipeline_succeeds": false,
    "milestone_id": null,
    "source_branch": "fix/random",
    "source_project_id": 39,
    "state": "opened",
    "target_branch": "develop",
    "target_project_id": 39,
    "time_estimate": 0,
    "title": "Fix random",
    "updated_at": "2019-03-20 09:00:21 UTC",
    "updated_by_id": 145,
    "url": "https://gitlab.example.com/projects/app/merge_requests/844",
    "source": {
      "id": 39,
      "name": "app",
      "description": "Lorem ipsum.",
      "web_url": "https://gitlab.example.com/projects/app",
      "avatar_url": "https://gitlab.example.com/uploads/-/system/project/avatar/39/app.png",
      "git_ssh_url": "git@gitlab.example.com:projects/app.git",
      "git_http_url": "https://gitlab.example.com/projects/app.git",
      "namespace": "projects",
      "visibility_level": 0,
      "path_with_namespace": "projects/app",
      "default_branch": "develop",
      "ci_config_path": null,
      "homepage": "https://gitlab.example.com/projects/app",
      "url": "git@gitlab.example.com:projects/app.git",
      "ssh_url": "git@gitlab.example.com:projects/app.git",
      "http_url": "https://gitlab.example.com/projects/app.git"
    },
    "target": {
      "id": 39,
      "name": "app",
      "description": "Lorem ipsum.",
      "web_url": "https://gitlab.example.com/projects/app",
      "avatar_url": "https://gitlab.example.com/uploads/-/system/project/avatar/39/app.png",
      "git_ssh_url": "git@gitlab.example.com:projects/app.git",
      "git_http_url": "https://gitlab.example.com/projects/app.git",
      "namespace": "projects",
      "visibility_level": 0,
      "path_with_namespace": "projects/app",
      "default_branch": "develop",
      "ci_config_path": null,
      "homepage": "https://gitlab.example.com/projects/app",
      "url": "git@gitlab.example.com:projects/app.git",
      "ssh_url": "git@gitlab.example.com:projects/app.git",
      "http_url": "https://gitlab.example.com/projects/app.git"
    },
    "last_commit": {
      "id": "cdda6f7d200468955ecbd224f0437932db607087",
      "message": "Fix random\n\n",
      "timestamp": "2019-03-20T08:45:40Z",
      "url": "https://gitlab.example.com/projects/app/commit/cdda6f7d200468955ecbd224f0437932db607087",
      "author": {
        "name": "User Name",
        "email": "username"
      }
    },
    "work_in_progress": false,
    "total_time_spent": 0,
    "human_total_time_spent": null,
    "human_time_estimate": null,
    "action": "update"
  },
  "labels": [
    {
      "id": 22,
      "title": "Bug fix",
      "color": "#FF0000",
      "project_id": null,
      "created_at": "2018-10-19 09:55:26 UTC",
      "updated_at": "2018-11-05 15:17:08 UTC",
      "template": false,
      "description": "",
      "type": "GroupLabel",
      "group_id": 15
    }
  ],
  "changes": {
    "description": {
      "previous": "s. https://fabric.io/development/projects/apps/com.example.app/issues/5974e5ffbe077a4dcc044254?time=last-thirty-days\r\nLorem ipsum.",
      "current": "- s. https://fabric.io/development/projects/apps/com.example.app/issues/5974e5ffbe077a4dcc044254?time=last-thirty-days\r\n- Lorem ipsum."
    },
    "last_edited_at": {
      "previous": "2019-03-19 16:42:50 UTC",
      "current": "2019-03-20 09:00:21 UTC"
    },
    "last_edited_by_id": {
      "previous": 5,
      "current": 145
    },
    "updated_at": {
      "previous": "2019-03-20 08:52:38 UTC",
      "current": "2019-03-20 09:00:21 UTC"
    },
    "updated_by_id": {
      "previous": 5,
      "current": 145
    }
  },
  "repository": {
    "name": "app",
    "url": "git@gitlab.example.com:projects/app.git",
    "description": "Lorem ipsum.",
    "homepage": "https://gitlab.example.com/projects/app"
  }
}

Заголовки ответа:

Server: nginx/1.10.3 (Ubuntu)
Date: Wed, 20 Mar 2019 09:00:21 GMT
Transfer-Encoding: chunked
Connection: close
X-Content-Type-Options: nosniff

Плагин Jenkins выглядит следующим образом:

Jenkins GitLab plugin

На машине Jenkins установлены следующие плагины GitLab:

Installed Jenkins GitLab plugins

Как настроить отправку запроса POST на компьютер CI только при создании или обновлении ветви запроса pull?

1 Ответ

4 голосов
/ 02 апреля 2019

Под триггерами (Настройки -> Интеграции) выполните следующие действия:

  1. Включение событий push (необязательное имя ветви - ветвь создается посредством событий push даже до того, как возможен MR)
  2. Включить триггеры событий MR в вашем репо проекта

Этот URL будет активирован при создании / обновлении / объединении запроса на слияние

enter image description here

В конфигурации плагина Jenkins -

  1. Проверка «Push-событий» (любые коммиты посредством прямого Push или создания)
  2. Отмена «Открыта»События запроса на слияние "
  3. Проверка" Принятые события запроса на слияние "(любые коммиты посредством запроса на слияние)
...