nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: PagerDuty/go-pagerduty
Pull request #253 (2020-12-02 09:13:26)

business_service: clean b.ID before calling UPDATE
PUT `/business_services/{id}` doesn't accept `ID` in the body:
https://developer.pagerduty.com/api-reference/reference/REST/openapiv3.json/paths/~1business_services~1%7Bid%7D/put

However, specifying it for the `go-pagerduty` to work is mandatory.
Thus, it is impossible to use this method ATM without this fix. Let's
clear `b.ID` before calling `PUT` and store it in a separate variable.

Testing: my code calling this method works again with these changes.
Otherwise, the following error is spotted:
```
Failed call API endpoint. HTTP response code: 400. Error: \u0026{400 Invalid input [The field id is invalid.]}
```

I have added a small test case to the suite. LMK if this looks good.


Patch:
diff --git a/business_service.go b/business_service.go
index bdf8f65..1541729 100644
--- a/business_service.go
+++ b/business_service.go
@@ -106,8 +106,10 @@ func (c *Client) DeleteBusinessService(ID string) error {
 // UpdateBusinessService updates a business_service.
 func (c *Client) UpdateBusinessService(b *BusinessService) (*BusinessService, *http.Response, error) {
 	v := make(map[string]*BusinessService)
+	id := b.ID
+	b.ID = ""
 	v["business_service"] = b
-	resp, err := c.put("/business_services/"+b.ID, v, nil)
+	resp, err := c.put("/business_services/"+id, v, nil)
 	return getBusinessServiceFromResponse(c, resp, err)
 }
 


Test patch:
diff --git a/business_service_test.go b/business_service_test.go
index c8c5227..420785c 100644
--- a/business_service_test.go
+++ b/business_service_test.go
@@ -1,6 +1,8 @@
 package pagerduty
 
 import (
+	"encoding/json"
+	"io/ioutil"
 	"net/http"
 	"testing"
 )
@@ -95,6 +97,18 @@ func TestBusinessService_Update(t *testing.T) {
 
 	mux.HandleFunc("/business_services/1", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "PUT")
+		reqText, err := ioutil.ReadAll(r.Body)
+		if err != nil {
+			t.Fatal(err)
+		}
+		v := make(map[string]*BusinessService)
+		if err := json.Unmarshal(reqText, &v); err != nil {
+			t.Fatal(err)
+		}
+		if v["business_service"].ID != "" {
+			t.Fatalf("got ID in the body when we were not supposed to")
+		}
+
 		w.Write([]byte(`{"business_service": {"id": "1", "name":"foo"}}`))
 	})
Repository: PagerDuty/go-pagerduty
Pull request #329 (2021-05-10 16:52:04)

Fix query params on tags
At the moment, this method is missing the `?` which results in a 404 when providing query parameters.


Patch:
diff --git a/tag.go b/tag.go
index 011ab1f..a044872 100644
--- a/tag.go
+++ b/tag.go
@@ -358,7 +358,7 @@ func getTagList(ctx context.Context, c *Client, entityType, entityID string, o L
 	}
 
 	// Make call to get all pages associated with the base endpoint.
