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