Skip to content

Commit

Permalink
Add pull-request-id as customized build parameter (#65)
Browse files Browse the repository at this point in the history
To be provided from trigger to the rest of the build
so it can be provided to other integrations such as
sonar that requires the pull-request id to delegate
sonar comments to sonar plugins
  • Loading branch information
O5ten authored and meriouma committed Apr 11, 2018
1 parent 13b2048 commit c8e150c
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.arcbees.pullrequest;

import com.google.common.collect.Maps;
import java.io.IOException;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -73,7 +74,6 @@ public PullRequestsTrigger(
public void triggerBuild(@NotNull PolledTriggerContext context) throws BuildTriggerException {
BuildTriggerDescriptor triggerDescriptor = context.getTriggerDescriptor();
Map<String, String> properties = triggerDescriptor.getProperties();

VcsPropertiesHelper vcsPropertiesHelper = new VcsPropertiesHelper(properties, vcsConstants);
String repositoryOwner = vcsPropertiesHelper.getRepositoryOwner();
String repositoryName = vcsPropertiesHelper.getRepositoryName();
Expand Down Expand Up @@ -129,18 +129,24 @@ private boolean addBuildTask(PolledTriggerContext context, List<TriggerTask> tri

boolean added = false;
if (!lastCommit.getHash().equals(lastTriggeredCommitHash)) {
addBuildTask(context, triggerTasks, source);
addBuildTask(context, triggerTasks, pullRequest);
added = true;
}

return added;
}

private void addBuildTask(PolledTriggerContext context, List<TriggerTask> triggerTasks, PullRequestTarget source) {
private void addBuildTask(PolledTriggerContext context, List<TriggerTask> triggerTasks, PullRequest pullRequest) {
PullRequestTarget source = pullRequest.getSource();
BuildTypeEx buildType = (BuildTypeEx) context.getBuildType();

BuildCustomizer buildCustomizer = buildCustomizerFactory.createBuildCustomizer(buildType, null);
buildCustomizer.setCleanSources(true);

Map<String, String> parameters = Maps.newHashMap();
parameters.put("trigger.pullRequestId", String.valueOf(pullRequest.getId()));
buildCustomizer.setParameters(parameters);

BranchEx branch = buildType.getBranchByDisplayName(source.getBranch().getName());
SVcsModification lastModification = checkChanges(source.getCommit().getHash(),
branch.getDummyBuild().getChanges(SelectPrevBuildPolicy.SINCE_NULL_BUILD, true));
Expand Down

0 comments on commit c8e150c

Please sign in to comment.