Repository: xanzy/go-gitlab
Pull request #1489 (2022-06-03 06:40:11)

Add support to the field failure_reason
Following GitLab API documentation we have:
[https://docs.gitlab.com/ee/api/jobs.html](https://docs.gitlab.com/ee/api/jobs.html)

It was added a field called `failure_reason` which returns the failure reason for a given job.

Signed-off-by: Daniela Bento <danibento@overdestiny.com>


Patch:
diff --git a/jobs.go b/jobs.go
index d50a43c..5fe3d3f 100644
--- a/jobs.go
+++ b/jobs.go
@@ -71,12 +71,13 @@ type Job struct {
 		IsShared    bool   `json:"is_shared"`
 		Name        string `json:"name"`
 	} `json:"runner"`
-	Stage   string   `json:"stage"`
-	Status  string   `json:"status"`
-	Tag     bool     `json:"tag"`
-	WebURL  string   `json:"web_url"`
-	Project *Project `json:"project"`
-	User    *User    `json:"user"`
+	Stage         string   `json:"stage"`
+	Status        string   `json:"status"`
+	FailureReason string   `json:"failure_reason"`
+	Tag           bool     `json:"tag"`
+	WebURL        string   `json:"web_url"`
+	Project       *Project `json:"project"`
+	User          *User    `json:"user"`
 }
 
 // Bridge represents a pipeline bridge.
diff --git a/projects.go b/projects.go
index c623c9e..d9c83d2 100644
--- a/projects.go
+++ b/projects.go
@@ -224,8 +224,8 @@ type ProjectNamespace struct {
 	Name      string `json:"name"`
 	Path      string `json:"path"`
 	Kind      string `json:"kind"`
-	ParentID  int    `json:"parent_id"`
 	FullPath  string `json:"full_path"`
+	ParentID  int    `json:"parent_id"`
 	AvatarURL string `json:"avatar_url"`
 	WebURL    string `json:"web_url"`
 }


Test patch:
diff --git a/jobs_test.go b/jobs_test.go
index 8eb816a..0abe9b0 100644
--- a/jobs_test.go
+++ b/jobs_test.go
@@ -77,6 +77,7 @@ func TestJobsService_ListProjectJobs(t *testing.T) {
     "ref": "master",
     "stage": "test",
     "status": "failed",
+	  "failure_reason": "script_failure",
     "tag": false,
     "web_url": "https://example.com/foo/bar/-/jobs/7"
   },
@@ -118,35 +119,37 @@ func TestJobsService_ListProjectJobs(t *testing.T) {
 		t.Errorf("Jobs.ListProjectJobs returned error: %v", err)
 	}
 
-	want := []*Job{{
-		Commit: &Commit{
-			ID:          "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
-			ShortID:     "0ff3ae19",
-			Title:       "Test the CI integration.",
-			AuthorName:  "Administrator",
-			AuthorEmail: "admin@example.com",
-		},
-		AllowFailure: false,
-		ID:           7,
-		Name:         "teaspoon",
-		TagList:      []string{"docker runner", "ubuntu18"},
-		Pipeline: struct {
-			ID     int    `json:"id"`
-			Ref    string `json:"ref"`
-			Sha    string `json:"sha"`
-			Status string `json:"status"`
-		}{
-			ID:     6,
-			Ref:    "master",
-			Sha:    "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
-			Status: "pending",
+	want := []*Job{
+		{
+			Commit: &Commit{
+				ID:          "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
+				ShortID:     "0ff3ae19",
+				Title:       "Test the CI integration.",
+				AuthorName:  "Administrator",
+				AuthorEmail: "admin@example.com",
+			},
+			AllowFailure: false,
+			ID:           7,
+			Name:         "teaspoon",
+			TagList:      []string{"docker runner", "ubuntu18"},
+			Pipeline: struct {
+				ID     int    `json:"id"`
+				Ref    string `json:"ref"`
+				Sha    string `json:"sha"`
+				Status string `json:"status"`
+			}{
+				ID:     6,
+				Ref:    "master",
+				Sha:    "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
+				Status: "pending",
+			},
+			Ref:           "master",
+			Stage:         "test",
+			Status:        "failed",
+			FailureReason: "script_failure",
+			Tag:           false,
+			WebURL:        "https://example.com/foo/bar/-/jobs/7",
 		},
-		Ref:    "master",
-		Stage:  "test",
-		Status: "failed",
-		Tag:    false,
-		WebURL: "https://example.com/foo/bar/-/jobs/7",
-	},
 		{
 			Commit: &Commit{
 				ID:          "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
@@ -177,7 +180,8 @@ func TestJobsService_ListProjectJobs(t *testing.T) {
 			Status: "failed",
 			Tag:    false,
 			WebURL: "https://example.com/foo/bar/-/jobs/6",
-		}}
+		},
+	}
 	assert.Equal(t, want, jobs)
 }