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();
}
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();
}
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;
}
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);
}
Aggregations