use of org.eclipse.jgit.lib.ReflogEntry in project gerrit by GerritCodeReview.
the class GetReflog method apply.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Override
public Response<List<ReflogEntryInfo>> apply(BranchResource rsrc) throws RestApiException, IOException, PermissionBackendException {
permissionBackend.user(rsrc.getUser()).project(rsrc.getNameKey()).check(ProjectPermission.READ_REFLOG);
try (Repository repo = repoManager.openRepository(rsrc.getNameKey())) {
ReflogReader r;
try {
r = repo.getReflogReader(rsrc.getRef());
} catch (UnsupportedOperationException e) {
String msg = "reflog not supported on repo " + rsrc.getNameKey().get();
logger.atSevere().log("%s", msg);
throw new MethodNotAllowedException(msg, e);
}
if (r == null) {
throw new ResourceNotFoundException(rsrc.getRef());
}
List<ReflogEntry> entries;
if (from == null && to == null) {
entries = limit > 0 ? r.getReverseEntries(limit) : r.getReverseEntries();
} else {
entries = limit > 0 ? new ArrayList<>(limit) : new ArrayList<>();
for (ReflogEntry e : r.getReverseEntries()) {
Instant timestamp = e.getWho().getWhen().toInstant();
if ((from == null || from.isBefore(timestamp)) && (to == null || to.isAfter(timestamp))) {
entries.add(e);
}
if (limit > 0 && entries.size() >= limit) {
break;
}
}
}
return Response.ok(Lists.transform(entries, this::newReflogEntryInfo));
}
}
use of org.eclipse.jgit.lib.ReflogEntry in project gerrit by GerritCodeReview.
the class ReflogIT method peerIPIncludedInReflogRecord.
@Test
@GerritConfig(name = "gerrit.enablePeerIPInReflogRecord", value = "true")
public void peerIPIncludedInReflogRecord() throws Exception {
PushOneCommit.Result r = createChange();
Change.Id id = r.getChange().getId();
try (Repository repo = repoManager.openRepository(r.getChange().project())) {
File log = new File(repo.getDirectory(), "logs/" + changeMetaRef(id));
if (!log.exists()) {
log.getParentFile().mkdirs();
assertThat(log.createNewFile()).isTrue();
}
gApi.changes().id(id.get()).topic("foo");
ReflogEntry last = repo.getReflogReader(changeMetaRef(id)).getLastEntry();
assertThat(last.getWho().getEmailAddress()).isEqualTo(admin.username() + "|account-" + admin.id() + "@unknown");
}
}
use of org.eclipse.jgit.lib.ReflogEntry in project gerrit by GerritCodeReview.
the class ReflogIT method emaiIncludedInReflogRecord.
@Test
public void emaiIncludedInReflogRecord() throws Exception {
PushOneCommit.Result r = createChange();
Change.Id id = r.getChange().getId();
try (Repository repo = repoManager.openRepository(r.getChange().project())) {
File log = new File(repo.getDirectory(), "logs/" + changeMetaRef(id));
if (!log.exists()) {
log.getParentFile().mkdirs();
assertThat(log.createNewFile()).isTrue();
}
gApi.changes().id(id.get()).topic("foo");
ReflogEntry last = repo.getReflogReader(changeMetaRef(id)).getLastEntry();
assertThat(last.getWho().getEmailAddress()).isEqualTo(admin.email());
}
}
use of org.eclipse.jgit.lib.ReflogEntry in project gerrit by GerritCodeReview.
the class ReflogIT method guessRestApiInReflog.
@Test
public void guessRestApiInReflog() throws Exception {
PushOneCommit.Result r = createChange();
Change.Id id = r.getChange().getId();
try (Repository repo = repoManager.openRepository(r.getChange().project())) {
File log = new File(repo.getDirectory(), "logs/" + changeMetaRef(id));
if (!log.exists()) {
log.getParentFile().mkdirs();
assertThat(log.createNewFile()).isTrue();
}
gApi.changes().id(id.get()).topic("foo");
ReflogEntry last = repo.getReflogReader(changeMetaRef(id)).getLastEntry();
assertWithMessage("last RefLogEntry").that(last).isNotNull();
assertThat(last.getComment()).isEqualTo("restapi.change.PutTopic");
}
}
Aggregations