hudson.plugins.git.util.BuildData Java Examples

The following examples show how to use hudson.plugins.git.util.BuildData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommitStatusUpdater.java    From gitlab-plugin with GNU General Public License v2.0 8 votes vote down vote up
private static String getBuildRevision(Run<?, ?> build) {
    GitLabWebHookCause cause = build.getCause(GitLabWebHookCause.class);
    if (cause != null) {
        return cause.getData().getLastCommit();
    }

    BuildData action = build.getAction(BuildData.class);
    if (action == null) {
        throw new IllegalStateException("No (git-plugin) BuildData associated to current build");
    }
    Revision lastBuiltRevision = action.getLastBuiltRevision();

    if (lastBuiltRevision == null) {
        throw new IllegalStateException("Last build has no associated commit");
    }

    return action.getLastBuild(lastBuiltRevision.getSha1()).getMarked().getSha1String();
}
 
Example #2
Source File: GitScmAdapter.java    From bitbucket-build-status-notifier-plugin with MIT License 6 votes vote down vote up
public Map<String, URIish> getCommitRepoMap() throws Exception {
    List<RemoteConfig> repoList = this.gitScm.getRepositories();
    if (repoList.size() < 1) {
        throw new Exception("No repos found");
    }

    HashMap<String, URIish> commitRepoMap = new HashMap<String, URIish>();
    BuildData buildData = build.getAction(BuildData.class);
    if (buildData == null || buildData.getLastBuiltRevision() == null) {
        logger.warning("Build data could not be found");
    } else {
        commitRepoMap.put(buildData.getLastBuiltRevision().getSha1String(), repoList.get(0).getURIs().get(0));
    }

    return commitRepoMap;
}
 
Example #3
Source File: BuildUtilTest.java    From gitlab-plugin with GNU General Public License v2.0 6 votes vote down vote up
private BuildData createBuildData(String sha) {
  
  BuildData buildData = mock(BuildData.class);
  Revision revision = mock(Revision.class);
  when(revision.getSha1String()).thenReturn(sha);
  when(buildData.getLastBuiltRevision()).thenReturn(revision);

  Build gitBuild = mock(Build.class);
  when(gitBuild.getMarked()).thenReturn(revision);
  when(buildData.getLastBuild(any(ObjectId.class))).thenReturn(gitBuild);
  when(gitBuild.getRevision()).thenReturn(revision);
  when(gitBuild.isFor(sha)).thenReturn(true);
  buildData.lastBuild = gitBuild;

  return buildData;
}
 
Example #4
Source File: BuildUtilTest.java    From gitlab-plugin with GNU General Public License v2.0 6 votes vote down vote up
private AbstractProject<?,?> createProject(String... shas) {
  AbstractBuild build = mock(AbstractBuild.class);
  List<BuildData> buildDatas = new ArrayList<BuildData>();
  for(String sha : shas) {
    BuildData buildData = createBuildData(sha);
    buildDatas.add(buildData);
  }

  when(build.getAction(BuildData.class)).thenReturn(buildDatas.get(0));
  when(build.getActions(BuildData.class)).thenReturn(buildDatas);

  AbstractProject<?, ?> project = mock(AbstractProject.class);
  when(build.getProject()).thenReturn(project);

  RunList list = mock(RunList.class);
  when(list.iterator()).thenReturn(Arrays.asList(build).iterator());
  when(project.getBuilds()).thenReturn(list);

  return project;
}
 
Example #5
Source File: DeflakeGitBuildChooser.java    From flaky-test-handler-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Get failing build revision if this is a deflake build, otherwise use the default build chooser
 */
@Override
public Collection<Revision> getCandidateRevisions(boolean isPollCall, String singleBranch, GitClient git,
    TaskListener listener, BuildData buildData, BuildChooserContext context)
    throws GitException, IOException, InterruptedException {

  // Not sure why it cannot be inferred and we have to put cast here
  DeflakeCause cause = (DeflakeCause) context.getBuild().getCause(DeflakeCause.class);

  if (cause != null) {
    BuildData gitBuildData = gitSCM.getBuildData(cause.getUpstreamRun(), true);
    Revision revision = gitBuildData.getLastBuiltRevision();
    if (revision != null) {
      return Collections.singletonList(revision);
    }
  }

  // If it is not a deflake run, then use the default git checkout strategy
  defaultBuildChooser.gitSCM = this.gitSCM;
  return defaultBuildChooser.getCandidateRevisions(isPollCall, singleBranch, git, listener, buildData, context);
}
 
