|
24 | 24 |
|
25 | 25 | package org.kohsuke.github; |
26 | 26 |
|
| 27 | +import static org.kohsuke.github.Previews.SQUIRREL_GIRL; |
| 28 | + |
27 | 29 | import com.infradna.tool.bridge_method_injector.WithBridgeMethods; |
28 | 30 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
29 | | - |
30 | 31 | import java.io.IOException; |
31 | 32 | import java.net.URL; |
| 33 | +import java.util.ArrayList; |
32 | 34 | import java.util.Arrays; |
33 | 35 | import java.util.Collection; |
34 | 36 | import java.util.Collections; |
35 | 37 | import java.util.Date; |
| 38 | +import java.util.HashSet; |
36 | 39 | import java.util.List; |
37 | 40 | import java.util.Locale; |
38 | | - |
39 | | -import static org.kohsuke.github.Previews.*; |
| 41 | +import java.util.Set; |
40 | 42 |
|
41 | 43 | /** |
42 | 44 | * Represents an issue on GitHub. |
@@ -216,6 +218,67 @@ public void setLabels(String... labels) throws IOException { |
216 | 218 | editIssue("labels",labels); |
217 | 219 | } |
218 | 220 |
|
| 221 | + /** |
| 222 | + * Adds labels to the issue. |
| 223 | + * |
| 224 | + * @param names Names of the label |
| 225 | + */ |
| 226 | + public void addLabels(String... names) throws IOException { |
| 227 | + _addLabels(Arrays.asList(names)); |
| 228 | + } |
| 229 | + |
| 230 | + public void addLabels(GHLabel... labels) throws IOException { |
| 231 | + addLabels(Arrays.asList(labels)); |
| 232 | + } |
| 233 | + |
| 234 | + public void addLabels(Collection<GHLabel> labels) throws IOException { |
| 235 | + _addLabels(GHLabel.toNames(labels)); |
| 236 | + } |
| 237 | + |
| 238 | + private void _addLabels(Collection<String> names) throws IOException { |
| 239 | + List<String> newLabels = new ArrayList<String>(); |
| 240 | + |
| 241 | + for (GHLabel label : getLabels()) { |
| 242 | + newLabels.add(label.getName()); |
| 243 | + } |
| 244 | + for (String name : names) { |
| 245 | + if (!newLabels.contains(name)) { |
| 246 | + newLabels.add(name); |
| 247 | + } |
| 248 | + } |
| 249 | + setLabels(newLabels.toArray(new String[0])); |
| 250 | + } |
| 251 | + |
| 252 | + /** |
| 253 | + * Remove a given label by name from this issue. |
| 254 | + */ |
| 255 | + public void removeLabels(String... names) throws IOException { |
| 256 | + _removeLabels(Arrays.asList(names)); |
| 257 | + } |
| 258 | + |
| 259 | + /** |
| 260 | + * @see #removeLabels(String...) |
| 261 | + */ |
| 262 | + public void removeLabels(GHLabel... labels) throws IOException { |
| 263 | + removeLabels(Arrays.asList(labels)); |
| 264 | + } |
| 265 | + |
| 266 | + public void removeLabels(Collection<GHLabel> labels) throws IOException { |
| 267 | + _removeLabels(GHLabel.toNames(labels)); |
| 268 | + } |
| 269 | + |
| 270 | + private void _removeLabels(Collection<String> names) throws IOException { |
| 271 | + List<String> newLabels = new ArrayList<String>(); |
| 272 | + |
| 273 | + for (GHLabel l : getLabels()) { |
| 274 | + if (!names.contains(l.getName())) { |
| 275 | + newLabels.add(l.getName()); |
| 276 | + } |
| 277 | + } |
| 278 | + |
| 279 | + setLabels(newLabels.toArray(new String[0])); |
| 280 | + } |
| 281 | + |
219 | 282 | /** |
220 | 283 | * Obtains all the comments associated with this issue. |
221 | 284 | * |
|
0 commit comments