Search in sources :

Example 1 with ReferenceMetadata

use of org.projectnessie.model.ReferenceMetadata in project nessie by projectnessie.

the class TreeApiImpl method filterReferences.

/**
 * Applies different filters to the {@link Stream} of references on the filter.
 *
 * @param references The references that different filters will be applied to
 * @param filter The filter to filter by
 * @return A potentially filtered {@link Stream} of commits based on the filter
 */
private Stream<Reference> filterReferences(Stream<Reference> references, String filter) {
    if (Strings.isNullOrEmpty(filter)) {
        return references;
    }
    final Script script;
    try {
        script = SCRIPT_HOST.buildScript(filter).withContainer(CONTAINER).withDeclarations(REFERENCES_DECLARATIONS).withTypes(REFERENCES_TYPES).build();
    } catch (ScriptException e) {
        throw new IllegalArgumentException(e);
    }
    return references.filter(reference -> {
        try {
            ReferenceMetadata refMeta = reference.getMetadata();
            if (refMeta == null) {
                refMeta = CELUtil.EMPTY_REFERENCE_METADATA;
            }
            CommitMeta commit = refMeta.getCommitMetaOfHEAD();
            if (commit == null) {
                commit = CELUtil.EMPTY_COMMIT_META;
            }
            return script.execute(Boolean.class, ImmutableMap.of(VAR_REF, reference, VAR_REF_TYPE, reference.getType().name(), VAR_COMMIT, commit, VAR_REF_META, refMeta));
        } catch (ScriptException e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : Script(org.projectnessie.cel.tools.Script) ScriptException(org.projectnessie.cel.tools.ScriptException) CommitMeta(org.projectnessie.model.CommitMeta) ReferenceMetadata(org.projectnessie.model.ReferenceMetadata) ImmutableReferenceMetadata(org.projectnessie.model.ImmutableReferenceMetadata)

Example 2 with ReferenceMetadata

use of org.projectnessie.model.ReferenceMetadata in project nessie by projectnessie.

the class AbstractRestReferences method verifyMetadataProperties.

void verifyMetadataProperties(int expectedCommitsAhead, int expectedCommitsBehind, Branch branch, Reference reference, long expectedCommits) throws NessieNotFoundException {
    List<LogEntry> commits = getApi().getCommitLog().refName(branch.getName()).maxRecords(1).get().getLogEntries();
    assertThat(commits).hasSize(1);
    CommitMeta commitMeta = commits.get(0).getCommitMeta();
    ReferenceMetadata referenceMetadata = branch.getMetadata();
    assertThat(referenceMetadata).isNotNull();
    assertThat(referenceMetadata.getNumCommitsAhead()).isEqualTo(expectedCommitsAhead);
    assertThat(referenceMetadata.getNumCommitsBehind()).isEqualTo(expectedCommitsBehind);
    assertThat(referenceMetadata.getCommitMetaOfHEAD()).isEqualTo(commitMeta);
    assertThat(referenceMetadata.getCommonAncestorHash()).isEqualTo(reference.getHash());
    assertThat(referenceMetadata.getNumTotalCommits()).isEqualTo(expectedCommits);
}
Also used : CommitMeta(org.projectnessie.model.CommitMeta) LogEntry(org.projectnessie.model.LogResponse.LogEntry) ReferenceMetadata(org.projectnessie.model.ReferenceMetadata)

Example 3 with ReferenceMetadata

use of org.projectnessie.model.ReferenceMetadata in project nessie by projectnessie.

the class AbstractRestReferences method verifyMetadataProperties.

void verifyMetadataProperties(Tag tag) throws NessieNotFoundException {
    List<LogEntry> commits = getApi().getCommitLog().refName(tag.getName()).maxRecords(1).get().getLogEntries();
    assertThat(commits).hasSize(1);
    CommitMeta commitMeta = commits.get(0).getCommitMeta();
    ReferenceMetadata referenceMetadata = tag.getMetadata();
    assertThat(referenceMetadata).isNotNull();
    assertThat(referenceMetadata.getNumCommitsAhead()).isNull();
    assertThat(referenceMetadata.getNumCommitsBehind()).isNull();
    assertThat(referenceMetadata.getCommitMetaOfHEAD()).isEqualTo(commitMeta);
    assertThat(referenceMetadata.getCommonAncestorHash()).isNull();
    assertThat(referenceMetadata.getNumTotalCommits()).isEqualTo(10);
}
Also used : CommitMeta(org.projectnessie.model.CommitMeta) LogEntry(org.projectnessie.model.LogResponse.LogEntry) ReferenceMetadata(org.projectnessie.model.ReferenceMetadata)

Aggregations

CommitMeta (org.projectnessie.model.CommitMeta)3 ReferenceMetadata (org.projectnessie.model.ReferenceMetadata)3 LogEntry (org.projectnessie.model.LogResponse.LogEntry)2 Script (org.projectnessie.cel.tools.Script)1 ScriptException (org.projectnessie.cel.tools.ScriptException)1 ImmutableReferenceMetadata (org.projectnessie.model.ImmutableReferenceMetadata)1