Example #6
Source File: HistoryAggregatedFlakyTestResultAction.java    From flaky-test-handler-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a SingleTestFlakyStatsWithRevision object with {@link SingleTestFlakyStats} and
 * build information.
 *
 * @param stats Embedded {@link SingleTestFlakyStats} object
 * @param build The {@link hudson.model.Run} object to get SCM information from.
 */
public SingleTestFlakyStatsWithRevision(SingleTestFlakyStats stats, Run build) {
  this.stats = stats;
  revision = Integer.toString(build.getNumber());

  Job job = build.getParent();
  SCMTriggerItem s = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job);
  if (s != null) {
    ArrayList<SCM> scms = new ArrayList<>(s.getSCMs());
    SCM scm = scms.size() > 0 ? scms.get(0) : null;

    if (scm != null && "hudson.plugins.git.GitSCM".equalsIgnoreCase(scm.getType())) {
      GitSCM gitSCM = (GitSCM) scm;
      BuildData buildData = gitSCM.getBuildData(build);
      if (buildData != null) {
        Revision gitRevision = buildData.getLastBuiltRevision();
        if (gitRevision != null) {
          revision = gitRevision.getSha1String();
        }
      }
    }
  }
}
 
Example #7
Source File: BuildUtil.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
public static Run<?, ?> getBuildBySHA1WithoutMergeBuilds(Job<?, ?> project, String sha1) {
    for (Run<?, ?> build : project.getBuilds()) {
        MergeRecord merge = build.getAction(MergeRecord.class);
        for(BuildData data : build.getActions(BuildData.class)) {
            if (hasLastBuild(data) && isNoMergeBuild(data, merge) && data.lastBuild.isFor(sha1)) {
                return build;
            }
        }
    }
    return null;
}
 
Example #8
Source File: TestUtility.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
static AbstractBuild mockSimpleBuild(String gitLabConnection, Result result, String... remoteUrls) {
    AbstractBuild build = mock(AbstractBuild.class);
    BuildData buildData = mock(BuildData.class);
    when(buildData.getRemoteUrls()).thenReturn(new HashSet<>(Arrays.asList(remoteUrls)));
    when(build.getAction(BuildData.class)).thenReturn(buildData);
    when(build.getResult()).thenReturn(result);
    when(build.getUrl()).thenReturn(BUILD_URL);
    when(build.getResult()).thenReturn(result);
    when(build.getNumber()).thenReturn(BUILD_NUMBER);

    AbstractProject<?, ?> project = mock(AbstractProject.class);
    when(project.getProperty(GitLabConnectionProperty.class)).thenReturn(new GitLabConnectionProperty(gitLabConnection));
    when(build.getProject()).thenReturn(project);
    return build;
}
 
Example #9
Source File: GitLabMessagePublisherTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
private AbstractBuild mockBuild(String gitLabConnection, Result result, String... remoteUrls) {
    AbstractBuild build = mock(AbstractBuild.class);
    BuildData buildData = mock(BuildData.class);
    when(buildData.getRemoteUrls()).thenReturn(new HashSet<>(Arrays.asList(remoteUrls)));
    when(build.getAction(BuildData.class)).thenReturn(buildData);
    when(build.getResult()).thenReturn(result);
    when(build.getUrl()).thenReturn(BUILD_URL);
    when(build.getResult()).thenReturn(result);
    when(build.getNumber()).thenReturn(BUILD_NUMBER);

    AbstractProject<?, ?> project = mock(AbstractProject.class);
    when(project.getProperty(GitLabConnectionProperty.class)).thenReturn(new GitLabConnectionProperty(gitLabConnection));
    when(build.getProject()).thenReturn(project);
    EnvVars environment = mock(EnvVars.class);
    when(environment.expand(anyString())).thenAnswer(new Answer<String>() {
        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return (String) invocation.getArguments()[0];
        }
    });
    try {
        when(build.getEnvironment(any(TaskListener.class))).thenReturn(environment);
    } catch (IOException | InterruptedException e) {
        throw new RuntimeException(e);
    }
    return build;
}
 
