From 31f8039a32e1bfe53234e3715bb2f6c6a45b5af2 Mon Sep 17 00:00:00 2001 From: Michal Slusarczyk Date: Wed, 19 Apr 2017 11:53:25 +0200 Subject: [PATCH] [JENKINS-40652] origin pr builds not treated as trusted - regression fix for private repos origin PRs --- .../plugins/github_branch_source/GitHubSCMSource.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java index 29d6d20fa..f9ef4f9d8 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java @@ -619,8 +619,7 @@ private void doRetrieve(SCMSourceCriteria criteria, SCMHeadObserver observer, Ta } continue; } - boolean trusted = collaboratorNames != null - && collaboratorNames.contains(ghPullRequest.getHead().getRepository().getOwnerName()); + boolean trusted = isTrusted(ghPullRequest, collaboratorNames); if (!trusted) { listener.getLogger().format(" (not from a trusted source)%n"); } @@ -807,6 +806,13 @@ private void doRetrieve(SCMSourceCriteria criteria, SCMHeadObserver observer, Ta } } + private boolean isTrusted(GHPullRequest ghPullRequest, Collection collaboratorNames) { + String prUserLogin = ghPullRequest.getUser().getLogin(); + String prRepoOwner = ghPullRequest.getHead().getRepository().getOwnerName(); + return collaboratorNames != null + && (collaboratorNames.contains(prRepoOwner) || collaboratorNames.contains(prUserLogin)); + } + /** * {@inheritDoc} */