@@ -76,19 +76,7 @@ public function getIssueLabels($issueNumber, Repository $repository): array
7676
7777 public function addIssueLabel ($ issueNumber , string $ label , Repository $ repository )
7878 {
79- $ key = $ this ->getCacheKey ($ issueNumber , $ repository );
80-
81- if (isset ($ this ->labelCache [$ key ][$ label ])) {
82- return ;
83- }
84-
85- $ this ->logger ->debug ('Adding label "{label}" for {repo}#{issue} ' , ['label ' => $ label , 'repo ' => $ repository ->getFullName (), 'issue ' => $ issueNumber ]);
86- $ this ->labelsApi ->add ($ repository ->getVendor (), $ repository ->getName (), $ issueNumber , $ label );
87-
88- // Update cache if already loaded
89- if (isset ($ this ->labelCache [$ key ])) {
90- $ this ->labelCache [$ key ][$ label ] = true ;
91- }
79+ $ this ->addIssueLabels ($ issueNumber , [$ label ], $ repository );
9280 }
9381
9482 public function removeIssueLabel ($ issueNumber , string $ label , Repository $ repository )
@@ -115,8 +103,24 @@ public function removeIssueLabel($issueNumber, string $label, Repository $reposi
115103
116104 public function addIssueLabels ($ issueNumber , array $ labels , Repository $ repository )
117105 {
106+ $ key = $ this ->getCacheKey ($ issueNumber , $ repository );
107+ $ labelsToAdd = [];
108+
118109 foreach ($ labels as $ label ) {
119- $ this ->addIssueLabel ($ issueNumber , $ label , $ repository );
110+ if (!isset ($ this ->labelCache [$ key ][$ label ])) {
111+ $ labelsToAdd [] = $ label ;
112+ }
113+ }
114+
115+ if ([] !== $ labelsToAdd ) {
116+ $ this ->labelsApi ->add ($ repository ->getVendor (), $ repository ->getName (), $ issueNumber , $ labelsToAdd );
117+ }
118+
119+ // Update cache if already loaded
120+ foreach ($ labels as $ label ) {
121+ if (isset ($ this ->labelCache [$ key ])) {
122+ $ this ->labelCache [$ key ][$ label ] = true ;
123+ }
120124 }
121125 }
122126
0 commit comments