Search in sources :

Example 1 with StoredCommentLinkInfo

use of com.google.gerrit.entities.StoredCommentLinkInfo in project gerrit by GerritCodeReview.

the class ProjectState method getCommentLinks.

public List<CommentLinkInfo> getCommentLinks() {
    Map<String, CommentLinkInfo> cls = new LinkedHashMap<>();
    for (CommentLinkInfo cl : commentLinks) {
        cls.put(cl.name.toLowerCase(), cl);
    }
    for (ProjectState s : treeInOrder()) {
        for (StoredCommentLinkInfo cl : s.getConfig().getCommentLinkSections().values()) {
            String name = cl.getName().toLowerCase();
            if (cl.getOverrideOnly()) {
                CommentLinkInfo parent = cls.get(name);
                if (parent == null) {
                    // Ignore invalid overrides.
                    continue;
                }
                cls.put(name, StoredCommentLinkInfo.fromInfo(parent, cl.getEnabled()).toInfo());
            } else {
                cls.put(name, cl.toInfo());
            }
        }
    }
    return ImmutableList.copyOf(cls.values());
}
Also used : StoredCommentLinkInfo(com.google.gerrit.entities.StoredCommentLinkInfo) CommentLinkInfo(com.google.gerrit.extensions.api.projects.CommentLinkInfo) StoredCommentLinkInfo(com.google.gerrit.entities.StoredCommentLinkInfo) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with StoredCommentLinkInfo

use of com.google.gerrit.entities.StoredCommentLinkInfo in project gerrit by GerritCodeReview.

the class CommentLinkProvider method parseConfig.

private List<CommentLinkInfo> parseConfig(Config cfg) {
    Set<String> subsections = cfg.getSubsections(ProjectConfig.COMMENTLINK);
    ImmutableList.Builder<CommentLinkInfo> cls = ImmutableList.builderWithExpectedSize(subsections.size());
    for (String name : subsections) {
        try {
            StoredCommentLinkInfo cl = ProjectConfig.buildCommentLink(cfg, name, true);
            if (cl.getOverrideOnly()) {
                logger.atWarning().log("commentlink %s empty except for \"enabled\"", name);
                continue;
            }
            cls.add(cl.toInfo());
        } catch (IllegalArgumentException e) {
            logger.atWarning().log("invalid commentlink: %s", e.getMessage());
        }
    }
    return cls.build();
}
Also used : StoredCommentLinkInfo(com.google.gerrit.entities.StoredCommentLinkInfo) StoredCommentLinkInfo(com.google.gerrit.entities.StoredCommentLinkInfo) CommentLinkInfo(com.google.gerrit.extensions.api.projects.CommentLinkInfo) ImmutableList(com.google.common.collect.ImmutableList)

Example 3 with StoredCommentLinkInfo

use of com.google.gerrit.entities.StoredCommentLinkInfo in project gerrit by GerritCodeReview.

the class ProjectConfigTest method addCommentLink.

@Test
public void addCommentLink() throws Exception {
    RevCommit rev = tr.commit().create();
    update(rev);
    ProjectConfig cfg = read(rev);
    StoredCommentLinkInfo cm = StoredCommentLinkInfo.builder("Test").setMatch("abc.*").setHtml("<a>link</a>").setEnabled(true).setOverrideOnly(false).build();
    cfg.addCommentLinkSection(cm);
    rev = commit(cfg);
    assertThat(text(rev, "project.config")).isEqualTo("[commentlink \"Test\"]\n\tmatch = abc.*\n\thtml = <a>link</a>\n");
}
Also used : StoredCommentLinkInfo(com.google.gerrit.entities.StoredCommentLinkInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 4 with StoredCommentLinkInfo

use of com.google.gerrit.entities.StoredCommentLinkInfo in project gerrit by GerritCodeReview.

the class StoredCommentLinkInfoSerializerTest method nullEnabled_roundTrip.

@Test
public void nullEnabled_roundTrip() {
    StoredCommentLinkInfo sourceAutoValue = StoredCommentLinkInfo.builder("name").setLink("<p>html").setMatch("*").build();
    StoredCommentLinkInfo storedAutoValue = StoredCommentLinkInfo.builder("name").setLink("<p>html").setMatch("*").setEnabled(true).build();
    assertThat(deserialize(serialize(sourceAutoValue))).isEqualTo(storedAutoValue);
}
Also used : StoredCommentLinkInfo(com.google.gerrit.entities.StoredCommentLinkInfo) Test(org.junit.Test)

Example 5 with StoredCommentLinkInfo

use of com.google.gerrit.entities.StoredCommentLinkInfo in project gerrit by GerritCodeReview.

the class StoredCommentLinkInfoSerializerTest method linkOnly_roundTrip.

@Test
public void linkOnly_roundTrip() {
    StoredCommentLinkInfo autoValue = StoredCommentLinkInfo.builder("name").setEnabled(true).setLink("<p>html").setMatch("*").build();
    assertThat(deserialize(serialize(autoValue))).isEqualTo(autoValue);
}
Also used : StoredCommentLinkInfo(com.google.gerrit.entities.StoredCommentLinkInfo) Test(org.junit.Test)

Aggregations

StoredCommentLinkInfo (com.google.gerrit.entities.StoredCommentLinkInfo)7 Test (org.junit.Test)5 CommentLinkInfo (com.google.gerrit.extensions.api.projects.CommentLinkInfo)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 ImmutableList (com.google.common.collect.ImmutableList)1 LinkedHashMap (java.util.LinkedHashMap)1