Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/main/java/org/kohsuke/github/GHLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -22,6 +23,11 @@
*/
public class GHLabel extends GitHubInteractiveObject {

private long id;
private String nodeId;
@JsonProperty("default")
private boolean default_;

@Nonnull
private String url, name, color;

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

/**
* Gets id.
*
* @return the id
*/
public long getId() {
return id;
}

/**
* Gets node id.
*
* @return the node id.
*/
public String getNodeId() {
return nodeId;
}

/**
* Gets url.
*
Expand Down Expand Up @@ -82,6 +106,15 @@ public String getDescription() {
return description;
}

/**
* If the label is one of the default labels created by GitHub automatically.
*
* @return true if the label is a default one
*/
public boolean isDefault() {
return default_;
}

/**
* Sets color.
*
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/org/kohsuke/github/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,9 @@ public void testRepoLabel() throws IOException {
GHLabel e = r.getLabel("enhancement");
assertEquals("enhancement", e.getName());
assertNotNull(e.getUrl());
assertEquals(177339106, e.getId());
assertEquals("MDU6TGFiZWwxNzczMzkxMDY=", e.getNodeId());
assertTrue(e.isDefault());
assertTrue(Pattern.matches("[0-9a-fA-F]{6}", e.getColor()));

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

assertFalse(t2.isDefault());

assertEquals(t.getId(), t2.getId());
assertEquals(t.getNodeId(), t2.getNodeId());
assertEquals(t.getName(), t2.getName());
assertEquals(t.getColor(), "123456");
assertEquals(t.getColor(), t2.getColor());
assertEquals(t.getDescription(), "");
assertEquals(t.getDescription(), t2.getDescription());
assertEquals(t.getUrl(), t2.getUrl());
assertEquals(t.isDefault(), t2.isDefault());

// update works on multiple changes in one call
t3 = t.update().color("000000").description("It is dark!").done();
Expand Down
15 changes: 13 additions & 2 deletions src/test/java/org/kohsuke/github/GHPullRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
import java.util.Collections;
import java.util.List;

import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

/**
* @author Kohsuke Kawaguchi
Expand Down Expand Up @@ -418,7 +425,11 @@ public void setLabels() throws Exception {

Collection<GHLabel> labels = getRepository().getPullRequest(p.getNumber()).getLabels();
assertEquals(1, labels.size());
assertEquals(label, labels.iterator().next().getName());
GHLabel savedLabel = labels.iterator().next();
assertEquals(label, savedLabel.getName());
assertNotNull(savedLabel.getId());
assertNotNull(savedLabel.getNodeId());
assertFalse(savedLabel.isDefault());
}

@Test
Expand Down