Example #10
Source File: GitLabCommitStatusPublisherTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
private AbstractBuild mockBuild(String gitLabConnection, Result result, String... remoteUrls) {
    AbstractBuild build = mock(AbstractBuild.class);
    List<BuildData> buildDatas = new ArrayList<>();
    BuildData buildData = mock(BuildData.class);
    Revision revision = mock(Revision.class);
    when(revision.getSha1String()).thenReturn(SHA1);
    when(buildData.getLastBuiltRevision()).thenReturn(revision);
    when(buildData.getRemoteUrls()).thenReturn(new HashSet<>(Arrays.asList(remoteUrls)));
    Build gitBuild = mock(Build.class);
    when(gitBuild.getMarked()).thenReturn(revision);
    when(buildData.getLastBuild(any(ObjectId.class))).thenReturn(gitBuild);
    buildDatas.add(buildData);
    when(build.getActions(BuildData.class)).thenReturn(buildDatas);
    when(build.getAction(BuildData.class)).thenReturn(buildData);
    when(build.getResult()).thenReturn(result);
    when(build.getUrl()).thenReturn(BUILD_URL);
    AbstractProject<?, ?> project = mock(AbstractProject.class);
    when(project.getProperty(GitLabConnectionProperty.class)).thenReturn(new GitLabConnectionProperty(gitLabConnection));
    when(build.getProject()).thenReturn(project);
    EnvVars environment = mock(EnvVars.class);
    when(environment.expand(anyString())).thenAnswer(new Answer<String>() {
        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return (String) invocation.getArguments()[0];
        }
    });
    try {
        when(build.getEnvironment(any(TaskListener.class))).thenReturn(environment);
    } catch (IOException | InterruptedException e) {
        throw new RuntimeException(e);
    }
    return build;
}
 
Example #11
Source File: BuildUtil.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
public static Run<?, ?> getBuildBySHA1IncludingMergeBuilds(Job<?, ?> project, String sha1) {
    for (Run<?, ?> build : project.getBuilds()) {
        for(BuildData data : build.getActions(BuildData.class)) {
            if (data != null
                && data.lastBuild != null
                && data.lastBuild.getMarked() != null
                && data.lastBuild.getMarked().getSha1String().equals(sha1)) {
                return build;
            }
        }
    }
    return null;
}
 
Example #12
Source File: BuildUtil.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
public static Run<?, ?> getBuildByBranch(Job<?, ?> project, String branchName) {
    for (Run<?, ?> build : project.getBuilds()) {
        BuildData data = build.getAction(BuildData.class);
        MergeRecord merge = build.getAction(MergeRecord.class);
        if (hasLastBuild(data) && isNoMergeBuild(data, merge)) {    
            for (Branch branch : data.lastBuild.getRevision().getBranches()) {
                if (branch.getName().endsWith("/" + branchName)) {
                    return build;
                }
            }
        }
    }
    return null;
}
 
Example #13
Source File: GitHubPRTriggerTest.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Test
public void checkBuildDataAbsenceAfterBuild() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("test-job");
    p.addProperty(new GithubProjectProperty("https://github.com/KostyaSha/test-repo"));
    p.addTrigger(defaultGitHubPRTrigger());
    p.getBuildersList().add(new BuildDataBuilder());

    GitHubPRCause cause = new GitHubPRCause("headSha", 1, true, "targetBranch", "srcBranch", "[email protected]",
            "title", new URL("http://www.example.com"), "repoOwner", new HashSet<String>(),
            null, false, "nice reason", "author name", "[email protected]", "open");
    FreeStyleBuild build = p.scheduleBuild2(0, cause).get();
    j.waitUntilNoActivity();

    assertTrue(build.getActions(BuildData.class).size() == 0);
}
 
Example #14
Source File: GitHubPRTriggerTest.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Test
public void checkBuildDataExistenceAfterBuild() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("test-job");
    p.getBuildersList().add(new BuildDataBuilder());

    FreeStyleBuild build = p.scheduleBuild2(0).get();
    j.waitUntilNoActivity();

    assertTrue(build.getActions(BuildData.class).size() > 0);
}
 
