nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: xanzy/go-gitlab
Pull request #1938 (2024-05-11 15:36:31)

GitLab 17.0: Fix an issue where Settings errors when ContainerRegistry is not enabled
In the 17.0-nightly build, the ContainerRegistryImportCreatedBefore attribute now returns "" when the container registry isn't enabled. This causes a parsing error because an empty string isn't parseable as a date in Go. As a result, `GetSettings` fails on every instance without a container registry enabled.

This PR implements custom parsing logic for the `Settings` struct that discards that value if it's set to an empty string to ensure that the Settings can continue to parse properly.

You can see this being detected in the Terraform Provider Nightly tests here: https://gitlab.com/gitlab-org/terraform-provider-gitlab/-/jobs/6827815421#L1850



Patch:
diff --git a/settings.go b/settings.go
index ac90566..4265e47 100644
--- a/settings.go
+++ b/settings.go
@@ -17,6 +17,7 @@
 package gitlab
 
 import (
+	"encoding/json"
 	"net/http"
 	"time"
 )
@@ -392,6 +393,31 @@ type Settings struct {
 	UserEmailLookupLimit int `json:"user_email_lookup_limit"`
 }
 
+// Settings requires a custom unmarshaller in order to properly unmarshal
+// `container_registry_import_created_before` which is either a time.Time or
+// an empty string if no value is set.
+func (s *Settings) UnmarshalJSON(data []byte) error {
+	type Alias Settings
+
+	raw := make(map[string]interface{})
+	err := json.Unmarshal(data, &raw)
+	if err != nil {
+		return err
+	}
+
+	// If empty string, remove the value to leave it nil in the response.
+	if v, ok := raw["container_registry_import_created_before"]; ok && v == "" {
+		delete(raw, "container_registry_import_created_before")
+
+		data, err = json.Marshal(raw)
+		if err != nil {
+			return err
+		}
+	}
+
+	return json.Unmarshal(data, (*Alias)(s))
+}
+
 func (s Settings) String() string {
 	return Stringify(s)
 }


Test patch:
diff --git a/settings_test.go b/settings_test.go
index a4ad6ce..6676741 100644
--- a/settings_test.go
+++ b/settings_test.go
@@ -63,3 +63,22 @@ func TestUpdateSettings(t *testing.T) {
 		t.Errorf("Settings.UpdateSettings returned %+v, want %+v", settings, want)
 	}
 }
+
+func TestSettingsWithEmptyContainerRegistry(t *testing.T) {
+	mux, client := setup(t)
+
+	mux.HandleFunc("/api/v4/application/settings", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, http.MethodGet)
+		fmt.Fprint(w, `{"id":1, "container_registry_import_created_before": ""}`)
+	})
+
+	settings, _, err := client.Settings.GetSettings()
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	want := &Settings{ID: 1, ContainerRegistryImportCreatedBefore: nil}
+	if !reflect.DeepEqual(settings, want) {
+		t.Errorf("Settings.UpdateSettings returned %+v, want %+v", settings, want)
+	}
+}
Repository: xanzy/go-gitlab
Pull request #1947 (2024-05-25 16:29:13)

Add ProjectID to snippets struct
Fixes https://github.com/xanzy/go-gitlab/issues/1946


Patch:
diff --git a/snippets.go b/snippets.go
index 7c7c808..3cb4827 100644
--- a/snippets.go
+++ b/snippets.go
@@ -50,6 +50,7 @@ type Snippet struct {
 	} `json:"author"`
 	UpdatedAt *time.Time `json:"updated_at"`
 	CreatedAt *time.Time `json:"created_at"`
+	ProjectID int        `json:"project_id"`
 	WebURL    string     `json:"web_url"`
 	RawURL    string     `json:"raw_url"`
 	Files     []struct {


Test patch:
diff --git a/project_snippets_test.go b/project_snippets_test.go
index ae6e3e9..6416ab7 100644
--- a/project_snippets_test.go
+++ b/project_snippets_test.go
@@ -55,8 +55,9 @@ func TestProjectSnippetsService_ListSnippets(t *testing.T) {
 			Name:     "Venkatesh Thalluri",
 			State:    "active",
 		},
-		WebURL: "http://example.com/example/example/snippets/1",
-		RawURL: "http://example.com/example/example/snippets/1/raw",
+		ProjectID: 1,
+		WebURL:    "http://example.com/example/example/snippets/1",
+		RawURL:    "http://example.com/example/example/snippets/1/raw",
 	}}
 
 	ss, resp, err := client.ProjectSnippets.ListSnippets(1, nil, nil)
@@ -124,8 +125,9 @@ func TestProjectSnippetsService_GetSnippet(t *testing.T) {
 			Name:     "Venkatesh Thalluri",
 			State:    "active",
 		},
-		WebURL: "http://example.com/example/example/snippets/1",
-		RawURL: "http://example.com/example/example/snippets/1/raw",
+		ProjectID: 1,
+		WebURL:    "http://example.com/example/example/snippets/1",
+		RawURL:    "http://example.com/example/example/snippets/1/raw",
 	}
 
 	s, resp, err := client.ProjectSnippets.GetSnippet(1, 1, nil, nil)
@@ -199,8 +201,9 @@ func TestProjectSnippetsService_CreateSnippet(t *testing.T) {
 			Name:     "Venkatesh Thalluri",
 			State:    "active",
 		},
-		WebURL: "http://example.com/example/example/snippets/1",
-		RawURL: "http://example.com/example/example/snippets/1/raw",
+		ProjectID: 1,
+		WebURL:    "http://example.com/example/example/snippets/1",
+		RawURL:    "http://example.com/example/example/snippets/1/raw",
 		Files: []struct {
 			Path   string `json:"path"`
 			RawURL string `json:"raw_url"`
@@ -277,8 +280,9 @@ func TestProjectSnippetsService_UpdateSnippet(t *testing.T) {
 			Name:     "Venkatesh Thalluri",
 			State:    "active",
 		},
-		WebURL: "http://example.com/example/example/snippets/1",
-		RawURL: "http://example.com/example/example/snippets/1/raw",
+		ProjectID: 1,
+		WebURL:    "http://example.com/example/example/snippets/1",
+		RawURL:    "http://example.com/example/example/snippets/1/raw",
 	}
 
 	s, resp, err := client.ProjectSnippets.UpdateSnippet(1, 1, nil, nil, nil)