use of io.jenkins.blueocean.service.embedded.rest.ChangeSetResource in project blueocean-plugin by jenkinsci.
the class ChangeSetResourceTest method testChangeSet.
@Test
public void testChangeSet() {
Reachable reachable = mock(Reachable.class);
when(reachable.getLink()).thenReturn(new Link("/foo/bar"));
User user = mock(User.class);
when(user.getId()).thenReturn("vivek");
ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);
when(entry.getAuthor()).thenReturn(user);
when(entry.getTimestamp()).thenReturn(System.currentTimeMillis());
when(entry.getCommitId()).thenReturn("12345");
when(entry.getMsg()).thenReturn("test changeset");
when(entry.getAffectedPaths()).thenReturn(Collections.singleton("/foo/bar"));
ChangeSetResource changeSetResource = new ChangeSetResource(new OrganizationImpl("testorg", mock(Folder.class)), entry, reachable);
assertEquals(user.getId(), changeSetResource.getAuthor().getId());
assertEquals(entry.getCommitId(), changeSetResource.getCommitId());
assertEquals(entry.getMsg(), changeSetResource.getMsg());
}
use of io.jenkins.blueocean.service.embedded.rest.ChangeSetResource in project blueocean-plugin by jenkinsci.
the class PipelineRunImpl method getChangeSet.
@Override
@Nonnull
public Container<BlueChangeSetEntry> getChangeSet() {
// If this run is a replay then return the changesets from the original run
ReplayCause replayCause = run.getCause(ReplayCause.class);
if (replayCause != null) {
Run run = this.run.getParent().getBuildByNumber(replayCause.getOriginalNumber());
if (run == null) {
return Containers.empty(getLink());
}
BlueRun blueRun = BlueRunFactory.getRun(run, parent);
if (blueRun == null) {
return Containers.empty(getLink());
}
return blueRun.getChangeSet();
} else {
Map<String, BlueChangeSetEntry> m = new LinkedHashMap<>();
int cnt = 0;
for (ChangeLogSet<? extends Entry> cs : run.getChangeSets()) {
for (ChangeLogSet.Entry e : cs) {
cnt++;
String id = e.getCommitId();
if (id == null)
id = String.valueOf(cnt);
m.put(id, new ChangeSetResource(organization, e, this));
}
}
return Containers.fromResourceMap(getLink(), m);
}
}
Aggregations