nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: hetznercloud/cli
Pull request #961 (2025-01-21 12:22:40)

fix: ignore firewall rule description when looking for a rule to delete
We now ignore firewall rule description when searching a rule to delete in the existing rules.

This allows the users to delete a rule without having to pass the description of the rule.


Patch:
diff --git a/internal/cmd/firewall/delete_rule.go b/internal/cmd/firewall/delete_rule.go
index 3b3d160..29d0b9a 100644
--- a/internal/cmd/firewall/delete_rule.go
+++ b/internal/cmd/firewall/delete_rule.go
@@ -2,7 +2,6 @@ package firewall
 
 import (
 	"fmt"
-	"reflect"
 
 	"github.com/spf13/cobra"
 
@@ -56,7 +55,7 @@ var DeleteRuleCmd = base.Cmd{
 
 		var rules = make([]hcloud.FirewallRule, 0)
 		for _, existingRule := range firewall.Rules {
-			if !reflect.DeepEqual(existingRule, *rule) {
+			if !EqualFirewallRule(existingRule, *rule) {
 				rules = append(rules, existingRule)
 			}
 		}
diff --git a/internal/cmd/firewall/validation.go b/internal/cmd/firewall/validation.go
index 6f5be2d..4ca8b49 100644
--- a/internal/cmd/firewall/validation.go
+++ b/internal/cmd/firewall/validation.go
@@ -3,6 +3,9 @@ package firewall
 import (
 	"fmt"
 	"net"
+	"reflect"
+
+	"github.com/hetznercloud/hcloud-go/v2/hcloud"
 )
 
 func ValidateFirewallIP(ip string) (*net.IPNet, error) {
@@ -16,3 +19,10 @@ func ValidateFirewallIP(ip string) (*net.IPNet, error) {
 
 	return n, nil
 }
+
+func EqualFirewallRule(a, b hcloud.FirewallRule) bool {
+	a.Description = nil
+	b.Description = nil
+
+	return reflect.DeepEqual(a, b)
+}


Test patch:
diff --git a/internal/cmd/firewall/validation_test.go b/internal/cmd/firewall/validation_test.go
index 1e56695..502b864 100644
--- a/internal/cmd/firewall/validation_test.go
+++ b/internal/cmd/firewall/validation_test.go
@@ -7,6 +7,7 @@ import (
 	"github.com/stretchr/testify/require"
 
 	"github.com/hetznercloud/cli/internal/cmd/firewall"
+	"github.com/hetznercloud/hcloud-go/v2/hcloud"
 )
 
 func TestValidateFirewallIP(t *testing.T) {
@@ -65,3 +66,12 @@ func TestValidateFirewallIP(t *testing.T) {
 		})
 	}
 }
+
+func TestEqualFirewallRule(t *testing.T) {
+	t.Run("success", func(t *testing.T) {
+		assert.True(t, firewall.EqualFirewallRule(
+			hcloud.FirewallRule{Description: hcloud.Ptr("a")},
+			hcloud.FirewallRule{Description: hcloud.Ptr("b")},
+		))
+	})
+}