Repository: xanzy/go-gitlab
Pull request #1403 (2022-03-07 10:07:26)

Implement `priority` field in project label creation and update functions
Required for:

* https://github.com/gitlabhq/terraform-provider-gitlab/issues/69


Patch:
diff --git a/labels.go b/labels.go
index 66db474..4868bda 100644
--- a/labels.go
+++ b/labels.go
@@ -140,6 +140,7 @@ type CreateLabelOptions struct {
 	Name        *string `url:"name,omitempty" json:"name,omitempty"`
 	Color       *string `url:"color,omitempty" json:"color,omitempty"`
 	Description *string `url:"description,omitempty" json:"description,omitempty"`
+	Priority    *int    `url:"priority,omitempty" json:"priority,omitempty"`
 }
 
 // CreateLabel creates a new label for given repository with given name and
@@ -200,6 +201,7 @@ type UpdateLabelOptions struct {
 	NewName     *string `url:"new_name,omitempty" json:"new_name,omitempty"`
 	Color       *string `url:"color,omitempty" json:"color,omitempty"`
 	Description *string `url:"description,omitempty" json:"description,omitempty"`
+	Priority    *int    `url:"priority,omitempty" json:"priority,omitempty"`
 }
 
 // UpdateLabel updates an existing label with new name or now color. At least


Test patch:
diff --git a/labels_test.go b/labels_test.go
index eb262b3..66cdcb7 100644
--- a/labels_test.go
+++ b/labels_test.go
@@ -30,20 +30,21 @@ func TestCreateLabel(t *testing.T) {
 
 	mux.HandleFunc("/api/v4/projects/1/labels", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, http.MethodPost)
-		fmt.Fprint(w, `{"id":1, "name": "My Label", "color" : "#11FF22"}`)
+		fmt.Fprint(w, `{"id":1, "name": "My Label", "color" : "#11FF22", "priority": 2}`)
 	})
 
 	// Create new label
 	l := &CreateLabelOptions{
-		Name:  String("My Label"),
-		Color: String("#11FF22"),
+		Name:     String("My Label"),
+		Color:    String("#11FF22"),
+		Priority: Int(2),
 	}
 	label, _, err := client.Labels.CreateLabel("1", l)
 
 	if err != nil {
 		log.Fatal(err)
 	}
-	want := &Label{ID: 1, Name: "My Label", Color: "#11FF22"}
+	want := &Label{ID: 1, Name: "My Label", Color: "#11FF22", Priority: 2}
 	if !reflect.DeepEqual(want, label) {
 		t.Errorf("Labels.CreateLabel returned %+v, want %+v", label, want)
 	}
@@ -74,7 +75,7 @@ func TestUpdateLabel(t *testing.T) {
 
 	mux.HandleFunc("/api/v4/projects/1/labels", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, http.MethodPut)
-		fmt.Fprint(w, `{"id":1, "name": "New Label", "color" : "#11FF23" , "description":"This is updated label"}`)
+		fmt.Fprint(w, `{"id":1, "name": "New Label", "color" : "#11FF23" , "description":"This is updated label", "priority": 42}`)
 	})
 
 	// Update label
@@ -83,6 +84,7 @@ func TestUpdateLabel(t *testing.T) {
 		NewName:     String("New Label"),
 		Color:       String("#11FF23"),
 		Description: String("This is updated label"),
+		Priority:    Int(42),
 	}
 
 	label, resp, err := client.Labels.UpdateLabel("1", l)
@@ -94,7 +96,7 @@ func TestUpdateLabel(t *testing.T) {
 		log.Fatal(err)
 	}
 
-	want := &Label{ID: 1, Name: "New Label", Color: "#11FF23", Description: "This is updated label"}
+	want := &Label{ID: 1, Name: "New Label", Color: "#11FF23", Description: "This is updated label", Priority: 42}
 
 	if !reflect.DeepEqual(want, label) {
 		t.Errorf("Labels.UpdateLabel returned %+v, want %+v", label, want)