Search in sources :

Example 16 with Directives

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

the class MkIssueLabels method add.

@Override
public void add(final Iterable<String> labels) throws IOException {
    final Collection<String> existing = this.labels();
    final Set<String> added = new HashSet<String>();
    final Directives dirs = new Directives().xpath(this.xpath());
    for (final String label : labels) {
        dirs.add("label").set(label).up();
        if (!existing.contains(label)) {
            added.add(label);
        }
    }
    this.storage.apply(dirs);
    if (!added.isEmpty()) {
        final MkIssueEvents events = new MkIssueEvents(this.storage, this.self, this.repo);
        for (final String label : added) {
            events.create(Event.LABELED, this.ticket, this.self, Optional.of(label));
        }
    }
}
Also used : Directives(org.xembly.Directives) ToString(lombok.ToString) HashSet(java.util.HashSet)

Example 17 with Directives

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

the class MkMilestones method create.

@Override
public Milestone create(final String title) throws IOException {
    final int number;
    number = 1 + this.storage.xml().xpath(String.format("%s/milestone/number/text()", this.xpath())).size();
    this.storage.apply(new Directives().xpath(this.xpath()).add("milestone").add("number").set(Integer.toString(number)).up().add("title").set(title).up().add("state").set(Milestone.OPEN_STATE).up().add("description").set("mock milestone").up());
    return this.get(number);
}
Also used : Directives(org.xembly.Directives)

Example 18 with Directives

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

the class MkPublicKeys method create.

@Override
public PublicKey create(final String title, final String key) throws IOException {
    this.storage.lock();
    final int number;
    try {
        number = 1 + this.storage.xml().xpath(String.format("%s/key/id/text()", this.xpath())).size();
        this.storage.apply(new Directives().xpath(this.xpath()).add("key").add("id").set(String.valueOf(number)).up().add("title").set(title).up().add("key").set(key));
    } finally {
        this.storage.unlock();
    }
    return this.get(number);
}
Also used : Directives(org.xembly.Directives)

Example 19 with Directives

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

the class MkRepos method create.

@Override
public Repo create(final RepoCreate settings) throws IOException {
    final Coordinates coords = new Coordinates.Simple(this.self, settings.name());
    this.storage.apply(new Directives().xpath(this.xpath()).add("repo").attr("coords", coords.toString()).add("name").set(settings.name()).up().add("description").set("test repository").up().add("private").set("false").up());
    final Repo repo = this.get(coords);
    repo.patch(settings.json());
    Logger.info(this, "repository %s created by %s", coords, this.self);
    return repo;
}
Also used : Repo(com.jcabi.github.Repo) Directives(org.xembly.Directives) Coordinates(com.jcabi.github.Coordinates)

Example 20 with Directives

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

the class MkTags method create.

@Override
public Tag create(final JsonObject params) throws IOException {
    final Directives dirs = new Directives().xpath(this.xpath()).add("tag");
    for (final Entry<String, JsonValue> entry : params.entrySet()) {
        dirs.add(entry.getKey()).set(entry.getValue().toString()).up();
    }
    this.storage.apply(dirs);
    new MkReferences(this.storage, this.self, this.coords).create(new StringBuilder().append("refs/tags/").append(params.getString("name")).toString(), params.getString("sha"));
    return this.get(params.getString("sha"));
}
Also used : Directives(org.xembly.Directives) JsonValue(javax.json.JsonValue)

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