Search in sources :

Example 1 with Label

use of com.jcabi.github.Label in project jcabi-github by jcabi.

the class MkIssue method json.

@Override
public JsonObject json() throws IOException {
    final XML xml = this.storage.xml();
    final JsonObject obj = new JsonNode(xml.nodes(this.xpath()).get(0)).json();
    final JsonObjectBuilder json = Json.createObjectBuilder();
    for (final Map.Entry<String, JsonValue> val : obj.entrySet()) {
        json.add(val.getKey(), val.getValue());
    }
    final JsonArrayBuilder array = Json.createArrayBuilder();
    for (final Label label : this.labels().iterate()) {
        array.add(Json.createObjectBuilder().add("name", label.name()).build());
    }
    final JsonObjectBuilder res = json.add("labels", array).add(// @checkstyle MultipleStringLiteralsCheck (1 line)
    "assignee", Json.createObjectBuilder().add("login", obj.getString("assignee", "")).build());
    final JsonObjectBuilder pull = Json.createObjectBuilder();
    final String html = "html_url";
    if (xml.nodes(String.format(// @checkstyle LineLengthCheck (1 line)
    "/github/repos/repo[@coords='%s']/pulls/pull/number[text() = '%d']", this.coords, this.num)).isEmpty()) {
        pull.addNull(html);
    } else {
        pull.add(html, String.format("https://%s/pulls/%d", this.coords, this.num));
    }
    return res.add("pull_request", pull.build()).build();
}
Also used : XML(com.jcabi.xml.XML) JsonValue(javax.json.JsonValue) Label(com.jcabi.github.Label) JsonObject(javax.json.JsonObject) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) Map(java.util.Map)

Example 2 with Label

use of com.jcabi.github.Label in project jcabi-github by jcabi.

the class MkEventTest method canGetAbsentLabel.

/**
 * MkEvent can get absent label value from json object.
 * @throws Exception If some problem inside
 */
@Test
public void canGetAbsentLabel() throws Exception {
    final MkStorage storage = new MkStorage.InFile();
    final String user = "barbie";
    final Repo repo = new MkGithub(storage, user).repos().create(new Repos.RepoCreate("bar", false));
    final int num = ((MkIssueEvents) (repo.issueEvents())).create(Event.LABELED, 1, user, Optional.<String>absent()).number();
    MatcherAssert.assertThat(new Event.Smart(new MkEvent(storage, user, repo.coordinates(), num)).label(), Matchers.equalTo(Optional.<Label>absent()));
}
Also used : Repos(com.jcabi.github.Repos) Repo(com.jcabi.github.Repo) Label(com.jcabi.github.Label) Test(org.junit.Test)

Aggregations

Label (com.jcabi.github.Label)2 Repo (com.jcabi.github.Repo)1 Repos (com.jcabi.github.Repos)1 XML (com.jcabi.xml.XML)1 Map (java.util.Map)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonObject (javax.json.JsonObject)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 JsonValue (javax.json.JsonValue)1 Test (org.junit.Test)1