@@ -17,45 +17,51 @@ func TestLabels_UpdateWithRegex(t *testing.T) {
1717 proj := createProject (t , "temporary-update-labels-" , "Temporary repository to update labels into" )
1818 defer deleteProject (t , proj )
1919
20- addLabel (t , proj , "category#label" , "#000000" )
21- addLabel (t , proj , "misc#anotherlabel" , "#ff0000" )
20+ addLabel (t , proj , "category#label" , "#000000" , "First label" )
21+ addLabel (t , proj , "misc#anotherlabel" , "#ff0000" , "Second label" )
2222
2323 // update with regex
24- if err := GitLabClient .Labels .UpdateWithRegex (* proj .ID , & gogitlab.UpdateLabelOptions {
25- Name : "(.+)#(.+)" ,
26- NewName : "${1}/${2}" ,
24+ name := "(.+)#(.+)"
25+ newName := "${1}/${2}"
26+ if err := GitLabClient .Labels .UpdateWithRegex (proj .ID , & gogitlab.UpdateLabelOptions {
27+ Name : & name ,
28+ NewName : & newName ,
2729 }); err != nil {
2830 t .Fatal (err )
2931 }
3032
3133 labelsExist (t , proj , []* gogitlab.Label {
32- & gogitlab.Label {"category/label" , "" },
33- & gogitlab.Label {"misc/anotherlabel" , "" },
34+ & gogitlab.Label {"category/label" , "#000000" , "First label" , 0 , 0 , 0 },
35+ & gogitlab.Label {"misc/anotherlabel" , "#ff0000" , "Second label" , 0 , 0 , 0 },
3436 })
3537
3638 // update again without regex
37- if err := GitLabClient .Labels .UpdateWithRegex (* proj .ID , & gogitlab.UpdateLabelOptions {
38- Name : "category/label" ,
39- NewName : "category-label" ,
39+ name = "category/label"
40+ newName = "category-label"
41+ if err := GitLabClient .Labels .UpdateWithRegex (proj .ID , & gogitlab.UpdateLabelOptions {
42+ Name : & name ,
43+ NewName : & newName ,
4044 }); err != nil {
4145 t .Fatal (err )
4246 }
4347
4448 labelsExist (t , proj , []* gogitlab.Label {
45- & gogitlab.Label {"category-label" , "" },
46- & gogitlab.Label {"misc/anotherlabel" , "" },
49+ & gogitlab.Label {"category-label" , "#000000" , "First label" , 0 , 0 , 0 },
50+ & gogitlab.Label {"misc/anotherlabel" , "#ff0000" , "Second label" , 0 , 0 , 0 },
4751 })
4852
4953 // update color
50- if err := GitLabClient .Labels .UpdateWithRegex (* proj .ID , & gogitlab.UpdateLabelOptions {
51- Name : "^misc" ,
52- Color : "#ff7863" ,
54+ name = "^misc"
55+ col := "#ff7863"
56+ if err := GitLabClient .Labels .UpdateWithRegex (proj .ID , & gogitlab.UpdateLabelOptions {
57+ Name : & name ,
58+ Color : & col ,
5359 }); err != nil {
5460 t .Fatal (err )
5561 }
5662
5763 labelsExist (t , proj , []* gogitlab.Label {
58- & gogitlab.Label {"misc/anotherlabel" , "#ff7863" },
64+ & gogitlab.Label {"misc/anotherlabel" , "#ff7863" , "Second label" , 0 , 0 , 0 },
5965 })
6066}
6167
@@ -65,12 +71,12 @@ func TestLabels_DeleteWithRegex(t *testing.T) {
6571 proj := createProject (t , "temporary-delete-labels-from-" , "Temporary repository to delete labels from" )
6672 defer deleteProject (t , proj )
6773
68- addLabel (t , proj , "test-label" , "#000000" )
74+ addLabel (t , proj , "test-label" , "#000000" , "Test label description" )
6975
70- if err := GitLabClient .Labels .DeleteWithRegex (* proj .ID , "" ); err != nil {
76+ if err := GitLabClient .Labels .DeleteWithRegex (proj .ID , "" ); err != nil {
7177 t .Fatal (err )
7278 }
73- if labels := getLabels (t , * proj .ID ); len (labels ) > 0 {
79+ if labels := getLabels (t , proj .ID ); len (labels ) > 0 {
7480 t .Fatalf ("labels still exist after supposedly deleting them all: %v" , labels )
7581 }
7682}
@@ -81,17 +87,17 @@ func TestLabels_CopyGlobalLabelsTo(t *testing.T) {
8187 proj := createProject (t , "temporary-copy-globals-to-" , "Temporary repository to copy global labels to" )
8288 defer deleteProject (t , proj )
8389
84- globalLabels := getLabels (t , * proj .ID )
90+ globalLabels := getLabels (t , proj .ID )
8591
86- if err := GitLabClient .Labels .DeleteWithRegex (* proj .ID , "" ); err != nil {
92+ if err := GitLabClient .Labels .DeleteWithRegex (proj .ID , "" ); err != nil {
8793 t .Fatal (err )
8894 }
8995
90- if err := GitLabClient .Labels .CopyGlobalLabelsTo (* proj .ID ); err != nil {
96+ if err := GitLabClient .Labels .CopyGlobalLabelsTo (proj .ID ); err != nil {
9197 t .Fatal (err )
9298 }
9399
94- labels := getLabels (t , * proj .ID )
100+ labels := getLabels (t , proj .ID )
95101 if len (labels ) != len (globalLabels ) {
96102 t .Fatalf ("different number of labels\n globalLabels: %v\n repoLabels: %v" , globalLabels , labels )
97103 }
@@ -118,10 +124,11 @@ func getLabels(tb testing.TB, pid interface{}) []*gogitlab.Label {
118124 return labels
119125}
120126
121- func addLabel (tb testing.TB , proj * gogitlab.Project , name , color string ) * gogitlab.Label {
122- l , _ , err := GitLabClient .Labels .CreateLabel (* proj .ID , & gogitlab.CreateLabelOptions {
123- Name : name ,
124- Color : color ,
127+ func addLabel (tb testing.TB , proj * gogitlab.Project , name , color , description string ) * gogitlab.Label {
128+ l , _ , err := GitLabClient .Labels .CreateLabel (proj .ID , & gogitlab.CreateLabelOptions {
129+ Name : & name ,
130+ Color : & color ,
131+ Description : & description ,
125132 })
126133 if err != nil {
127134 // The failure happens at wherever we were called, not here
@@ -135,14 +142,26 @@ func addLabel(tb testing.TB, proj *gogitlab.Project, name, color string) *gogitl
135142}
136143
137144func labelsExist (tb testing.TB , proj * gogitlab.Project , expected []* gogitlab.Label ) {
138- labels := getLabels (tb , * proj .ID )
145+ labels := getLabels (tb , proj .ID )
139146 for _ , exp := range expected {
140147 found := false
141148 for _ , l := range labels {
142149 e := * exp
143150 if exp .Color == "" {
144151 e .Color = l .Color
145152 }
153+ if exp .Description == "" {
154+ e .Description = l .Description
155+ }
156+ if exp .OpenIssuesCount == 0 {
157+ e .OpenIssuesCount = l .OpenIssuesCount
158+ }
159+ if exp .ClosedIssuesCount == 0 {
160+ e .ClosedIssuesCount = l .ClosedIssuesCount
161+ }
162+ if exp .OpenMergeRequestsCount == 0 {
163+ e .OpenMergeRequestsCount = l .OpenMergeRequestsCount
164+ }
146165 if reflect .DeepEqual (& e , l ) {
147166 found = true
148167 break
0 commit comments