Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>4.3.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Util;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.plugins.git.GitException;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.Revision;
import hudson.plugins.git.browser.BitbucketWeb;
import hudson.plugins.git.extensions.GitSCMChangelogExtension;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -53,6 +60,8 @@
import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy;
import jenkins.scm.api.mixin.TagSCMHead;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.gitclient.ChangelogCommand;
import org.jenkinsci.plugins.gitclient.GitClient;

/**
* A {@link GitSCMBuilder} specialized for bitbucket.
Expand Down Expand Up @@ -264,17 +273,41 @@ public BitbucketGitSCMBuilder withBitbucketRemote() {
"+refs/heads/" + name + ":refs/remotes/@{remote}/" + localName);
if ((r instanceof PullRequestSCMRevision)
&& ((PullRequestSCMRevision) r).getTarget() instanceof AbstractGitSCMSource.SCMRevisionImpl) {
String targetHash = ((AbstractGitSCMSource.SCMRevisionImpl) ((PullRequestSCMRevision) r).getTarget())
.getHash();
withExtension(new GitSCMPullRequestChangelogExtension(targetHash));
withExtension(new MergeWithGitSCMExtension("remotes/" + remoteName + "/" + localName,
((AbstractGitSCMSource.SCMRevisionImpl) ((PullRequestSCMRevision) r).getTarget())
.getHash()));
} else {
withExtension(new MergeWithGitSCMExtension("remotes/" + remoteName + "/" + localName, null));
}
}
// else head.getCheckoutStrategy() != ChangeRequestCheckoutStrategy.MERGE)
// TODO Compute changelog of change request without target
}
return this;
}

/**
* Compute changelog of pull request.
*/
static final class GitSCMPullRequestChangelogExtension extends GitSCMChangelogExtension {
final String targetHash;

public GitSCMPullRequestChangelogExtension(String targetHash) {
this.targetHash = targetHash;
}

@Override
public boolean decorateChangelogCommand(GitSCM gitSCM, Run<?, ?> run, GitClient git, TaskListener taskListener, ChangelogCommand cmd, Revision revToBuild) throws IOException, InterruptedException, GitException {
taskListener.getLogger().println("Using 'Changelog for PullRequest' strategy.");
cmd.includes(revToBuild.getSha1());
cmd.excludes(targetHash);
return true;
}
}

/**
* {@inheritDoc}
*/
Expand Down