Example #15
Source File: GitHubPRBuildListener.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Override
public void onCompleted(Run<?, ?> run, @Nonnull TaskListener listener) {
    GitHubPRTrigger trigger = ghPRTriggerFromRun(run);
    if (isNull(trigger)) {
        return;
    }

    GitHubPRCause cause = ghPRCauseFromRun(run);

    if (nonNull(cause)) {
        //remove all BuildData, because it doesn't work right with pull requests now
        //TODO rework after git-client patching about BuildData usage
        run.getActions().removeAll(run.getActions(BuildData.class));
    }
}
 
Example #16
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test
public void getMultiBranchPipelineActivityRuns() throws Exception {
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    scheduleAndFindBranchProject(mp);
    j.waitUntilNoActivity();

    WorkflowJob p = findBranchProject(mp, "master");

    WorkflowRun b1 = p.getLastBuild();
    assertEquals(1, b1.getNumber());
    assertEquals(3, mp.getItems().size());

    //execute feature/ux-1 branch build
    p = findBranchProject(mp, "feature%2Fux-1");
    WorkflowRun b2 = p.getLastBuild();
    assertEquals(1, b2.getNumber());


    //execute feature 2 branch build
    p = findBranchProject(mp, "feature2");
    WorkflowRun b3 = p.getLastBuild();
    assertEquals(1, b3.getNumber());


    List<Map> resp = get("/organizations/jenkins/pipelines/p/runs", List.class);
    Assert.assertEquals(3, resp.size());
    Date d1 = new SimpleDateFormat(DATE_FORMAT_STRING).parse((String)resp.get(0).get("startTime"));
    Date d2 = new SimpleDateFormat(DATE_FORMAT_STRING).parse((String)resp.get(1).get("startTime"));
    Date d3 = new SimpleDateFormat(DATE_FORMAT_STRING).parse((String)resp.get(2).get("startTime"));

    Assert.assertTrue(d1.compareTo(d2) >= 0);
    Assert.assertTrue(d2.compareTo(d3) >= 0);

    for(Map m: resp){
        BuildData d;
        WorkflowRun r;
        if(m.get("pipeline").equals("master")){
            r = b1;
            d = b1.getAction(BuildData.class);
        } else if(m.get("pipeline").equals("feature2")){
            r = b3;
            d = b3.getAction(BuildData.class);
        } else{
            r = b2;
            d = b2.getAction(BuildData.class);
        }
        validateRun(r,m);
        String commitId = "";
        if(d != null) {
            commitId = d.getLastBuiltRevision().getSha1String();
            Assert.assertEquals(commitId, m.get("commitId"));
        }
    }
}
 
Example #17
Source File: BuildUtil.java    From gitlab-plugin with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isNoMergeBuild(BuildData data, MergeRecord merge) {
    return merge == null || merge.getSha1().equals(data.lastBuild.getMarked().getSha1String());
}
 
Example #18
Source File: BuildUtil.java    From gitlab-plugin with GNU General Public License v2.0 4 votes vote down vote up
private static boolean hasLastBuild(BuildData data) {
    return data != null && data.lastBuild != null && data.lastBuild.getRevision() != null;
}
 
