Search in sources :

Example 1 with ChangeSetResource

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());
}
Also used : User(hudson.model.User) ChangeLogSet(hudson.scm.ChangeLogSet) Reachable(io.jenkins.blueocean.rest.Reachable) ChangeSetResource(io.jenkins.blueocean.service.embedded.rest.ChangeSetResource) Link(io.jenkins.blueocean.rest.hal.Link) OrganizationImpl(io.jenkins.blueocean.service.embedded.rest.OrganizationImpl) Test(org.junit.Test)

Example 2 with ChangeSetResource

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);
    }
}
Also used : ChangeLogSet(hudson.scm.ChangeLogSet) Entry(hudson.scm.ChangeLogSet.Entry) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) StoppableRun(io.jenkins.blueocean.service.embedded.rest.StoppableRun) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) Run(hudson.model.Run) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) BlueChangeSetEntry(io.jenkins.blueocean.rest.model.BlueChangeSetEntry) ReplayCause(org.jenkinsci.plugins.workflow.cps.replay.ReplayCause) ChangeSetResource(io.jenkins.blueocean.service.embedded.rest.ChangeSetResource) LinkedHashMap(java.util.LinkedHashMap) Nonnull(javax.annotation.Nonnull)

Aggregations

ChangeLogSet (hudson.scm.ChangeLogSet)2 ChangeSetResource (io.jenkins.blueocean.service.embedded.rest.ChangeSetResource)2 Run (hudson.model.Run)1 User (hudson.model.User)1 Entry (hudson.scm.ChangeLogSet.Entry)1 Reachable (io.jenkins.blueocean.rest.Reachable)1 Link (io.jenkins.blueocean.rest.hal.Link)1 BlueChangeSetEntry (io.jenkins.blueocean.rest.model.BlueChangeSetEntry)1 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)1 OrganizationImpl (io.jenkins.blueocean.service.embedded.rest.OrganizationImpl)1 StoppableRun (io.jenkins.blueocean.service.embedded.rest.StoppableRun)1 LinkedHashMap (java.util.LinkedHashMap)1 Nonnull (javax.annotation.Nonnull)1 ReplayCause (org.jenkinsci.plugins.workflow.cps.replay.ReplayCause)1 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)1 Test (org.junit.Test)1