-	if err := c.pagedGet(ctx, path+queryParms.Encode(), responseHandler); err != nil {
+	if err := c.pagedGet(ctx, path+"?"+queryParms.Encode(), responseHandler); err != nil {
 		return nil, err
 	}
 


Test patch:
diff --git a/tag_test.go b/tag_test.go
index 08b7f64..ea11c3d 100644
--- a/tag_test.go
+++ b/tag_test.go
@@ -12,6 +12,7 @@ func TestTag_List(t *testing.T) {
 
 	mux.HandleFunc("/tags/", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
+		testEqual(t, r.URL.Query()["query"], []string{"MyTag"})
 		_, _ = w.Write([]byte(`{"tags": [{"id": "1","label":"MyTag"}]}`))
 	})
 
@@ -19,6 +20,7 @@ func TestTag_List(t *testing.T) {
 	client := &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient}
 	opts := ListTagOptions{
 		APIListObject: listObj,
+		Query:         "MyTag",
 	}
 	res, err := client.ListTags(opts)
 	if err != nil {
Repository: PagerDuty/go-pagerduty
Pull request #365 (2021-09-23 14:49:21)

Add json field incidents_responders to Incident struct
Add json:"incidents_responders,omitempty" to Incident struct in order to get
"incident": {"incidents_responders": []} from func GetIncident(ctx context.Context, client *pagerduty.Client, id string) (*pagerduty.Incident, error)


Patch:
diff --git a/incident.go b/incident.go
index 78b4043..05ba87f 100644
--- a/incident.go
+++ b/incident.go
@@ -89,6 +89,7 @@ type Incident struct {
 	Body                 IncidentBody         `json:"body,omitempty"`
 	IsMergeable          bool                 `json:"is_mergeable,omitempty"`
 	ConferenceBridge     *ConferenceBridge    `json:"conference_bridge,omitempty"`
+	IncidentResponders   []IncidentResponders `json:"incidents_responders,omitempty"`
 }
 
 // ListIncidentsResponse is the response structure when calling the ListIncident API endpoint.


Test patch:
diff --git a/incident_test.go b/incident_test.go
index 7529445..8c699da 100644
--- a/incident_test.go
+++ b/incident_test.go
@@ -237,7 +237,7 @@ func TestIncident_Get(t *testing.T) {
 
 	mux.HandleFunc("/incidents/1", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
-		_, _ = w.Write([]byte(`{"incident": {"id": "1"}}`))
+		_, _ = w.Write([]byte(`{"incident": {"id": "1", "incidents_responders": [{"incident": {"id": "1"}}]}}`))
 	})
 
 	client := defaultTestClient(server.URL, "foo")
@@ -245,7 +245,7 @@ func TestIncident_Get(t *testing.T) {
 	id := "1"
 	res, err := client.GetIncident(id)
 
-	want := &Incident{Id: "1"}
+	want := &Incident{Id: "1", IncidentResponders: []IncidentResponders{{Incident: APIObject{ID: "1"}}}}
 
 	if err != nil {
 		t.Fatal(err)
Repository: PagerDuty/go-pagerduty
Pull request #372 (2021-10-13 15:54:16)

Add title to ManageIncidentOptions
Looking at PagerDuty API doc it seems that the `title` attribute is missing from `ManageIncidentOptions`
https://developer.pagerduty.com/api-reference/b3A6Mjc0ODEzOQ-manage-incidents


Patch:
diff --git a/incident.go b/incident.go
index ed416a2..9aea857 100644
--- a/incident.go
+++ b/incident.go
@@ -169,6 +169,7 @@ type ManageIncidentsOptions struct {
 	ID               string        `json:"id"`
 	Type             string        `json:"type"`
 	Status           string        `json:"status,omitempty"`
+	Title            string        `json:"title,omitempty"`
 	Priority         *APIReference `json:"priority,omitempty"`
 	Assignments      []Assignee    `json:"assignments,omitempty"`
 	EscalationPolicy *APIReference `json:"escalation_policy,omitempty"`


Test patch:
diff --git a/incident_test.go b/incident_test.go
index d1fed01..39db805 100644
--- a/incident_test.go
+++ b/incident_test.go
@@ -1,6 +1,8 @@
 package pagerduty
 
 import (
+	"encoding/json"
+	"io/ioutil"
 	"net/http"
 	"testing"
 )
@@ -155,6 +157,60 @@ func TestIncident_Manage_priority(t *testing.T) {
 	testEqual(t, want, res)
 }
 
+func TestIncident_Manage_title(t *testing.T) {
+	setup()
+	defer teardown()
+
+	mux.HandleFunc("/incidents", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "PUT")
+
+		// test if title is present and correct
+		body, err := ioutil.ReadAll(r.Body)
+		if err != nil {
+			t.Fatal(err)
+		}
+		var data map[string][]ManageIncidentsOptions
+		if err := json.Unmarshal(body, &data); err != nil {
+			t.Fatal(err)
+		}
+		if len(data["incidents"]) == 0 {
+			t.Fatalf("no incidents, expect 1")
+		}
+		if data["incidents"][0].Title != "bar" {
+			t.Fatalf("expected incidents[0].title to be \"bar\" got \"%s\"", data["incidents"][0].Title)
+		}
+		_, _ = w.Write([]byte(`{"incidents": [{"title": "bar", "id": "1"}]}`))
+	})
+	listObj := APIListObject{Limit: 0, Offset: 0, More: false, Total: 0}
+	client := defaultTestClient(server.URL, "foo")
+	from := "foo@bar.com"
+
+	input := []ManageIncidentsOptions{
+		{
+			ID:    "1",
+			Type:  "incident",
+			Title: "bar",
+		},
+	}
+
+	want := &ListIncidentsResponse{
+		APIListObject: listObj,
+		Incidents: []Incident{
+			{
+				APIObject: APIObject{
+					ID: "1",
+				},
+				Title: "bar",
+			},
+		},
+	}
+	res, err := client.ManageIncidents(from, input)
+	if err != nil {
+		t.Fatal(err)
+	}
+	testEqual(t, want, res)
+}
+
 func TestIncident_Manage_assignments(t *testing.T) {
 	setup()
 	defer teardown()
Repository: PagerDuty/go-pagerduty
Pull request #380 (2021-11-09 07:58:43)

Add missing required parameeter to ManageIncidentAlerts
When making a call to the REST API[1] endpoint to manage alerts for incidents,
an HTTP header ("From") indicating who made the request is required. As a
result, these methods may not have ever worked properly.

So while we're breaking the API, let's remove the deprecated non-context version
to have fewer breaking changes in v2.

Closes #338

[1] https://developer.pagerduty.com/api-reference/b3A6Mjc0ODE0NA-manage-alerts


Patch:
diff --git a/incident.go b/incident.go
index 4bf79c9..a01c464 100644
--- a/incident.go
+++ b/incident.go
@@ -632,15 +632,12 @@ func (c *Client) GetIncidentAlertWithContext(ctx context.Context, incidentID, al
 }
 
 // ManageIncidentAlerts allows you to manage the alerts of an incident.
-//
-// Deprecated: Use ManageIncidentAlertsWithContext instead.
-func (c *Client) ManageIncidentAlerts(incidentID string, alerts *IncidentAlertList) (*ListAlertsResponse, error) {
-	return c.ManageIncidentAlertsWithContext(context.Background(), incidentID, alerts)
-}
+func (c *Client) ManageIncidentAlerts(ctx context.Context, incidentID, from string, alerts *IncidentAlertList) (*ListAlertsResponse, error) {
+	h := map[string]string{
+		"From": from,
+	}
 
-// ManageIncidentAlertsWithContext allows you to manage the alerts of an incident.
-func (c *Client) ManageIncidentAlertsWithContext(ctx context.Context, incidentID string, alerts *IncidentAlertList) (*ListAlertsResponse, error) {
-	resp, err := c.put(ctx, "/incidents/"+incidentID+"/alerts/", alerts, nil)
+	resp, err := c.put(ctx, "/incidents/"+incidentID+"/alerts/", alerts, h)
 	if err != nil {
 		return nil, err
 	}


Test patch:
diff --git a/incident_test.go b/incident_test.go
index 24e7797..aba9f6f 100644
--- a/incident_test.go
+++ b/incident_test.go
@@ -1,6 +1,7 @@
 package pagerduty
 
 import (
+	"context"
 	"encoding/json"
 	"io/ioutil"
 	"net/http"
@@ -708,12 +709,17 @@ func TestIncident_GetAlert(t *testing.T) {
 	testEqual(t, want, res)
 }
 
-func TestIncident_ManageAlerts(t *testing.T) {
+func TestIncident_ManageIncidentAlerts(t *testing.T) {
 	setup()
 	defer teardown()
 
+	from := "pagerduty@example.com"
+
 	mux.HandleFunc("/incidents/1/alerts/", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "PUT")
+		if hdr := r.Header.Get("From"); hdr != "pagerduty@example.com" {
+			t.Errorf("From header = %q, want %q", hdr, from)
+		}
 		_, _ = w.Write([]byte(`{"alerts": [{"id": "1"}]}`))
 	})
 
@@ -730,7 +736,7 @@ func TestIncident_ManageAlerts(t *testing.T) {
 			},
 		},
 	}
-	res, err := client.ManageIncidentAlerts(incidentID, input)
+	res, err := client.ManageIncidentAlerts(context.Background(), incidentID, from, input)
 
 	want := &ListAlertsResponse{
 		Alerts: []IncidentAlert{
Repository: PagerDuty/go-pagerduty
Pull request #401 (2021-11-22 12:33:03)

Add support for escalation_policy.on_call_handoff_notifications field
Closes https://github.com/PagerDuty/go-pagerduty/issues/395

I added a test, just in case, but it basically checks JSON Unmarshal.

As CLI uses JSON files as input no changes on that side are needed.

Not sure if any docs need an update.


Patch:
diff --git a/escalation_policy.go b/escalation_policy.go
index 2f3febd..3222e4c 100644
--- a/escalation_policy.go
+++ b/escalation_policy.go
@@ -22,12 +22,13 @@ type EscalationRule struct {
 // EscalationPolicy is a collection of escalation rules.
 type EscalationPolicy struct {
 	APIObject
-	Name            string           `json:"name,omitempty"`
-	EscalationRules []EscalationRule `json:"escalation_rules,omitempty"`
-	Services        []APIObject      `json:"services,omitempty"`
-	NumLoops        uint             `json:"num_loops,omitempty"`
-	Teams           []APIReference   `json:"teams"`
-	Description     string           `json:"description,omitempty"`
+	Name                       string           `json:"name,omitempty"`
+	EscalationRules            []EscalationRule `json:"escalation_rules,omitempty"`
+	Services                   []APIObject      `json:"services,omitempty"`
+	NumLoops                   uint             `json:"num_loops,omitempty"`
+	Teams                      []APIReference   `json:"teams"`
+	Description                string           `json:"description,omitempty"`
+	OnCallHandoffNotifications string           `json:"on_call_handoff_notifications,omitempty"`
 }
 
 // ListEscalationPoliciesResponse is the data structure returned from calling the ListEscalationPolicies API endpoint.


Test patch:
diff --git a/escalation_policy_test.go b/escalation_policy_test.go
index 72bee1d..698cd7f 100644
--- a/escalation_policy_test.go
+++ b/escalation_policy_test.go
@@ -158,3 +158,28 @@ func TestEscalationPolicy_UpdateTeams(t *testing.T) {
 	}
 	testEqual(t, want, res)
 }
+
+func TestEscalationPolicy_GetOnCallHandoffNotifications(t *testing.T) {
+	setup()
+	defer teardown()
+
+	mux.HandleFunc("/escalation_policies/1", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		_, _ = w.Write([]byte(`{"escalation_policy": {"id": "1", "on_call_handoff_notifications": "if_has_services"}}`))
+	})
+	client := defaultTestClient(server.URL, "foo")
+	var opts *GetEscalationPolicyOptions
+	res, err := client.GetEscalationPolicy("1", opts)
+
+	want := &EscalationPolicy{
+		APIObject: APIObject{
+			ID: "1",
+		},
+		OnCallHandoffNotifications: "if_has_services",
+	}
+
+	if err != nil {
+		t.Fatal(err)
+	}
+	testEqual(t, want, res)
+}
Repository: PagerDuty/go-pagerduty
Pull request #416 (2022-01-18 03:01:36)

Find a way to gracefully avoid one breaking change in #405
In #405 I opted to rename one of the types to be more consistent, and in the
moment totally forgot about type aliases. A type alias allows you to rename a
type in a non-breaking way, by converting the old name to be an alias to the new
one.

This change does that, and effectively removes one breaking change from v1.5.0.

I also do the sane thing to unify the Priority type into one.

theckman: https://github.com/PagerDuty/go-pagerduty/pull/405#discussion_r756650209

Patch:
diff --git a/priorites.go b/priorites.go
index 845738c..78a75de 100644
--- a/priorites.go
+++ b/priorites.go
@@ -6,20 +6,25 @@ import (
 	"github.com/google/go-querystring/query"
 )
 
-// PriorityProperty is a single priorty object returned from the Priorities endpoint
-type PriorityProperty struct {
-	APIObject
-	Name        string `json:"name"`
-	Description string `json:"description"`
-}
+// PriorityProperty is the original type name and is retained as an alias for API
+// compatibility.
+//
+// Deprecated: Use type Priority instead; will be removed in V2
+type PriorityProperty = Priority
 
 // ListPrioritiesResponse repreents the API response from PagerDuty when listing
 // the configured priorities.
 type ListPrioritiesResponse struct {
 	APIListObject
-	Priorities []PriorityProperty `json:"priorities"`
+	Priorities []Priority `json:"priorities"`
 }
 
+// Priorities is the original type name and is retained as an alias for API
+// compatibility.
+//
+// Deprecated: Use type ListPrioritiesResponse instead; will be removed in V2
+type Priorities = ListPrioritiesResponse
+
 // ListPrioritiesOptions is the data structure used when calling the
 // ListPriorities API endpoint.
 type ListPrioritiesOptions struct {


Test patch:
diff --git a/priorities_test.go b/priorities_test.go
index 5ba0146..7be1d7c 100644
--- a/priorities_test.go
+++ b/priorities_test.go
@@ -23,7 +23,7 @@ func TestPriorities_List(t *testing.T) {
 
 	want := &ListPrioritiesResponse{
 		APIListObject: listObj,
-		Priorities: []PriorityProperty{
+		Priorities: []Priority{
 			{
 				APIObject: APIObject{
 					ID:      "1",
Repository: PagerDuty/go-pagerduty
Pull request #443 (2022-04-23 22:58:04)

Fix potential panic when debug request captures are enabled
This fixes a panic that would occur if we attempted to duplicate a request that
has a nil Body, which would be any `GET` request. This also adds a regression
test.


Patch:
diff --git a/client.go b/client.go
index 3ab9382..44a2206 100644
--- a/client.go
+++ b/client.go
@@ -499,17 +499,19 @@ func (c *Client) prepRequest(req *http.Request, authRequired bool, headers map[s
 }
 
 func dupeRequest(r *http.Request) (*http.Request, error) {
-	data, err := ioutil.ReadAll(r.Body)
-	if err != nil {
-		return nil, fmt.Errorf("failed to copy request body: %w", err)
-	}
+	dreq := r.Clone(r.Context())
 
-	_ = r.Body.Close()
+	if r.Body != nil {
+		data, err := ioutil.ReadAll(r.Body)
+		if err != nil {
+			return nil, fmt.Errorf("failed to copy request body: %w", err)
+		}
 
-	dreq := r.Clone(r.Context())
+		_ = r.Body.Close()
 
-	r.Body = ioutil.NopCloser(bytes.NewReader(data))
-	dreq.Body = ioutil.NopCloser(bytes.NewReader(data))
+		r.Body = ioutil.NopCloser(bytes.NewReader(data))
+		dreq.Body = ioutil.NopCloser(bytes.NewReader(data))
+	}
 
 	return dreq, nil
 }


Test patch:
diff --git a/client_test.go b/client_test.go
index 512d9ef..f2dced8 100644
--- a/client_test.go
+++ b/client_test.go
@@ -1,6 +1,7 @@
 package pagerduty
 
 import (
+	"bytes"
 	"context"
 	"encoding/json"
 	"fmt"
@@ -742,3 +743,44 @@ func TestNullAPIErrorObject_UnmarshalJSON(t *testing.T) {
 		})
 	}
 }
+
+func Test_dupeRequest(t *testing.T) {
+	reqA, _ := http.NewRequest(http.MethodGet, "http://localhost/api/v1/foo", strings.NewReader("some data\n"))
+	reqB, _ := http.NewRequest(http.MethodGet, "http://localhost/api/v1/foo", nil)
+
+	tests := []struct {
+		name string
+		req  *http.Request
+	}{
+		{
+			name: "ok",
+			req:  reqA,
+		},
+		{
+			name: "ok_nil_body",
+			req:  reqB,
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			gotr, err := dupeRequest(tt.req)
+			testErrCheck(t, "dupeRequest()", "", err)
+
+			var gotb, wantb []byte
+			if gotr.Body != nil {
+				gotb, err = ioutil.ReadAll(gotr.Body)
+				testErrCheck(t, "ioutil.ReadAll(gotr.Body)", "", err)
+			}
+
+			if tt.req.Body != nil {
+				wantb, err = ioutil.ReadAll(tt.req.Body)
+				testErrCheck(t, "ioutil.ReadAll(tt.req.Body)", "", err)
+			}
+
+			if !bytes.Equal(gotb, wantb) {
+				t.Fatalf("gotb = %q, want %q", gotb, wantb)
+			}
+		})
+	}
+}
Repository: PagerDuty/go-pagerduty
Pull request #444 (2022-04-23 23:00:52)

Backport fix for panic when debug request captures are enabled
This fixes a panic that would occur if we attempted to duplicate a request that
has a nil Body, which would be any `GET` request. This also adds a regression
test.


Patch:
diff --git a/client.go b/client.go
index bdc2970..3ee6ee9 100644
--- a/client.go
+++ b/client.go
@@ -497,17 +497,19 @@ func (c *Client) prepRequest(req *http.Request, authRequired bool, headers map[s
 }
 
 func dupeRequest(r *http.Request) (*http.Request, error) {
-	data, err := ioutil.ReadAll(r.Body)
-	if err != nil {
-		return nil, fmt.Errorf("failed to copy request body: %w", err)
-	}
+	dreq := r.Clone(r.Context())
 
-	_ = r.Body.Close()
+	if r.Body != nil {
+		data, err := ioutil.ReadAll(r.Body)
+		if err != nil {
+			return nil, fmt.Errorf("failed to copy request body: %w", err)
+		}
 
-	dreq := r.Clone(r.Context())
+		_ = r.Body.Close()
 
-	r.Body = ioutil.NopCloser(bytes.NewReader(data))
-	dreq.Body = ioutil.NopCloser(bytes.NewReader(data))
+		r.Body = ioutil.NopCloser(bytes.NewReader(data))
+		dreq.Body = ioutil.NopCloser(bytes.NewReader(data))
+	}
 
 	return dreq, nil
 }


Test patch:
diff --git a/client_test.go b/client_test.go
index 512d9ef..f2dced8 100644
--- a/client_test.go
+++ b/client_test.go
@@ -1,6 +1,7 @@
 package pagerduty
 
 import (
+	"bytes"
 	"context"
 	"encoding/json"
 	"fmt"
@@ -742,3 +743,44 @@ func TestNullAPIErrorObject_UnmarshalJSON(t *testing.T) {
 		})
 	}
 }
+
+func Test_dupeRequest(t *testing.T) {
+	reqA, _ := http.NewRequest(http.MethodGet, "http://localhost/api/v1/foo", strings.NewReader("some data\n"))
+	reqB, _ := http.NewRequest(http.MethodGet, "http://localhost/api/v1/foo", nil)
+
+	tests := []struct {
+		name string
+		req  *http.Request
+	}{
+		{
+			name: "ok",
+			req:  reqA,
+		},
+		{
+			name: "ok_nil_body",
+			req:  reqB,
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			gotr, err := dupeRequest(tt.req)
+			testErrCheck(t, "dupeRequest()", "", err)
+
+			var gotb, wantb []byte
+			if gotr.Body != nil {
+				gotb, err = ioutil.ReadAll(gotr.Body)
+				testErrCheck(t, "ioutil.ReadAll(gotr.Body)", "", err)
+			}
+
+			if tt.req.Body != nil {
+				wantb, err = ioutil.ReadAll(tt.req.Body)
+				testErrCheck(t, "ioutil.ReadAll(tt.req.Body)", "", err)
+			}
+
+			if !bytes.Equal(gotb, wantb) {
+				t.Fatalf("gotb = %q, want %q", gotb, wantb)
+			}
+		})
+	}
+}