@@ -76,19 +76,7 @@ public function getIssueLabels($issueNumber, Repository $repository): array
76
76
77
77
public function addIssueLabel ($ issueNumber , string $ label , Repository $ repository )
78
78
{
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 );
92
80
}
93
81
94
82
public function removeIssueLabel ($ issueNumber , string $ label , Repository $ repository )
@@ -115,8 +103,24 @@ public function removeIssueLabel($issueNumber, string $label, Repository $reposi
115
103
116
104
public function addIssueLabels ($ issueNumber , array $ labels , Repository $ repository )
117
105
{
106
+ $ key = $ this ->getCacheKey ($ issueNumber , $ repository );
107
+ $ labelsToAdd = [];
108
+
118
109
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
+ }
120
124
}
121
125
}
122
126
0 commit comments