Example #19
Source File: CommitStatusUpdater.java    From gitlab-plugin with GNU General Public License v2.0 4 votes vote down vote up
private static List<GitLabBranchBuild> retrieveGitlabProjectIds(Run<?, ?> build, EnvVars environment) {
    LOGGER.log(Level.INFO, "Retrieving gitlab project ids");
    final List<GitLabBranchBuild> result = new ArrayList<>();

    GitLabWebHookCause gitlabCause = build.getCause(GitLabWebHookCause.class);
    if (gitlabCause != null) {
        return Collections.singletonList(new GitLabBranchBuild(
                gitlabCause.getData().getSourceProjectId().toString(), gitlabCause.getData().getLastCommit()));
    }

    // Check upstream causes for GitLabWebHookCause
    List<GitLabBranchBuild> builds = findBuildsFromUpstreamCauses(build.getCauses());
    if (!builds.isEmpty()) {
        return builds;
    }

    final GitLabClient gitLabClient = getClient(build);
    if (gitLabClient == null) {
        LOGGER.log(Level.WARNING, "No gitlab client found.");
        return result;
    }

    final List<BuildData> buildDatas = build.getActions(BuildData.class);
    if (CollectionUtils.isEmpty(buildDatas)) {
        LOGGER.log(Level.INFO, "Build does not contain build data.");
        return result;
    }

    if (buildDatas.size() == 1) {
        addGitLabBranchBuild(result, getBuildRevision(build), buildDatas.get(0).getRemoteUrls(), environment, gitLabClient);
    } else {
        final SCMRevisionAction scmRevisionAction = build.getAction(SCMRevisionAction.class);

        if (scmRevisionAction == null) {
            LOGGER.log(Level.INFO, "Build does not contain SCM revision action.");
            return result;
        }

        final SCMRevision scmRevision = scmRevisionAction.getRevision();

        String scmRevisionHash = null;
        if (scmRevision instanceof AbstractGitSCMSource.SCMRevisionImpl) {
            if (scmRevision == null) {
                LOGGER.log(Level.INFO, "Build does not contain SCM revision object.");
                return result;
            }
            scmRevisionHash = ((AbstractGitSCMSource.SCMRevisionImpl) scmRevision).getHash();

            for (final BuildData buildData : buildDatas) {
                for (final Entry<String, Build> buildByBranchName : buildData.getBuildsByBranchName().entrySet()) {
                    if (buildByBranchName.getValue().getSHA1().equals(ObjectId.fromString(scmRevisionHash))) {
                        addGitLabBranchBuild(result, scmRevisionHash, buildData.getRemoteUrls(), environment, gitLabClient);
                    }
                }
            }
        }
    }

    return result;
}
 
Example #20
Source File: GitLabCommitStatusPublisherTest.java    From gitlab-plugin with GNU General Public License v2.0 4 votes vote down vote up
private AbstractBuild mockBuildWithLibrary(String gitLabConnection, Result result, String... remoteUrls) {
    AbstractBuild build = mock(AbstractBuild.class);
    List<BuildData> buildDatas = new ArrayList<>();
    BuildData buildData = mock(BuildData.class);
    SCMRevisionAction scmRevisionAction = mock(SCMRevisionAction.class);
    AbstractGitSCMSource.SCMRevisionImpl revisionImpl = mock(AbstractGitSCMSource.SCMRevisionImpl.class);
    
    when(build.getAction(SCMRevisionAction.class)).thenReturn(scmRevisionAction);
    when(scmRevisionAction.getRevision()).thenReturn(revisionImpl);
    when(revisionImpl.getHash()).thenReturn(SHA1);
    
    Revision revision = mock(Revision.class);
    when(revision.getSha1String()).thenReturn(SHA1);
    when(buildData.getLastBuiltRevision()).thenReturn(revision);
    when(buildData.getRemoteUrls()).thenReturn(new HashSet<>(Arrays.asList(remoteUrls)));

    Build gitBuild = mock(Build.class);

    when(gitBuild.getMarked()).thenReturn(revision);
    when(gitBuild.getSHA1()).thenReturn(ObjectId.fromString(SHA1));
    when(buildData.getLastBuild(any(ObjectId.class))).thenReturn(gitBuild);
    Map<String, Build> buildsByBranchName = new HashMap<>();
    buildsByBranchName.put("develop", gitBuild);
    when(buildData.getBuildsByBranchName()).thenReturn(buildsByBranchName);
    buildDatas.add(buildData);
    
    //Second build data (@librabry)
    BuildData buildDataLib = mock(BuildData.class);
    Revision revisionLib = mock(Revision.class);
    when(revisionLib.getSha1String()).thenReturn("SHALIB");
    when(buildDataLib.getLastBuiltRevision()).thenReturn(revisionLib);
    Build gitBuildLib = mock(Build.class);
    when(gitBuildLib.getMarked()).thenReturn(revisionLib);
    when(buildDataLib.getLastBuild(any(ObjectId.class))).thenReturn(gitBuildLib);
    buildDatas.add(buildDataLib);
    
    when(build.getActions(BuildData.class)).thenReturn(buildDatas);
    when(build.getResult()).thenReturn(result);
    when(build.getUrl()).thenReturn(BUILD_URL);

    AbstractProject<?, ?> project = mock(AbstractProject.class);
    when(project.getProperty(GitLabConnectionProperty.class)).thenReturn(new GitLabConnectionProperty(gitLabConnection));
    when(build.getProject()).thenReturn(project);
    EnvVars environment = mock(EnvVars.class);
    when(environment.expand(anyString())).thenAnswer(new Answer<String>() {
        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return (String) invocation.getArguments()[0];
        }
    });
    try {
        when(build.getEnvironment(any(TaskListener.class))).thenReturn(environment);
    } catch (IOException | InterruptedException e) {
        throw new RuntimeException(e);
    }
    return build;
}
 
