Skip to content

Commit 40937a5

Browse files
committed
Add the missing fields for GHLabel
Fixes hub4j#1059
1 parent 1f7f646 commit 40937a5

3 files changed

Lines changed: 54 additions & 2 deletions

File tree

src/main/java/org/kohsuke/github/GHLabel.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.JacksonInject;
44
import com.fasterxml.jackson.annotation.JsonCreator;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
56

67
import java.io.IOException;
78
import java.util.ArrayList;
@@ -22,6 +23,11 @@
2223
*/
2324
public class GHLabel extends GitHubInteractiveObject {
2425

26+
private long id;
27+
private String nodeId;
28+
@JsonProperty("default")
29+
private boolean default_;
30+
2531
@Nonnull
2632
private String url, name, color;
2733

@@ -42,6 +48,24 @@ GitHub getApiRoot() {
4248
return Objects.requireNonNull(root);
4349
}
4450

51+
/**
52+
* Gets id.
53+
*
54+
* @return the id
55+
*/
56+
public long getId() {
57+
return id;
58+
}
59+
60+
/**
61+
* Gets node id.
62+
*
63+
* @return the node id.
64+
*/
65+
public String getNodeId() {
66+
return nodeId;
67+
}
68+
4569
/**
4670
* Gets url.
4771
*
@@ -82,6 +106,15 @@ public String getDescription() {
82106
return description;
83107
}
84108

109+
/**
110+
* If the label is one of the default labels created by GitHub automatically.
111+
*
112+
* @return true if the label is a default one
113+
*/
114+
public boolean isDefault() {
115+
return default_;
116+
}
117+
85118
/**
86119
* Sets color.
87120
*

src/test/java/org/kohsuke/github/AppTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,9 @@ public void testRepoLabel() throws IOException {
965965
GHLabel e = r.getLabel("enhancement");
966966
assertEquals("enhancement", e.getName());
967967
assertNotNull(e.getUrl());
968+
assertEquals(177339106, e.getId());
969+
assertEquals("MDU6TGFiZWwxNzczMzkxMDY=", e.getNodeId());
970+
assertTrue(e.isDefault());
968971
assertTrue(Pattern.matches("[0-9a-fA-F]{6}", e.getColor()));
969972

970973
GHLabel t = null;
@@ -976,12 +979,17 @@ public void testRepoLabel() throws IOException {
976979
assertThat(t, not(sameInstance(t2)));
977980
assertThat(t, equalTo(t2));
978981

982+
assertFalse(t2.isDefault());
983+
984+
assertEquals(t.getId(), t2.getId());
985+
assertEquals(t.getNodeId(), t2.getNodeId());
979986
assertEquals(t.getName(), t2.getName());
980987
assertEquals(t.getColor(), "123456");
981988
assertEquals(t.getColor(), t2.getColor());
982989
assertEquals(t.getDescription(), "");
983990
assertEquals(t.getDescription(), t2.getDescription());
984991
assertEquals(t.getUrl(), t2.getUrl());
992+
assertEquals(t.isDefault(), t2.isDefault());
985993

986994
// update works on multiple changes in one call
987995
t3 = t.update().color("000000").description("It is dark!").done();

src/test/java/org/kohsuke/github/GHPullRequestTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
import java.util.Collections;
1010
import java.util.List;
1111

12-
import static org.hamcrest.Matchers.*;
12+
import static org.hamcrest.Matchers.containsInAnyOrder;
13+
import static org.hamcrest.Matchers.containsString;
14+
import static org.hamcrest.Matchers.equalTo;
15+
import static org.hamcrest.Matchers.hasProperty;
16+
import static org.hamcrest.Matchers.instanceOf;
17+
import static org.hamcrest.Matchers.is;
18+
import static org.hamcrest.Matchers.notNullValue;
19+
import static org.hamcrest.Matchers.nullValue;
1320

1421
/**
1522
* @author Kohsuke Kawaguchi
@@ -418,7 +425,11 @@ public void setLabels() throws Exception {
418425

419426
Collection<GHLabel> labels = getRepository().getPullRequest(p.getNumber()).getLabels();
420427
assertEquals(1, labels.size());
421-
assertEquals(label, labels.iterator().next().getName());
428+
GHLabel savedLabel = labels.iterator().next();
429+
assertEquals(label, savedLabel.getName());
430+
assertNotNull(savedLabel.getId());
431+
assertNotNull(savedLabel.getNodeId());
432+
assertFalse(savedLabel.isDefault());
422433
}
423434

424435
@Test

0 commit comments

Comments
 (0)