@@ -12,7 +12,7 @@ import (
1212 "time"
1313
1414 "github.com/google/go-github/v63/github"
15- "github.com/multimediallc/codeowners-plus/pkg/functional"
15+ f "github.com/multimediallc/codeowners-plus/pkg/functional"
1616)
1717
1818func setupReviews () * GHClient {
@@ -424,6 +424,13 @@ func TestNilPRErr(t *testing.T) {
424424 return err
425425 },
426426 },
427+ {
428+ name : "IsInLabels" ,
429+ testFn : func () error {
430+ _ , err := gh .IsInLabels ([]string {"label" })
431+ return err
432+ },
433+ },
427434 }
428435 for _ , tc := range tt {
429436 t .Run (tc .name , func (t * testing.T ) {
@@ -1019,3 +1026,94 @@ func TestInitUserReviewerMap(t *testing.T) {
10191026 }
10201027 }
10211028}
1029+
1030+ func TestIsInLabels (t * testing.T ) {
1031+ tt := []struct {
1032+ name string
1033+ pr * github.PullRequest
1034+ labels []string
1035+ expected bool
1036+ expectError bool
1037+ failMessage string
1038+ }{
1039+ {
1040+ name : "has matching label" ,
1041+ pr : & github.PullRequest {
1042+ Labels : []* github.Label {
1043+ {Name : github .String ("high-priority" )},
1044+ },
1045+ },
1046+ labels : []string {"high-priority" },
1047+ expected : true ,
1048+ expectError : false ,
1049+ failMessage : "Should detect matching label" ,
1050+ },
1051+ {
1052+ name : "has multiple labels but no match" ,
1053+ pr : & github.PullRequest {
1054+ Labels : []* github.Label {
1055+ {Name : github .String ("bug" )},
1056+ {Name : github .String ("enhancement" )},
1057+ },
1058+ },
1059+ labels : []string {"high-priority" },
1060+ expected : false ,
1061+ expectError : false ,
1062+ failMessage : "Should not detect label when not present" ,
1063+ },
1064+ {
1065+ name : "empty labels list" ,
1066+ pr : & github.PullRequest {
1067+ Labels : []* github.Label {
1068+ {Name : github .String ("high-priority" )},
1069+ },
1070+ },
1071+ labels : []string {},
1072+ expected : false ,
1073+ expectError : false ,
1074+ failMessage : "Should return false for empty labels list" ,
1075+ },
1076+ {
1077+ name : "multiple target labels" ,
1078+ pr : & github.PullRequest {
1079+ Labels : []* github.Label {
1080+ {Name : github .String ("urgent" )},
1081+ },
1082+ },
1083+ labels : []string {"high-priority" , "urgent" },
1084+ expected : true ,
1085+ expectError : false ,
1086+ failMessage : "Should detect any of the target labels" ,
1087+ },
1088+ {
1089+ name : "nil PR" ,
1090+ pr : nil ,
1091+ labels : []string {"high-priority" },
1092+ expected : false ,
1093+ expectError : true ,
1094+ failMessage : "Should return error for nil PR" ,
1095+ },
1096+ }
1097+
1098+ for _ , tc := range tt {
1099+ t .Run (tc .name , func (t * testing.T ) {
1100+ client := & GHClient {pr : tc .pr }
1101+ hasLabel , err := client .IsInLabels (tc .labels )
1102+ if tc .expectError {
1103+ if err == nil {
1104+ t .Error ("Expected error but got none" )
1105+ }
1106+ if _ , ok := err .(* NoPRError ); ! ok {
1107+ t .Errorf ("Expected NoPRError, got %T" , err )
1108+ }
1109+ return
1110+ }
1111+ if err != nil {
1112+ t .Errorf ("Unexpected error: %v" , err )
1113+ }
1114+ if hasLabel != tc .expected {
1115+ t .Error (tc .failMessage )
1116+ }
1117+ })
1118+ }
1119+ }
0 commit comments