Example #21
Source File: GitHubPRTriggerTest.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) {
    build.addAction(new BuildData());
    return true;
}
 
Example #22
Source File: CommitStatusUpdaterTest.java    From gitlab-plugin with GNU General Public License v2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    PowerMockito.mockStatic(GitLabConnectionProperty.class);
    PowerMockito.mockStatic(Jenkins.class);
    when(Jenkins.getInstance()).thenReturn(jenkins);
       when(Jenkins.getActiveInstance()).thenReturn(jenkins);
    when(jenkins.getRootUrl()).thenReturn(JENKINS_URL);
    when(jenkins.getDescriptor(GitLabConnectionConfig.class)).thenReturn(gitLabConnectionConfig);
    when(GitLabConnectionProperty.getClient(any(Run.class))).thenReturn(client);
    when(gitLabConnectionConfig.getClient(any(String.class), any(Item.class), any(String.class))).thenReturn(client);
       when(connection.getClient()).thenReturn(client);
    when(build.getAction(BuildData.class)).thenReturn(action);
    when(action.getLastBuiltRevision()).thenReturn(lastBuiltRevision);
    when(action.getLastBuild(any(ObjectId.class))).thenReturn(lastBuild);
    when(lastBuild.getMarked()).thenReturn(revision);
    when(revision.getSha1String()).thenReturn(REVISION);
    when(build.getUrl()).thenReturn(BUILD_URL);
    when(build.getEnvironment(any(TaskListener.class))).thenReturn(environment);
    when(build.getCauses()).thenReturn(new ArrayList<Cause>(Collections.singletonList(upCauseLevel1)));
    when(upCauseLevel1.getUpstreamCauses()).thenReturn(new ArrayList<Cause>(Collections.singletonList(upCauseLevel2)));
    when(upCauseLevel2.getUpstreamCauses()).thenReturn(new ArrayList<Cause>(Collections.singletonList(gitlabCause)));
    if(Functions.isWindows()) {
        when(taskListener.getLogger()).thenReturn(new PrintStream("nul"));
    } else {
        when(taskListener.getLogger()).thenReturn(new PrintStream("/dev/null"));
    }


    causeData = causeData()
               .withActionType(CauseData.ActionType.NOTE)
               .withSourceProjectId(PROJECT_ID)
               .withTargetProjectId(PROJECT_ID)
               .withBranch("feature")
               .withSourceBranch("feature")
               .withUserName("")
               .withSourceRepoHomepage("https://gitlab.org/test")
               .withSourceRepoName("test")
               .withSourceNamespace("test-namespace")
               .withSourceRepoUrl("[email protected]:test.git")
               .withSourceRepoSshUrl("[email protected]:test.git")
               .withSourceRepoHttpUrl("https://gitlab.org/test.git")
               .withMergeRequestTitle("Test")
               .withMergeRequestId(1)
               .withMergeRequestIid(1)
               .withTargetBranch("master")
               .withTargetRepoName("test")
               .withTargetNamespace("test-namespace")
               .withTargetRepoSshUrl("[email protected]:test.git")
               .withTargetRepoHttpUrl("https://gitlab.org/test.git")
               .withTriggeredByUser("test")
               .withLastCommit(REVISION)
               .withTargetProjectUrl("https://gitlab.org/test")
               .build();

    when(gitlabCause.getData()).thenReturn(causeData);
    PowerMockito.spy(client);
}