Search in sources :

Example 6 with Directives

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

the class MkIssueEvents method create.

/**
 * Creates a new issue event.
 * This has no equivalent in GitHub's public API, since GitHub generates
 * events automatically in response to some other API calls.
 * @param type Type of event
 * @param issue ID number of issue the event is regarding
 * @param login Username of actor who caused the event
 * @param label Label added or removed
 * @return The newly created issue event
 * @throws IOException If there is any I/O problem
 * @todo #1063:30min Make it possible to set the "assignee" field for
 *  "assigned"/"unassigned" events. Make it possible to set the
 *  "milestone" field for "milestoned"/"demilestoned" events. Make it
 *  possible to set the "rename" field for "renamed" events. Make it
 *  possible to set the "commit_id" field for events related to commits.
 *  See https://developer.github.com/v3/issues/events/ for details.
 * @checkstyle ParameterNumberCheck (4 lines)
 */
public Event create(final String type, final int issue, final String login, final Optional<String> label) throws IOException {
    final String created = new Github.Time().toString();
    this.storage.lock();
    final int number;
    try {
        number = 1 + this.storage.xml().xpath(String.format("%s/issue-event/number/text()", this.xpath())).size();
        Directives directives = new Directives().xpath(this.xpath()).add("issue-event").add("issue").set(Integer.toString(issue)).up().add("number").set(Integer.toString(number)).up().add("event").set(type).up().add("created_at").set(created).up().add("login").set(login).up();
        if (label.isPresent()) {
            directives = directives.add("label").set(label.get()).up();
        }
        this.storage.apply(directives);
    } finally {
        this.storage.unlock();
    }
    Logger.info(MkEvent.class, "issue event #%d of type %s created in %s for issue #%d by %s", number, type, this.self, issue, login);
    return this.get(number);
}
Also used : Github(com.jcabi.github.Github) Directives(org.xembly.Directives) ToString(lombok.ToString)

Example 7 with Directives

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

the class MkForks method create.

@Override
public Fork create(final String org) throws IOException {
    this.storage.lock();
    final int number;
    try {
        number = 1 + this.storage.xml().xpath(String.format("%s/fork/id/text()", this.xpath())).size();
        this.storage.apply(new Directives().xpath(this.xpath()).add("fork").add("id").set(Integer.toString(number)).up().attr("organization", org));
    } finally {
        this.storage.unlock();
    }
    Logger.info(this, "fork %s created inside %s by %s", this.coords, org, this.self);
    return this.get(number);
}
Also used : Directives(org.xembly.Directives)

Example 8 with Directives

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

the class MkGists method create.

@Override
public Gist create(final Map<String, String> files, final boolean visible) throws IOException {
    this.storage.lock();
    final String number;
    try {
        number = Integer.toString(1 + this.storage.xml().xpath(String.format("%s/gist/id/text()", this.xpath())).size());
        final Directives dirs = new Directives().xpath(this.xpath()).add("gist").add("id").set(number).up().add("public").set(String.valueOf(visible)).up().add("files");
        for (final Map.Entry<String, String> file : files.entrySet()) {
            dirs.add("file").add("filename").set(file.getKey()).up().add("raw_content").set(file.getValue()).up().up();
        }
        this.storage.apply(dirs);
    } finally {
        this.storage.unlock();
    }
    return this.get(number);
}
Also used : Directives(org.xembly.Directives) ToString(lombok.ToString) Map(java.util.Map)

Example 9 with Directives

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

the class MkIssueLabels method remove.

@Override
public void remove(final String name) throws IOException {
    if (this.labels().contains(name)) {
        this.storage.apply(new Directives().xpath(String.format("%s/label[.='%s']", this.xpath(), name)).remove());
        new MkIssueEvents(this.storage, this.self, this.repo).create(Event.UNLABELED, this.ticket, this.self, Optional.of(name));
    }
}
Also used : Directives(org.xembly.Directives)

Example 10 with Directives

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

the class MkBlobs method create.

@Override
public Blob create(final String content, final String encoding) throws IOException {
    this.storage.lock();
    final String sha = fakeSha();
    try {
        this.storage.apply(new Directives().xpath(this.xpath()).add("blob").add("sha").set(sha).up().add("url").set("http://localhost/1").up().attr("content", content).attr("encoding", encoding));
    } finally {
        this.storage.unlock();
    }
    return this.get(sha);
}
Also used : Directives(org.xembly.Directives)

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