use of org.xembly.Directives in project wring by yegor256.
the class TkEvents method source.
/**
* Convert event to Xembly.
* @param event The event
* @return Xembly
* @throws IOException If fails
*/
private static XeSource source(final Event event) throws IOException {
final Iterable<Directive> dirs = event.asXembly();
final String title = new XePrint(dirs).text("{/event/title/text()}");
final String hash = new XePrint(dirs).text("{/event/md5/text()}");
return new XeDirectives(new Directives().append(dirs).append(new XeLink("delete", new Href("/event-delete").with("title", title).with("hash", hash)).toXembly()).append(new XeLink("down", new Href("/event-down").with("title", title)).toXembly()));
}
use of org.xembly.Directives in project jcabi-github by jcabi.
the class MkPullComments method post.
// @checkstyle ParameterNumberCheck (7 lines)
@Override
public PullComment post(final String body, final String commit, final String path, final int position) throws IOException {
this.storage.lock();
final int number;
try {
number = 1 + this.storage.xml().nodes(String.format("%s/comment/id/text()", this.xpath())).size();
this.storage.apply(new Directives().xpath(this.xpath()).add("comment").add("id").set(Integer.toString(number)).up().add("url").set("http://localhost/1").up().add("diff_hunk").set("@@ -16,33 +16,40 @@ public...").up().add("path").set(path).up().add("position").set(Integer.toString(position)).up().add("original_position").set(Integer.toString(number)).up().add("commit_id").set(commit).up().add("original_commit_id").set(commit).up().add("body").set(body).up().add("created_at").set(new Github.Time().toString()).up().add("published_at").set(new Github.Time().toString()).up().add("user").add("login").set(this.self).up().add("pull_request_url").set("http://localhost/2").up());
} finally {
this.storage.unlock();
}
return this.get(number);
}
use of org.xembly.Directives in project jcabi-github by jcabi.
the class MkPulls method create.
@Override
public Pull create(final String title, final String head, final String base) throws IOException {
if (head.isEmpty()) {
throw new IllegalArgumentException("head cannot be empty!");
}
if (base.isEmpty()) {
throw new IllegalArgumentException("base cannot be empty!");
}
final String canonical;
if (head.contains(MkPulls.USER_BRANCH_SEP)) {
canonical = head;
} else {
canonical = String.format("%s%s%s", this.coords.user(), MkPulls.USER_BRANCH_SEP, head);
}
this.storage.lock();
final int number;
try {
final Issue issue = this.repo().issues().create(title, "some body");
number = issue.number();
this.storage.apply(new Directives().xpath(this.xpath()).add("pull").add("number").set(Integer.toString(number)).up().add("head").set(canonical).up().add("base").set(base).up().add("user").add("login").set(this.self).up());
} finally {
this.storage.unlock();
}
return this.get(number);
}
use of org.xembly.Directives in project jcabi-github by jcabi.
the class MkTrees method create.
@Override
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public Tree create(final JsonObject params) throws IOException {
final JsonArray trees = params.getJsonArray("tree");
for (final JsonValue val : trees) {
final JsonObject tree = (JsonObject) val;
final String sha = tree.getString("sha");
final Directives dirs = new Directives().xpath(this.xpath()).add("tree");
for (final Entry<String, JsonValue> entry : tree.entrySet()) {
dirs.add(entry.getKey()).set(entry.getValue().toString()).up();
}
this.storage.apply(dirs);
final String ref;
if (tree.containsValue("name")) {
ref = tree.getString("name");
} else {
ref = sha;
}
new MkReferences(this.storage, this.self, this.coords).create(new StringBuilder("refs/trees/").append(ref).toString(), sha);
}
return this.get(trees.getJsonObject(0).getString("sha"));
}
use of org.xembly.Directives in project jcabi-github by jcabi.
the class MkUserEmails method remove.
@Override
public void remove(final Iterable<String> emails) throws IOException {
final Directives directives = new Directives();
for (final String email : emails) {
directives.xpath(String.format("%s/email[.='%s']", this.xpath(), email)).remove();
}
this.storage.apply(directives);
}
Aggregations