Search in sources :

Example 21 with Directives

use of org.xembly.Directives in project jcabi-github by jcabi.

the class MkUserEmails method add.

@Override
public Iterable<String> add(final Iterable<String> emails) throws IOException {
    this.storage.lock();
    try {
        final Directives directives = new Directives().xpath(this.xpath());
        for (final String email : emails) {
            directives.add("email").set(email).up();
        }
        this.storage.apply(directives);
    } finally {
        this.storage.unlock();
    }
    return emails;
}
Also used : Directives(org.xembly.Directives) ToString(lombok.ToString)

Example 22 with Directives

use of org.xembly.Directives in project jcabi-github by jcabi.

the class MkBranches method create.

/**
 * Creates a new branch.
 * @param name Name of branch
 * @param sha Commit SHA
 * @return New branch
 * @throws IOException if there is an I/O problem
 */
public Branch create(final String name, final String sha) throws IOException {
    final Directives directives = new Directives().xpath(this.xpath()).add("branch").attr("name", name).add("sha").set(sha).up();
    this.storage.apply(directives);
    return new MkBranch(this.storage, this.self, this.coords, name, sha);
}
Also used : Directives(org.xembly.Directives)

Example 23 with Directives

use of org.xembly.Directives in project jcabi-github by jcabi.

the class MkContents method commit.

/**
 * XML Directives for commit creation.
 * @param json Source
 * @return SHA string
 * @throws IOException If an IO Exception occurs
 */
private MkRepoCommit commit(final JsonObject json) throws IOException {
    final String sha = fakeSha();
    // @checkstyle MultipleStringLiterals (40 lines)
    final Directives commit = new Directives().xpath(this.commitXpath()).add("commit").add("sha").set(sha).up().add("url").set("http://localhost/4").up().add("html_url").set("http://localhost/5").up().add("message").set(json.getString("message")).up();
    if (json.containsKey("committer")) {
        final JsonObject committer = json.getJsonObject("committer");
        commit.add("committer").add("email").set(committer.getString("email")).up().add("name").set(committer.getString("name")).up();
    }
    if (json.containsKey("author")) {
        final JsonObject author = json.getJsonObject("author");
        commit.add("author").add("email").set(author.getString("email")).up().add("name").set(author.getString("name")).up();
    }
    this.storage.apply(commit);
    return new MkRepoCommit(this.storage, this.repo(), sha);
}
Also used : Directives(org.xembly.Directives) JsonObject(javax.json.JsonObject) ToString(lombok.ToString)

Example 24 with Directives

use of org.xembly.Directives in project jcabi-github by jcabi.

the class MkReleaseAssets method upload.

@Override
public ReleaseAsset upload(final byte[] content, final String type, final String name) throws IOException {
    this.storage.lock();
    final int number;
    try {
        number = 1 + this.storage.xml().xpath(String.format("%s/asset/id/text()", this.xpath())).size();
        this.storage.apply(new Directives().xpath(this.xpath()).add("asset").add("id").set(Integer.toString(number)).up().add("name").set(name).up().add("content").set(DatatypeConverter.printBase64Binary(content)).up().add("content_type").set(type).up().add("size").set(Integer.toString(content.length)).up().add("download_count").set("42").up().add("created_at").set(new Github.Time().toString()).up().add("updated_at").set(new Github.Time().toString()).up().add("url").set("http://localhost/1").up().add("html_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 25 with Directives

use of org.xembly.Directives in project jcabi-github by jcabi.

the class MkComments method post.

@Override
public Comment post(final String text) throws IOException {
    this.storage.lock();
    final int number;
    try {
        final String timestamp = new Github.Time().toString();
        number = 1 + this.storage.xml().nodes("//comment/number").size();
        this.storage.apply(new Directives().xpath(this.xpath()).add("comment").add("number").set(Integer.toString(number)).up().add("url").set(String.format(// @checkstyle LineLength (1 line)
        "https://api.jcabi-github.invalid/repos/%s/%s/issues/comments/%d", this.repo.user(), this.repo.repo(), number)).up().add("body").set(text).up().add("user").add("login").set(this.self).up().up().add("created_at").set(timestamp).up().add("updated_at").set(timestamp));
    } finally {
        this.storage.unlock();
    }
    Logger.info(this, "comment #%d posted to issue #%d by %s: %[text]s", number, this.issue().number(), this.self, text);
    return this.get(number);
}
Also used : Github(com.jcabi.github.Github) 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