Skip to content
Draft
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
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>4.3.0-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.model.Item;
import hudson.model.Queue;
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.GithubWeb;
import hudson.plugins.git.extensions.GitSCMChangelogExtension;
import hudson.security.ACL;

import java.io.IOException;
import java.net.URL;
import java.util.HashSet;
import java.util.Random;
Expand All @@ -51,6 +58,8 @@
import org.apache.commons.lang.StringUtils;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.transport.RefSpec;
import org.jenkinsci.plugins.gitclient.ChangelogCommand;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.github.config.GitHubServerConfig;

/**
Expand Down Expand Up @@ -339,6 +348,7 @@ public GitSCM build() {
if (r instanceof PullRequestSCMRevision) {
PullRequestSCMRevision rev = (PullRequestSCMRevision) r;
withRevision(new AbstractGitSCMSource.SCMRevisionImpl(head, rev.getPullHash()));
withExtension(new GitSCMPullRequestChangelogExtension(rev.getBaseHash()));
}
}
return super.build();
Expand All @@ -347,4 +357,22 @@ public GitSCM build() {
withRevision(r);
}
}

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

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

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;
}
}
}