Repository: xanzy/go-gitlab
Pull request #752 (2019-12-26 14:42:49)

Pipeline webhook merge request detail


Patch:
diff --git a/event_types.go b/event_types.go
index 1b1298b..d4d3595 100644
--- a/event_types.go
+++ b/event_types.go
@@ -329,40 +329,40 @@ type MergeCommentEvent struct {
 	} `json:"object_attributes"`
 	Repository   *Repository `json:"repository"`
 	MergeRequest struct {
-		ID              int    `json:"id"`
-		TargetBranch    string `json:"target_branch"`
-		SourceBranch    string `json:"source_branch"`
-		SourceProjectID int    `json:"source_project_id"`
-		AuthorID        int    `json:"author_id"`
-		AssigneeID      int    `json:"assignee_id"`
-		Title           string `json:"title"`
-		CreatedAt       string `json:"created_at"`
-		UpdatedAt       string `json:"updated_at"`
-		MilestoneID     int    `json:"milestone_id"`
-		State           string `json:"state"`
-		MergeStatus     string `json:"merge_status"`
-		TargetProjectID int    `json:"target_project_id"`
-		IID             int    `json:"iid"`
-		Description     string `json:"description"`
-		Position        int    `json:"position"`
-		LockedAt        string `json:"locked_at"`
-		UpdatedByID     int    `json:"updated_by_id"`
-		MergeError      string `json:"merge_error"`
-		MergeParams     *MergeParams `json:"merge_params"`
-		MergeWhenPipelineSucceeds bool        `json:"merge_when_pipeline_succeeds"`
-		MergeUserID               int         `json:"merge_user_id"`
-		MergeCommitSHA            string      `json:"merge_commit_sha"`
-		DeletedAt                 string      `json:"deleted_at"`
-		InProgressMergeCommitSHA  string      `json:"in_progress_merge_commit_sha"`
-		LockVersion               int         `json:"lock_version"`
-		ApprovalsBeforeMerge      string      `json:"approvals_before_merge"`
-		RebaseCommitSHA           string      `json:"rebase_commit_sha"`
-		TimeEstimate              int         `json:"time_estimate"`
-		Squash                    bool        `json:"squash"`
-		LastEditedAt              string      `json:"last_edited_at"`
-		LastEditedByID            int         `json:"last_edited_by_id"`
-		Source                    *Repository `json:"source"`
-		Target                    *Repository `json:"target"`
+		ID                        int          `json:"id"`
+		TargetBranch              string       `json:"target_branch"`
+		SourceBranch              string       `json:"source_branch"`
+		SourceProjectID           int          `json:"source_project_id"`
+		AuthorID                  int          `json:"author_id"`
+		AssigneeID                int          `json:"assignee_id"`
+		Title                     string       `json:"title"`
+		CreatedAt                 string       `json:"created_at"`
+		UpdatedAt                 string       `json:"updated_at"`
+		MilestoneID               int          `json:"milestone_id"`
+		State                     string       `json:"state"`
+		MergeStatus               string       `json:"merge_status"`
+		TargetProjectID           int          `json:"target_project_id"`
+		IID                       int          `json:"iid"`
+		Description               string       `json:"description"`
+		Position                  int          `json:"position"`
+		LockedAt                  string       `json:"locked_at"`
+		UpdatedByID               int          `json:"updated_by_id"`
+		MergeError                string       `json:"merge_error"`
+		MergeParams               *MergeParams `json:"merge_params"`
+		MergeWhenPipelineSucceeds bool         `json:"merge_when_pipeline_succeeds"`
+		MergeUserID               int          `json:"merge_user_id"`
+		MergeCommitSHA            string       `json:"merge_commit_sha"`
+		DeletedAt                 string       `json:"deleted_at"`
+		InProgressMergeCommitSHA  string       `json:"in_progress_merge_commit_sha"`
+		LockVersion               int          `json:"lock_version"`
+		ApprovalsBeforeMerge      string       `json:"approvals_before_merge"`
+		RebaseCommitSHA           string       `json:"rebase_commit_sha"`
+		TimeEstimate              int          `json:"time_estimate"`
+		Squash                    bool         `json:"squash"`
+		LastEditedAt              string       `json:"last_edited_at"`
+		LastEditedByID            int          `json:"last_edited_by_id"`
+		Source                    *Repository  `json:"source"`
+		Target                    *Repository  `json:"target"`
 		LastCommit                struct {
 			ID        string     `json:"id"`
 			Message   string     `json:"message"`
@@ -713,6 +713,18 @@ type PipelineEvent struct {
 		FinishedAt string   `json:"finished_at"`
 		Duration   int      `json:"duration"`
 	} `json:"object_attributes"`
+	MergeRequest struct {
+		ID                 int    `json:"id"`
+		IID                int    `json:"iid"`
+		Title              string `json:"title"`
+		SourceBranch       string `json:"source_branch"`
+		SourceProjectID    int    `json:"source_project_id"`
+		TargetBranch       string `json:"target_branch"`
+		TargetProjectID    int    `json:"target_project_id"`
+		State              string `json:"state"`
+		MergeRequestStatus string `json:"merge_status"`
+		URL                string `json:"url"`
+	} `json:"merge_request"`
 	User struct {
 		Name      string `json:"name"`
 		Username  string `json:"username"`


Test patch:
diff --git a/event_types_test.go b/event_types_test.go
index 6409476..d261455 100644
--- a/event_types_test.go
+++ b/event_types_test.go
@@ -329,6 +329,18 @@ func TestPipelineEventUnmarshal(t *testing.T) {
         }
       ]
    },
+   "merge_request": {
+      "id": 1,
+      "iid": 1,
+      "title": "Test",
+      "source_branch": "test",
+      "source_project_id": 1,
+      "target_branch": "master",
+      "target_project_id": 1,
+      "state": "opened",
+      "merge_status": "can_be_merged",
+      "url": "http://192.168.64.1:3005/gitlab-org/gitlab-test/merge_requests/1"
+   },
    "user":{
       "name": "Administrator",
       "username": "root",
@@ -507,6 +519,10 @@ func TestPipelineEventUnmarshal(t *testing.T) {
 	if name := event.Commit.Author.Name; name != "User" {
 		t.Errorf("Commit Username is %s, want %s", name, "User")
 	}
+
+	if mergeRequestID := event.MergeRequest.ID; mergeRequestID != 1 {
+		t.Errorf("Merge Request ID is %d, want %d", mergeRequestID, 1)
+	}
 }
 
 func TestBuildEventUnmarshal(t *testing.T) {