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