Search in sources :

Example 1 with DashboardSectionInfo

use of com.google.gerrit.extensions.api.projects.DashboardSectionInfo in project gerrit by GerritCodeReview.

the class DashboardsCollection method parse.

static DashboardInfo parse(Project definingProject, String refName, String path, Config config, String project, boolean setDefault) {
    DashboardInfo info = newDashboardInfo(refName, path);
    info.project = project;
    info.definingProject = definingProject.getName();
    String title = config.getString("dashboard", null, "title");
    info.title = replace(project, title == null ? info.path : title);
    info.description = replace(project, config.getString("dashboard", null, "description"));
    info.foreach = config.getString("dashboard", null, "foreach");
    if (setDefault) {
        String id = refName + ":" + path;
        info.isDefault = id.equals(defaultOf(definingProject)) ? true : null;
    }
    UrlEncoded u = new UrlEncoded("/dashboard/");
    u.put("title", MoreObjects.firstNonNull(info.title, info.path));
    if (info.foreach != null) {
        u.put("foreach", replace(project, info.foreach));
    }
    for (String name : config.getSubsections("section")) {
        DashboardSectionInfo s = new DashboardSectionInfo();
        s.name = name;
        s.query = config.getString("section", name, "query");
        u.put(s.name, replace(project, s.query));
        info.sections.add(s);
    }
    info.url = u.toString().replace("%3A", ":");
    return info;
}
Also used : DashboardSectionInfo(com.google.gerrit.extensions.api.projects.DashboardSectionInfo) UrlEncoded(com.google.gerrit.server.UrlEncoded) IdString(com.google.gerrit.extensions.restapi.IdString) DashboardInfo(com.google.gerrit.extensions.api.projects.DashboardInfo)

Example 2 with DashboardSectionInfo

use of com.google.gerrit.extensions.api.projects.DashboardSectionInfo in project gerrit by GerritCodeReview.

the class DashboardIT method createDashboard.

private DashboardInfo createDashboard(DashboardInfo info) throws Exception {
    String canonicalRef = DashboardsCollection.normalizeDashboardRef(info.ref);
    try {
        project().branch(canonicalRef).create(new BranchInput());
    } catch (ResourceConflictException e) {
        // The branch already exists if this method has already been called once.
        if (!e.getMessage().contains("already exists")) {
            throw e;
        }
    }
    try (Repository r = repoManager.openRepository(project);
        TestRepository<Repository> tr = new TestRepository<>(r)) {
        TestRepository<Repository>.CommitBuilder cb = tr.branch(canonicalRef).commit();
        StringBuilder content = new StringBuilder("[dashboard]\n");
        if (info.title != null) {
            content.append("title = ").append(info.title).append("\n");
        }
        if (info.description != null) {
            content.append("description = ").append(info.description).append("\n");
        }
        if (info.foreach != null) {
            content.append("foreach = ").append(info.foreach).append("\n");
        }
        if (info.sections != null) {
            for (DashboardSectionInfo section : info.sections) {
                content.append("[section \"").append(section.name).append("\"]\n");
                content.append("query = ").append(section.query).append("\n");
            }
        }
        cb.add(info.path, content.toString());
        RevCommit c = cb.create();
        project().commit(c.name());
    }
    return info;
}
Also used : DashboardSectionInfo(com.google.gerrit.extensions.api.projects.DashboardSectionInfo) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) TestRepository(org.eclipse.jgit.junit.TestRepository) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 3 with DashboardSectionInfo

use of com.google.gerrit.extensions.api.projects.DashboardSectionInfo in project gerrit by GerritCodeReview.

the class DashboardIT method newDashboardInfo.

private DashboardInfo newDashboardInfo(String ref, String path) {
    DashboardInfo info = DashboardsCollection.newDashboardInfo(ref, path);
    info.title = "Reviewer";
    info.description = "Own review requests";
    info.foreach = "owner:self";
    DashboardSectionInfo section = new DashboardSectionInfo();
    section.name = "Open";
    section.query = "is:open";
    info.sections = ImmutableList.of(section);
    return info;
}
Also used : DashboardSectionInfo(com.google.gerrit.extensions.api.projects.DashboardSectionInfo) DashboardInfo(com.google.gerrit.extensions.api.projects.DashboardInfo)

Aggregations

DashboardSectionInfo (com.google.gerrit.extensions.api.projects.DashboardSectionInfo)3 DashboardInfo (com.google.gerrit.extensions.api.projects.DashboardInfo)2 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)1 IdString (com.google.gerrit.extensions.restapi.IdString)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 UrlEncoded (com.google.gerrit.server.UrlEncoded)1 TestRepository (org.eclipse.jgit.junit.TestRepository)1 Repository (org.eclipse.jgit.lib.Repository)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1