Search in sources :

Example 11 with Directives

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()));
}
Also used : Directives(org.xembly.Directives) XeDirectives(org.takes.rs.xe.XeDirectives) Href(org.takes.misc.Href) XePrint(io.wring.model.XePrint) XeLink(org.takes.rs.xe.XeLink) Directive(org.xembly.Directive) XeDirectives(org.takes.rs.xe.XeDirectives)

Example 12 with Directives

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);
}
Also used : Github(com.jcabi.github.Github) Directives(org.xembly.Directives)

Example 13 with Directives

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);
}
Also used : Issue(com.jcabi.github.Issue) Directives(org.xembly.Directives) ToString(lombok.ToString)

Example 14 with Directives

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"));
}
Also used : JsonArray(javax.json.JsonArray) Directives(org.xembly.Directives) JsonValue(javax.json.JsonValue) JsonObject(javax.json.JsonObject)

Example 15 with Directives

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);
}
Also used : Directives(org.xembly.Directives) ToString(lombok.ToString)

Aggregations

Directives (org.xembly.Directives)28 ToString (lombok.ToString)12 Github (com.jcabi.github.Github)4 Map (java.util.Map)3 JsonValue (javax.json.JsonValue)3 JsonObject (javax.json.JsonObject)2 Test (org.junit.Test)2 Coordinates (com.jcabi.github.Coordinates)1 Issue (com.jcabi.github.Issue)1 Repo (com.jcabi.github.Repo)1 XML (com.jcabi.xml.XML)1 FkBase (io.wring.fake.FkBase)1 FkPipe (io.wring.fake.FkPipe)1 Base (io.wring.model.Base)1 Pipe (io.wring.model.Pipe)1 XePrint (io.wring.model.XePrint)1 HashSet (java.util.HashSet)1 JsonArray (javax.json.JsonArray)1 Href (org.takes.misc.Href)1 XeDirectives (org.takes.rs.xe.XeDirectives)1