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