Skip to content
Permalink
Browse files
[JENKINS-41453] sourceOwner != pull request user and add ContributorM…
…etadataAction for PRs
  • Loading branch information
stephenc committed Jan 26, 2017
1 parent 1e6f8f6 commit e05ea33fe7e1ffdd02911c9b284d1fff5f48addf
@@ -75,6 +75,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.SSLHandshakeException;
import jenkins.management.ConfigureLink;
import jenkins.plugins.git.AbstractGitSCMSource;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMHeadCategory;
@@ -86,6 +87,7 @@
import jenkins.scm.api.SCMSourceDescriptor;
import jenkins.scm.api.SCMSourceEvent;
import jenkins.scm.api.SCMSourceOwner;
import jenkins.scm.api.metadata.ContributorMetadataAction;
import jenkins.scm.api.metadata.ObjectMetadataAction;
import jenkins.scm.api.metadata.PrimaryInstanceMetadataAction;
import jenkins.scm.impl.ChangeRequestSCMHeadCategory;
@@ -181,6 +183,11 @@
*/
@NonNull
private transient /*effectively final*/ Map<Integer,ObjectMetadataAction> pullRequestMetadataCache;
/**
* The cache of {@link ObjectMetadataAction} instances for each open PR.
*/
@NonNull
private transient /*effectively final*/ Map<Integer,ContributorMetadataAction> pullRequestContributorCache;

@DataBoundConstructor
public GitHubSCMSource(String id, String apiUri, String checkoutCredentialsId, String scanCredentialsId, String repoOwner, String repository) {
@@ -217,6 +224,9 @@ private Object readResolve() {
if (pullRequestMetadataCache == null) {
pullRequestMetadataCache = new ConcurrentHashMap<>();
}
if (pullRequestContributorCache == null) {
pullRequestContributorCache = new ConcurrentHashMap<>();
}
return this;
}

@@ -603,6 +613,12 @@ private void doRetrieve(SCMSourceCriteria criteria, SCMHeadObserver observer, Ta
ghPullRequest.getHtmlUrl().toExternalForm()
)
);
GHUser user = ghPullRequest.getUser();
pullRequestContributorCache.put(number, new ContributorMetadataAction(
user.getLogin(),
user.getName(),
user.getEmail()
));
pullRequestMetadataKeys.add(number);
PullRequestSCMHead head = new PullRequestSCMHead(ghPullRequest, branchName, merge);
if (includes != null && !includes.contains(head)) {
@@ -649,6 +665,7 @@ private void doRetrieve(SCMSourceCriteria criteria, SCMHeadObserver observer, Ta
if (includes == null) {
// we did a full scan, so trim the cache entries
this.pullRequestMetadataCache.keySet().retainAll(pullRequestMetadataKeys);
this.pullRequestContributorCache.keySet().retainAll(pullRequestMetadataKeys);
}
}

@@ -1078,12 +1095,17 @@ protected boolean isCategoryEnabled(@NonNull SCMHeadCategory category) {
ObjectMetadataAction metadataAction = null;
if (head instanceof PullRequestSCMHead) {
// pull request to this repository
url = repoLink.getUrl() + "/pull/" + ((PullRequestSCMHead) head).getNumber();
metadataAction = pullRequestMetadataCache.get(((PullRequestSCMHead) head).getNumber());
int number = ((PullRequestSCMHead) head).getNumber();
url = repoLink.getUrl() + "/pull/" + number;
metadataAction = pullRequestMetadataCache.get(number);
if (metadataAction == null) {
// best effort
metadataAction = new ObjectMetadataAction(null, null, url);
}
ContributorMetadataAction contributor = pullRequestContributorCache.get(number);
if (contributor != null) {
result.add(contributor);
}
} else {
// branch in this repository
url = repoLink.getUrl() + "/tree/" + head.getName();
@@ -106,7 +106,7 @@ private Object readResolve() {
merge,
metadata.getNumber(),
new BranchSCMHead(metadata.getBaseRef()),
metadata.getUserLogin(),
null,
null,
null
);

0 comments on commit e05ea33

Please sign in to comment.