nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: prometheus/alertmanager
Pull request #4195 (2025-01-06 13:59:24)

opsgenie : trim space for api key file
The goal is to trim the spaces on the API key file for Opsgenie as it is already done for most other integrations (Slack, Discord, PagerDuty, etc.)

grobinson-grafana: LGTM. Could you please write a unit test for this too?
zoov-xavier: Hello, @grobinson-grafana  thanks for the review. I added some tests. Let me know if any updates are needed.
zoov-xavier: Hello, @grobinson-grafana 
I rebased the PR maybe you could merge it ? 
Thanks !
grobinson-grafana: > Hello, @grobinson-grafana I rebased the PR maybe you could merge it ? Thanks !

I don't merge permissions I'm afraid :(

Patch:
diff --git a/notify/opsgenie/api_key_file b/notify/opsgenie/api_key_file
new file mode 100644
index 00000000..90d2bb3b
--- /dev/null
+++ b/notify/opsgenie/api_key_file
@@ -0,0 +1,2 @@
+my_secret_api_key
+
diff --git a/notify/opsgenie/opsgenie.go b/notify/opsgenie/opsgenie.go
index 75549846..54c0e245 100644
--- a/notify/opsgenie/opsgenie.go
+++ b/notify/opsgenie/opsgenie.go
@@ -282,6 +282,7 @@ func (n *Notifier) createRequests(ctx context.Context, as ...*types.Alert) ([]*h
 			return nil, false, fmt.Errorf("read key_file error: %w", err)
 		}
 		apiKey = tmpl(string(content))
+		apiKey = strings.TrimSpace(string(apiKey))
 	}
 
 	if err != nil {


Test patch:
diff --git a/notify/opsgenie/opsgenie_test.go b/notify/opsgenie/opsgenie_test.go
index 9db635d1..c6d70047 100644
--- a/notify/opsgenie/opsgenie_test.go
+++ b/notify/opsgenie/opsgenie_test.go
@@ -321,6 +321,25 @@ func TestOpsGenieWithUpdate(t *testing.T) {
 `, body2)
 }
 
+func TestOpsGenieApiKeyFile(t *testing.T) {
+	u, err := url.Parse("https://test-opsgenie-url")
+	require.NoError(t, err)
+	tmpl := test.CreateTmpl(t)
+	ctx := context.Background()
+	ctx = notify.WithGroupKey(ctx, "1")
+	opsGenieConfigWithUpdate := config.OpsGenieConfig{
+		APIKeyFile: `./api_key_file`,
+		APIURL:     &config.URL{URL: u},
+		HTTPConfig: &commoncfg.HTTPClientConfig{},
+	}
+	notifierWithUpdate, err := New(&opsGenieConfigWithUpdate, tmpl, promslog.NewNopLogger())
+
+	require.NoError(t, err)
+	requests, _, err := notifierWithUpdate.createRequests(ctx)
+	require.NoError(t, err)
+	require.Equal(t, "GenieKey my_secret_api_key", requests[0].Header.Get("Authorization"))
+}
+
 func readBody(t *testing.T, r *http.Request) string {
 	t.Helper()
 	body, err := io.ReadAll(r.Body)
Repository: prometheus/alertmanager
Pull request #4366 (2025-04-24 01:54:58)

chore: fix typo in route config validation error message
This PR fixes a typo in the route config validation error message.


Patch:
diff --git a/config/config.go b/config/config.go
index 6f54c523..82885b23 100644
--- a/config/config.go
+++ b/config/config.go
@@ -924,7 +924,7 @@ func (r *Route) UnmarshalYAML(unmarshal func(interface{}) error) error {
 	}
 
 	if len(r.GroupBy) > 0 && r.GroupByAll {
-		return errors.New("cannot have wildcard group_by (`...`) and other other labels at the same time")
+		return errors.New("cannot have wildcard group_by (`...`) and other labels at the same time")
 	}
 
 	groupBy := map[model.LabelName]struct{}{}


Test patch:
diff --git a/config/config_test.go b/config/config_test.go
index a9b77f17..a609b9f5 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -300,7 +300,7 @@ receivers:
 `
 	_, err := Load(in)
 
-	expected := "cannot have wildcard group_by (`...`) and other other labels at the same time"
+	expected := "cannot have wildcard group_by (`...`) and other labels at the same time"
 
 	if err == nil {
 		t.Fatalf("no error returned, expected:\n%q", expected)