Search in sources :

Example 6 with XML

use of com.jcabi.xml.XML 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 7 with XML

use of com.jcabi.xml.XML in project jcabi-github by jcabi.

the class MkPull method json.

@Override
public JsonObject json() throws IOException {
    final XML xml = this.storage.xml().nodes(this.xpath()).get(0);
    final String branch = xml.xpath("base/text()").get(0);
    final String head = xml.xpath("head/text()").get(0);
    final String[] parts = head.split(MkPull.USER_BRANCH_SEP, 2);
    final List<String> patches = xml.xpath("patch/text()");
    final String patch;
    if (patches.isEmpty()) {
        patch = "";
    } else {
        patch = patches.get(0);
    }
    return Json.createObjectBuilder().add("number", Integer.parseInt(xml.xpath("number/text()").get(0))).add("user", Json.createObjectBuilder().add("login", xml.xpath("user/login/text()").get(0)).build()).add("patch", patch).add("head", Json.createObjectBuilder().add(MkPull.REF_PROP, parts[1]).add(MkPull.LABEL_PROP, head).build()).add("base", Json.createObjectBuilder().add(MkPull.REF_PROP, branch).add(MkPull.LABEL_PROP, String.format("%s:%s", this.coords.user(), branch)).build()).add("comments", this.storage.xml().nodes(this.comment()).size()).build();
}
Also used : XML(com.jcabi.xml.XML) ToString(lombok.ToString)

Example 8 with XML

use of com.jcabi.xml.XML in project jcabi-github by jcabi.

the class MkContents method iterate.

@Override
public Iterable<Content> iterate(final String pattern, final String ref) throws IOException {
    final Collection<XML> nodes = this.storage.xml().nodes(String.format("%s/content[@ref='%s']", this.xpath(), ref));
    final Collection<Content> result = new ArrayList<Content>(nodes.size());
    for (final XML node : nodes) {
        final String path = node.xpath("path/text()").get(0);
        if (path.startsWith(pattern)) {
            result.add(this.mkContent(ref, path));
        }
    }
    return result;
}
Also used : XML(com.jcabi.xml.XML) Content(com.jcabi.github.Content) ArrayList(java.util.ArrayList) ToString(lombok.ToString)

Example 9 with XML

use of com.jcabi.xml.XML in project jcabi-github by jcabi.

the class MkGist method fork.

@Override
public Gist fork() throws IOException {
    this.storage.lock();
    final String number;
    try {
        final XML xml = this.storage.xml();
        number = Integer.toString(1 + xml.xpath("/github/gists/gist/id/text()").size());
        final Directives dirs = new Directives().xpath("/github/gists").add("gist").add("id").set(number).up().add("files");
        final List<XML> files = xml.nodes(String.format("%s/files/file", this.xpath()));
        for (final XML file : files) {
            final String filename = file.xpath("filename/text()").get(0);
            // @checkstyle MultipleStringLiterals (3 lines)
            dirs.add("file").add("filename").set(filename).up().add("raw_content").set(this.read(filename)).up().up();
        }
        this.storage.apply(dirs);
    } finally {
        this.storage.unlock();
    }
    return new MkGist(this.storage, this.self, number);
}
Also used : XML(com.jcabi.xml.XML) Directives(org.xembly.Directives) ToString(lombok.ToString)

Aggregations

XML (com.jcabi.xml.XML)9 ToString (lombok.ToString)4 XMLDocument (com.jcabi.xml.XMLDocument)2 IOException (java.io.IOException)2 JsonObject (javax.json.JsonObject)2 Test (org.junit.Test)2 Content (com.jcabi.github.Content)1 Label (com.jcabi.github.Label)1 User (com.jcabi.github.User)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 JsonValue (javax.json.JsonValue)1 Directives (org.xembly.Directives)1 Xembler (org.xembly.Xembler)1