nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: grafana/k6-operator
Pull request #173 (2022-12-08 09:59:35)

Revert removal of annotations from initializer
Details in https://github.com/grafana/k6-operator/issues/172


Patch:
diff --git a/pkg/resources/jobs/initializer.go b/pkg/resources/jobs/initializer.go
index 370d508..865c54a 100644
--- a/pkg/resources/jobs/initializer.go
+++ b/pkg/resources/jobs/initializer.go
@@ -20,6 +20,7 @@ func NewInitializerJob(k6 *v1alpha1.K6, argLine string) (*batchv1.Job, error) {
 
 	var (
 		image                        = "ghcr.io/grafana/operator:latest-runner"
+		annotations                  = make(map[string]string)
 		labels                       = newLabels(k6.Name)
 		serviceAccountName           = "default"
 		automountServiceAccountToken = true
@@ -30,6 +31,10 @@ func NewInitializerJob(k6 *v1alpha1.K6, argLine string) (*batchv1.Job, error) {
 		image = k6.Spec.Runner.Image
 	}
 
+	if k6.Spec.Runner.Metadata.Annotations != nil {
+		annotations = k6.Spec.Runner.Metadata.Annotations
+	}
+
 	if k6.Spec.Runner.Metadata.Labels != nil {
 		for k, v := range k6.Spec.Runner.Metadata.Labels { // Order not specified
 			if _, ok := labels[k]; !ok {
@@ -61,14 +66,16 @@ func NewInitializerJob(k6 *v1alpha1.K6, argLine string) (*batchv1.Job, error) {
 
 	return &batchv1.Job{
 		ObjectMeta: metav1.ObjectMeta{
-			Name:      fmt.Sprintf("%s-initializer", k6.Name),
-			Namespace: k6.Namespace,
-			Labels:    labels,
+			Name:        fmt.Sprintf("%s-initializer", k6.Name),
+			Namespace:   k6.Namespace,
+			Labels:      labels,
+			Annotations: annotations,
 		},
 		Spec: batchv1.JobSpec{
 			Template: corev1.PodTemplateSpec{
 				ObjectMeta: metav1.ObjectMeta{
-					Labels: labels,
+					Labels:      labels,
+					Annotations: annotations,
 				},
 				Spec: corev1.PodSpec{
 					AutomountServiceAccountToken: &automountServiceAccountToken,


Test patch:
diff --git a/pkg/resources/jobs/initializer_test.go b/pkg/resources/jobs/initializer_test.go
index 970c25f..36bfa35 100644
--- a/pkg/resources/jobs/initializer_test.go
+++ b/pkg/resources/jobs/initializer_test.go
@@ -29,6 +29,9 @@ func TestNewInitializerJob(t *testing.T) {
 				"k6_cr":  "test",
 				"label1": "awesome",
 			},
+			Annotations: map[string]string{
+				"awesomeAnnotation": "dope",
+			},
 		},
 		Spec: batchv1.JobSpec{
 			Template: corev1.PodTemplateSpec{
@@ -38,6 +41,9 @@ func TestNewInitializerJob(t *testing.T) {
 						"k6_cr":  "test",
 						"label1": "awesome",
 					},
+					Annotations: map[string]string{
+						"awesomeAnnotation": "dope",
+					},
 				},
 				Spec: corev1.PodSpec{
 					AutomountServiceAccountToken: &automountServiceAccountToken,
Repository: argoproj-labs/applicationset
Pull request #235 (2021-05-15 17:31:20)

fix: handle conversion to string in git generator
Use `fmt.Sprintf` instead of type assertion for converting the incoming parameter to string.

Fixes: #192 

Signed-off-by: Chetan Banavikalmutt <chetanrns1997@gmail.com>


Patch:
diff --git a/pkg/generators/git.go b/pkg/generators/git.go
index 753f2be..32d5cb9 100644
--- a/pkg/generators/git.go
+++ b/pkg/generators/git.go
@@ -165,7 +165,7 @@ func (g *GitGenerator) generateParamsFromGitFile(appSetGenerator *argoprojiov1al
 		}
 		params := map[string]string{}
 		for k, v := range flat {
-			params[k] = v.(string)
+			params[k] = fmt.Sprintf("%v", v)
 		}
 		res = append(res, params)
 	}


Test patch:
diff --git a/pkg/generators/git_test.go b/pkg/generators/git_test.go
index b9fba2b..0a6b31a 100644
--- a/pkg/generators/git_test.go
+++ b/pkg/generators/git_test.go
@@ -216,7 +216,8 @@ func TestGitGenerateParamsFromFiles(t *testing.T) {
        "key2_2": {
            "key2_2_1": "val2_2_1"
        }
-   }
+   },
+   "key3": 123
 }`),
 				"cluster-config/staging/config.json": []byte(`{
    "cluster": {
@@ -236,6 +237,7 @@ func TestGitGenerateParamsFromFiles(t *testing.T) {
 					"key1":                 "val1",
 					"key2.key2_1":          "val2_1",
 					"key2.key2_2.key2_2_1": "val2_2_1",
+					"key3":                 "123",
 				},
 				{
 					"cluster.owner":   "foo.bar@example.com",
Repository: argoproj-labs/applicationset
Pull request #237 (2021-05-22 05:51:55)

fix: sanitize cluster name param by replacing unsupported character
Sanitize the cluster name in accordance with the below rules
1. contain no more than 253 characters
2. contain only lowercase alphanumeric characters, '-' or '.'
3. start and end with an alphanumeric character

Closes: #166 

Signed-off-by: Chetan Banavikalmutt <chetanrns1997@gmail.com>


Patch:
diff --git a/pkg/generators/cluster.go b/pkg/generators/cluster.go
index 1e9f9ad..334e450 100644
--- a/pkg/generators/cluster.go
+++ b/pkg/generators/cluster.go
@@ -3,6 +3,8 @@ package generators
 import (
 	"context"
 	"fmt"
+	"regexp"
+	"strings"
 	"time"
 
 	"github.com/argoproj/argo-cd/util/settings"
@@ -116,7 +118,7 @@ func (g *ClusterGenerator) GenerateParams(
 	// For each matching cluster secret (non-local clusters only)
 	for _, cluster := range secretsFound {
 		params := map[string]string{}
-		params["name"] = string(cluster.Data["name"])
+		params["name"] = sanitizeName(string(cluster.Data["name"]))
 		params["server"] = string(cluster.Data["server"])
 		for key, value := range cluster.ObjectMeta.Annotations {
 			params[fmt.Sprintf("metadata.annotations.%s", key)] = value
@@ -161,3 +163,20 @@ func (g *ClusterGenerator) getSecretsByClusterName(appSetGenerator *argoprojiov1
 	return res, nil
 
 }
+
+// santize the name in accordance with the below rules
+// 1. contain no more than 253 characters
+// 2. contain only lowercase alphanumeric characters, '-' or '.'
+// 3. start and end with an alphanumeric character
+func sanitizeName(name string) string {
+	invalidDNSNameChars := regexp.MustCompile("[^-a-z0-9.]")
+	maxDNSNameLength := 253
+
+	name = strings.ToLower(name)
+	name = invalidDNSNameChars.ReplaceAllString(name, "-")
+	if len(name) > maxDNSNameLength {
+		name = name[:maxDNSNameLength]
+	}
+
+	return strings.Trim(name, "-.")
+}


Test patch:
diff --git a/pkg/generators/cluster_test.go b/pkg/generators/cluster_test.go
index 6bec3f8..ca441d3 100644
--- a/pkg/generators/cluster_test.go
+++ b/pkg/generators/cluster_test.go
@@ -241,3 +241,13 @@ func TestGenerateParams(t *testing.T) {
 		})
 	}
 }
+
+func TestSanitizeClusterName(t *testing.T) {
+	t.Run("valid DNS-1123 subdomain name", func(t *testing.T) {
+		assert.Equal(t, "cluster-name", sanitizeName("cluster-name"))
+	})
+	t.Run("invalid DNS-1123 subdomain name", func(t *testing.T) {
+		invalidName := "-.--CLUSTER/name  -./.-"
+		assert.Equal(t, "cluster-name", sanitizeName(invalidName))
+	})
+}
Repository: xanzy/go-gitlab
Pull request #2051 (2024-10-29 18:08:06)

API pipeline update metadata
Implements for endpoint https://docs.gitlab.com/ee/api/pipelines.html#update-pipeline-metadata

Issue https://github.com/xanzy/go-gitlab/issues/2026


Patch:
diff --git a/pipelines.go b/pipelines.go
index 3f24484..33e97a2 100644
--- a/pipelines.go
+++ b/pipelines.go
@@ -406,3 +406,37 @@ func (s *PipelinesService) DeletePipeline(pid interface{}, pipeline int, options
 
 	return s.client.Do(req, nil)
 }
+
+// UpdatePipelineMetadataOptions represents the available UpdatePipelineMetadata() options.
+//
+// GitLab API docs:
+// https://docs.gitlab.com/ee/api/pipelines.html#update-pipeline-metadata
+type UpdatePipelineMetadataOptions struct {
+	Name *string `url:"name,omitempty" json:"name,omitempty"`
+}
+
+// UpdatePipelineMetadata You can update the metadata of a pipeline. The metadata
+// contains the name of the pipeline.
+//
+// GitLab API docs:
+// https://docs.gitlab.com/ee/api/pipelines.html#update-pipeline-metadata
+func (s *PipelinesService) UpdatePipelineMetadata(pid interface{}, pipeline int, opt *UpdatePipelineMetadataOptions, options ...RequestOptionFunc) (*Pipeline, *Response, error) {
+	project, err := parseID(pid)
+	if err != nil {
+		return nil, nil, err
+	}
+	u := fmt.Sprintf("projects/%s/pipelines/%d/metadata", PathEscape(project), pipeline)
+
+	req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	p := new(Pipeline)
+	resp, err := s.client.Do(req, p)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return p, resp, nil
+}


Test patch:
diff --git a/pipelines_test.go b/pipelines_test.go
index 870f2ea..88fb831 100644
--- a/pipelines_test.go
+++ b/pipelines_test.go
@@ -271,3 +271,23 @@ func TestDeletePipeline(t *testing.T) {
 		t.Errorf("Pipelines.DeletePipeline returned error: %v", err)
 	}
 }
+
+func TestUpdateMetadata(t *testing.T) {
+	mux, client := setup(t)
+
+	mux.HandleFunc("/api/v4/projects/1/pipelines/234/metadata", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, http.MethodPut)
+		fmt.Fprint(w, `{"id":1, "status":"running"}`)
+	})
+
+	opt := &UpdatePipelineMetadataOptions{Name: Ptr("new pipeline title")}
+	pipeline, _, err := client.Pipelines.UpdatePipelineMetadata("1", 234, opt)
+	if err != nil {
+		t.Errorf("Pipelines.UpdatePipelineMetadata returned error: %v", err)
+	}
+
+	want := &Pipeline{ID: 1, Status: "running"}
+	if !reflect.DeepEqual(want, pipeline) {
+		t.Errorf("Pipelines.UpdatePipelineMetadata returned %+v, want %+v", pipeline, want)
+	}
+}
Repository: xanzy/go-gitlab
Pull request #2053 (2024-11-02 18:50:49)

Add support for updating a project's GitLab Pages settings
Adds support for the Update Pages settings for a project endpoint: https://docs.gitlab.com/ee/api/pages.html#update-pages-settings-for-a-project


Patch:
diff --git a/pages.go b/pages.go
index 81be8ba..7b0f503 100644
--- a/pages.go
+++ b/pages.go
@@ -90,3 +90,38 @@ func (s *PagesService) GetPages(gid interface{}, options ...RequestOptionFunc) (
 
 	return p, resp, nil
 }
+
+// UpdatePages represents the available UpdatePages() options.
+//
+// GitLab API docs:
+// https://docs.gitlab.com/ee/api/pages.html#update-pages-settings-for-a-project
+type UpdatePagesOptions struct {
+	PagesUniqueDomainEnabled *bool `url:"pages_unique_domain_enabled,omitempty" json:"pages_unique_domain_enabled,omitempty"`
+	PagesHTTPSOnly           *bool `url:"pages_https_only,omitempty" json:"pages_https_only,omitempty"`
+}
+
+// UpdatePages updates Pages settings for a project. The user must have
+// administrator privileges.
+//
+// GitLab API Docs:
+// https://docs.gitlab.com/ee/api/pages.html#update-pages-settings-for-a-project
+func (s *PagesService) UpdatePages(pid interface{}, opt UpdatePagesOptions, options ...RequestOptionFunc) (*Pages, *Response, error) {
+	project, err := parseID(pid)
+	if err != nil {
+		return nil, nil, err
+	}
+	u := fmt.Sprintf("projects/%s/pages", PathEscape(project))
+
+	req, err := s.client.NewRequest(http.MethodPatch, u, opt, options)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	p := new(Pages)
+	resp, err := s.client.Do(req, p)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return p, resp, nil
+}


Test patch:
diff --git a/pages_test.go b/pages_test.go
index 0168253..4101caf 100644
--- a/pages_test.go
+++ b/pages_test.go
@@ -78,3 +78,47 @@ func TestGetPages(t *testing.T) {
 	require.NotNil(t, resp)
 	require.Equal(t, want, p)
 }
+
+func TestUpdatePages(t *testing.T) {
+	mux, client := setup(t)
+	mux.HandleFunc("/api/v4/projects/2/pages", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, http.MethodPatch)
+		fmt.Fprint(w, `
+		  {
+			"url": "https://ssl.domain.example",
+			"deployments": [
+			  {
+				"created_at": "2021-04-27T21:27:38.584Z",
+				"url": "https://ssl.domain.example/",
+				"path_prefix": "",
+				"root_directory": null
+			  }
+			],
+			"is_unique_domain_enabled": true,
+			"force_https": false
+		  }
+		`)
+	})
+
+	want := &Pages{
+		URL:                   "https://ssl.domain.example",
+		IsUniqueDomainEnabled: true,
+		ForceHTTPS:            false,
+		Deployments: []*PagesDeployment{
+			{
+				CreatedAt:     time.Date(2021, time.April, 27, 21, 27, 38, 584000000, time.UTC),
+				URL:           "https://ssl.domain.example/",
+				PathPrefix:    "",
+				RootDirectory: "",
+			},
+		},
+	}
+
+	p, resp, err := client.Pages.UpdatePages(2, UpdatePagesOptions{
+		PagesUniqueDomainEnabled: Ptr(true),
+		PagesHTTPSOnly:           Ptr(false),
+	})
+	require.NoError(t, err)
+	require.NotNil(t, resp)
+	require.Equal(t, want, p)
+}
Repository: xanzy/go-gitlab
Pull request #2055 (2024-11-02 20:53:07)

Add Web URL to response when comparing in a repository
Fixes https://github.com/xanzy/go-gitlab/issues/2031


Patch:
diff --git a/repositories.go b/repositories.go
index dde8761..3c59f9a 100644
--- a/repositories.go
+++ b/repositories.go
@@ -209,6 +209,7 @@ type Compare struct {
 	Diffs          []*Diff   `json:"diffs"`
 	CompareTimeout bool      `json:"compare_timeout"`
 	CompareSameRef bool      `json:"compare_same_ref"`
+	WebURL         string    `json:"web_url"`
 }
 
 func (c Compare) String() string {


Test patch:
diff --git a/repositories_test.go b/repositories_test.go
index 4610bf3..9130def 100644
--- a/repositories_test.go
+++ b/repositories_test.go
@@ -281,6 +281,7 @@ func TestRepositoriesService_Compare(t *testing.T) {
 		}},
 		CompareTimeout: false,
 		CompareSameRef: false,
+		WebURL:         "https://gitlab.example.com/thedude/gitlab-foss/-/compare/ae73cb07c9eeaf35924a10f713b364d32b2dd34f...0b4bc9a49b562e85de7cc9e834518ea6828729b9",
 	}
 
 	c, resp, err := client.Repositories.Compare("12d65c8dd2b2676fa3ac47d955accc085a37a9c1", opt, nil)
Repository: xanzy/go-gitlab
Pull request #1563 (2022-10-10 21:27:36)

CheckResponse errors include any non-JSON data
My GitLab is throwing errors where the body is not JSON, and using this library I'm finding that the error message coming back from `CheckResponse` wasn't very helpful, just `failed to parse unknown error format`.

This PR will include the original response body in the Go error, when that body cannot be parsed as JSON.

I hope you're amenable to this change.  Thanks for maintaining such a useful project!


Patch:
diff --git a/gitlab.go b/gitlab.go
index 8fb8869..c9055f8 100644
--- a/gitlab.go
+++ b/gitlab.go
@@ -892,7 +892,7 @@ func CheckResponse(r *http.Response) error {
 
 		var raw interface{}
 		if err := json.Unmarshal(data, &raw); err != nil {
-			errorResponse.Message = "failed to parse unknown error format"
+			errorResponse.Message = fmt.Sprintf("failed to parse unknown error format: %s", data)
 		} else {
 			errorResponse.Message = parseError(raw)
 		}


Test patch:
diff --git a/gitlab_test.go b/gitlab_test.go
index 860e7fb..496fd6a 100644
--- a/gitlab_test.go
+++ b/gitlab_test.go
@@ -172,6 +172,35 @@ func TestCheckResponse(t *testing.T) {
 	}
 }
 
+func TestCheckResponseOnUnknownErrorFormat(t *testing.T) {
+	c, err := NewClient("")
+	if err != nil {
+		t.Fatalf("Failed to create client: %v", err)
+	}
+
+	req, err := c.NewRequest(http.MethodGet, "test", nil, nil)
+	if err != nil {
+		t.Fatalf("Failed to create request: %v", err)
+	}
+
+	resp := &http.Response{
+		Request:    req.Request,
+		StatusCode: http.StatusBadRequest,
+		Body:       io.NopCloser(strings.NewReader("some error message but not JSON")),
+	}
+
+	errResp := CheckResponse(resp)
+	if errResp == nil {
+		t.Fatal("Expected error response.")
+	}
+
+	want := "GET https://gitlab.com/api/v4/test: 400 failed to parse unknown error format: some error message but not JSON"
+
+	if errResp.Error() != want {
+		t.Errorf("Expected error: %s, got %s", want, errResp.Error())
+	}
+}
+
 func TestRequestWithContext(t *testing.T) {
 	c, err := NewClient("")
 	if err != nil {
Repository: xanzy/go-gitlab
Pull request #1565 (2022-10-19 15:02:24)

 Add `ref` to deployment webhook 
Hey 👋,

`ref` seems to be undocumented in the [deployment webhook event docs](https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#deployment-events), but looking at the code, it's always present: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/data_builder/deployment.rb#L44. 

Just as another example, deploying from sth. else than a tag will contain sth. like `"ref":"refs/merge-requests/1/merge"`. I tested this with the GitLab SaaS version.

I also updated the docs URL for the job event since the TODO comment was from 2019 🙂


Patch:
diff --git a/event_webhook_types.go b/event_webhook_types.go
index cb94322..e596213 100644
--- a/event_webhook_types.go
+++ b/event_webhook_types.go
@@ -151,6 +151,7 @@ type DeploymentEvent struct {
 		SSHURL            string  `json:"ssh_url"`
 		HTTPURL           string  `json:"http_url"`
 	} `json:"project"`
+	Ref         string     `json:"ref"`
 	ShortSHA    string     `json:"short_sha"`
 	User        *EventUser `json:"user"`
 	UserURL     string     `json:"user_url"`
@@ -305,8 +306,7 @@ type IssueEvent struct {
 // JobEvent represents a job event.
 //
 // GitLab API docs:
-// TODO: link to docs instead of src once they are published.
-// https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitlab/data_builder/build.rb
+// https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#job-events
 type JobEvent struct {
 	ObjectKind         string     `json:"object_kind"`
 	Ref                string     `json:"ref"`


Test patch:
diff --git a/event_webhook_types_test.go b/event_webhook_types_test.go
index 7c2d67b..e01ff40 100644
--- a/event_webhook_types_test.go
+++ b/event_webhook_types_test.go
@@ -92,6 +92,10 @@ func TestDeploymentEventUnmarshal(t *testing.T) {
 	if event.CommitTitle != "Add new file" {
 		t.Errorf("CommitTitle is %s, want %s", event.CommitTitle, "Add new file")
 	}
+
+	if event.Ref != "1.0.0" {
+		t.Errorf("Ref is %s, want %s", event.Ref, "1.0.0")
+	}
 }
 
 func TestIssueCommentEventUnmarshal(t *testing.T) {
diff --git a/testdata/webhooks/deployment.json b/testdata/webhooks/deployment.json
index 3ab09fd..ce3c131 100644
--- a/testdata/webhooks/deployment.json
+++ b/testdata/webhooks/deployment.json
@@ -32,5 +32,6 @@
   },
   "user_url": "http://10.126.0.2:3000/root",
   "commit_url": "http://10.126.0.2:3000/root/test-deployment-webhooks/-/commit/279484c09fbe69ededfced8c1bb6e6d24616b468",
-  "commit_title": "Add new file"
+  "commit_title": "Add new file",
+  "ref": "1.0.0"
 }
Repository: xanzy/go-gitlab
Pull request #1621 (2023-01-10 11:07:53)

fix: Added missing mapping for ProjectID
The `RegistryRepository` also contains a `project_id` (see [here](https://docs.gitlab.com/ee/api/container_registry.html#within-a-group)) that wasn't mapped. 

Funnily enough, the tests had those JSON fields.


Patch:
diff --git a/container_registry.go b/container_registry.go
index 3bb565d..357efe4 100644
--- a/container_registry.go
+++ b/container_registry.go
@@ -37,6 +37,7 @@ type RegistryRepository struct {
 	ID                     int                      `json:"id"`
 	Name                   string                   `json:"name"`
 	Path                   string                   `json:"path"`
+	ProjectID              int                      `json:"project_id"`
 	Location               string                   `json:"location"`
 	CreatedAt              *time.Time               `json:"created_at"`
 	CleanupPolicyStartedAt *time.Time               `json:"cleanup_policy_started_at"`


Test patch:
diff --git a/container_registry_test.go b/container_registry_test.go
index c81da8c..5ef94c0 100644
--- a/container_registry_test.go
+++ b/container_registry_test.go
@@ -81,6 +81,7 @@ func TestListProjectRegistryRepositories(t *testing.T) {
 			ID:                     1,
 			Name:                   "",
 			Path:                   "group/project",
+			ProjectID:              9,
 			Location:               "gitlab.example.com:5000/group/project",
 			CreatedAt:              &createdAt1,
 			CleanupPolicyStartedAt: &cleanupPolicyStartedAt1,
@@ -89,6 +90,7 @@ func TestListProjectRegistryRepositories(t *testing.T) {
 			ID:                     2,
 			Name:                   "releases",
 			Path:                   "group/project/releases",
+			ProjectID:              9,
 			Location:               "gitlab.example.com:5000/group/project/releases",
 			CreatedAt:              &createdAt2,
 			CleanupPolicyStartedAt: &cleanupPolicyStartedAt2,
@@ -156,6 +158,7 @@ func TestListGroupRegistryRepositories(t *testing.T) {
 			ID:                     1,
 			Name:                   "",
 			Path:                   "group/project",
+			ProjectID:              9,
 			Location:               "gitlab.example.com:5000/group/project",
 			CreatedAt:              &createdAt1,
 			CleanupPolicyStartedAt: &cleanupPolicyStartedAt1,
@@ -164,6 +167,7 @@ func TestListGroupRegistryRepositories(t *testing.T) {
 			ID:                     2,
 			Name:                   "releases",
 			Path:                   "group/project/releases",
+			ProjectID:              9,
 			Location:               "gitlab.example.com:5000/group/project/releases",
 			CreatedAt:              &createdAt2,
 			CleanupPolicyStartedAt: &cleanupPolicyStartedAt2,
@@ -208,6 +212,7 @@ func TestGetSingleRegistryRepository(t *testing.T) {
 		ID:                     1,
 		Name:                   "",
 		Path:                   "group/project",
+		ProjectID:              9,
 		Location:               "gitlab.example.com:5000/group/project",
 		CreatedAt:              &createdAt,
 		CleanupPolicyStartedAt: &cleanupPolicyStartedAt,
Repository: xanzy/go-gitlab
Pull request #1635 (2023-01-23 17:05:43)

Add missing system hook event for user_failed_login
This PR adds the missing system hook event for `user_failed_login` as documented in the [GitLab Docs](https://docs.gitlab.com/ee/administration/system_hooks.html).

Interestingly enough the test data for the event was already there.


Patch:
diff --git a/event_parsing.go b/event_parsing.go
index bd668b0..4a83330 100644
--- a/event_parsing.go
+++ b/event_parsing.go
@@ -155,7 +155,8 @@ func ParseSystemhook(payload []byte) (event interface{}, err error) {
 	case
 		"user_create",
 		"user_destroy",
-		"user_rename":
+		"user_rename",
+		"user_failed_login":
 		event = &UserSystemEvent{}
 	case
 		"user_add_to_group",
diff --git a/event_systemhook_types.go b/event_systemhook_types.go
index 786f530..a653d15 100644
--- a/event_systemhook_types.go
+++ b/event_systemhook_types.go
@@ -90,6 +90,7 @@ type UserSystemEvent struct {
 	Username    string `json:"username"`
 	OldUsername string `json:"old_username,omitempty"`
 	Email       string `json:"email"`
+	State       string `json:"state,omitempty"`
 }
 
 // UserGroupSystemEvent represents a user group system event.


Test patch:
diff --git a/event_parsing_systemhook_test.go b/event_parsing_systemhook_test.go
index e61cfe2..12b5b43 100644
--- a/event_parsing_systemhook_test.go
+++ b/event_parsing_systemhook_test.go
@@ -140,6 +140,7 @@ func TestParseSystemhookUser(t *testing.T) {
 		{"user_create", loadFixture("testdata/systemhooks/user_create.json")},
 		{"user_destroy", loadFixture("testdata/systemhooks/user_destroy.json")},
 		{"user_rename", loadFixture("testdata/systemhooks/user_rename.json")},
+		{"user_failed_login", loadFixture("testdata/systemhooks/user_failed_login.json")},
 	}
 	for _, tc := range tests {
 		t.Run(tc.event, func(t *testing.T) {
Repository: xanzy/go-gitlab
Pull request #1662 (2023-03-03 21:16:40)

Expose Revoked and Expired field for Deploy Tokens


Patch:
diff --git a/deploy_tokens.go b/deploy_tokens.go
index 3519016..07c53cc 100644
--- a/deploy_tokens.go
+++ b/deploy_tokens.go
@@ -36,6 +36,8 @@ type DeployToken struct {
 	Name      string     `json:"name"`
 	Username  string     `json:"username"`
 	ExpiresAt *time.Time `json:"expires_at"`
+	Revoked   bool       `json:"revoked"`
+	Expired   bool       `json:"expired"`
 	Token     string     `json:"token,omitempty"`
 	Scopes    []string   `json:"scopes"`
 }


Test patch:
diff --git a/deploy_tokens_test.go b/deploy_tokens_test.go
index f67bc36..01b917b 100644
--- a/deploy_tokens_test.go
+++ b/deploy_tokens_test.go
@@ -36,6 +36,8 @@ func TestListAllDeployTokens(t *testing.T) {
 		"name": "MyToken",
 		"username": "gitlab+deploy-token-1",
 		"expires_at": "2020-02-14T00:00:00.000Z",
+		"revoked": true,
+		"expired": true,
 		"scopes": [
 			"read_repository",
 			"read_registry"
@@ -58,6 +60,8 @@ func TestListAllDeployTokens(t *testing.T) {
 			Name:      "MyToken",
 			Username:  "gitlab+deploy-token-1",
 			ExpiresAt: &wantExpiresAt,
+			Revoked:   true,
+			Expired:   true,
 			Scopes: []string{
 				"read_repository",
 				"read_registry",