Skip to content

Commit 494f18a

Browse files
authored
[JENKINS-74980] Pull requests are no longer fetchable (#989)
Restore the comparison of the owner name in Bitbucket Server to be case insensitive.
1 parent 156beeb commit 494f18a

25 files changed

+150
-195
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketGitSCMBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ private void withPullRequestRemote(PullRequestSCMHead head, String headName) {
214214
String scmSourceRepository = scmSource.getRepository();
215215
String pullRequestRepoOwner = head.getRepoOwner();
216216
String pullRequestRepository = head.getRepository();
217-
boolean prFromTargetRepository = pullRequestRepoOwner.equalsIgnoreCase(scmSourceRepoOwner)
217+
boolean prFromTargetRepository = StringUtils.equalsIgnoreCase(pullRequestRepoOwner, scmSourceRepoOwner)
218218
&& pullRequestRepository.equalsIgnoreCase(scmSourceRepository);
219219
SCMRevision revision = revision();
220220
ChangeRequestCheckoutStrategy checkoutStrategy = head.getCheckoutStrategy();

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMNavigator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ public void visitSources(SCMSourceObserver observer) throws IOException, Interru
513513
listener.getLogger()
514514
.format("Connecting to %s using %s%n", serverUrl, CredentialsNameProvider.name(credentials));
515515
}
516-
try (final BitbucketSCMNavigatorRequest request = new BitbucketSCMNavigatorContext().withTraits(traits)
516+
try (final BitbucketSCMNavigatorRequest request = new BitbucketSCMNavigatorContext()
517+
.withTraits(traits)
517518
.newRequest(this, observer)) {
518519
SourceFactory sourceFactory = new SourceFactory(request);
519520
WitnessImpl witness = new WitnessImpl(request, listener);

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public void setServerUrl(@CheckForNull String serverUrl) {
373373
}
374374

375375
@NonNull
376-
public String getEndpointJenkinsRootUrl() {
376+
public String getEndpointJenkinsRootURL() {
377377
return AbstractBitbucketEndpoint.getEndpointJenkinsRootUrl(serverUrl);
378378
}
379379

@@ -692,10 +692,10 @@ class Skip extends IOException {
692692
pull.getSource().getRepository().getFullName(),
693693
originalBranchName
694694
);
695-
boolean fork = !fullName.equalsIgnoreCase(pull.getSource().getRepository().getFullName());
695+
boolean fork = !StringUtils.equalsIgnoreCase(fullName, pull.getSource().getRepository().getFullName());
696696
String pullRepoOwner = pull.getSource().getRepository().getOwnerName();
697697
String pullRepository = pull.getSource().getRepository().getRepositoryName();
698-
final BitbucketApi pullBitbucket = fork && BitbucketApiUtils.isCloud(originBitbucket)
698+
final BitbucketApi client = fork && BitbucketApiUtils.isCloud(originBitbucket)
699699
? BitbucketApiFactory.newInstance(
700700
getServerUrl(),
701701
authenticator(),
@@ -731,8 +731,8 @@ class Skip extends IOException {
731731
// use branch instead of commit to postpone closure initialisation
732732
return new BranchHeadCommit(pull.getSource().getBranch());
733733
}, //
734-
new BitbucketProbeFactory<>(pullBitbucket, request), //
735-
new BitbucketRevisionFactory<BitbucketCommit>(pullBitbucket) {
734+
new BitbucketProbeFactory<>(client, request), //
735+
new BitbucketRevisionFactory<BitbucketCommit>(client) {
736736
@NonNull
737737
@Override
738738
public SCMRevision create(@NonNull SCMHead head, @Nullable BitbucketCommit sourceCommit)
@@ -1172,7 +1172,7 @@ protected List<Action> retrieveActions(@NonNull SCMHead head,
11721172
SCMSourceOwner owner = getOwner();
11731173
if (owner instanceof Actionable actionable) {
11741174
for (BitbucketDefaultBranch p : actionable.getActions(BitbucketDefaultBranch.class)) {
1175-
if (StringUtils.equals(getRepoOwner(), p.getRepoOwner())
1175+
if (StringUtils.equalsIgnoreCase(getRepoOwner(), p.getRepoOwner())
11761176
&& StringUtils.equals(repository, p.getRepository())
11771177
&& StringUtils.equals(p.getDefaultBranch(), head.getName())) {
11781178
result.add(new PrimaryInstanceMetadataAction());
@@ -1202,7 +1202,7 @@ private synchronized Map<String, ContributorMetadataAction> getPullRequestContri
12021202
@NonNull
12031203
public SCMHeadOrigin originOf(@NonNull String repoOwner, @NonNull String repository) {
12041204
if (this.repository.equalsIgnoreCase(repository)) {
1205-
if (this.repoOwner.equalsIgnoreCase(repoOwner)) {
1205+
if (StringUtils.equalsIgnoreCase(this.repoOwner, repoOwner)) {
12061206
return SCMHeadOrigin.DEFAULT;
12071207
}
12081208
return new SCMHeadOrigin.Fork(repoOwner);

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BranchDiscoveryTrait.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import jenkins.scm.api.trait.SCMSourceTrait;
4242
import jenkins.scm.api.trait.SCMSourceTraitDescriptor;
4343
import jenkins.scm.impl.trait.Discovery;
44+
import org.apache.commons.lang.StringUtils;
4445
import org.jenkinsci.Symbol;
4546
import org.kohsuke.accmod.Restricted;
4647
import org.kohsuke.accmod.restrictions.NoExternalUse;
@@ -243,7 +244,7 @@ public boolean isExcluded(@NonNull SCMSourceRequest request, @NonNull SCMHead he
243244
String fullName = req.getRepoOwner() + "/" + req.getRepository();
244245
for (BitbucketPullRequest pullRequest : req.getPullRequests()) {
245246
BitbucketRepository source = pullRequest.getSource().getRepository();
246-
if (fullName.equalsIgnoreCase(source.getFullName())
247+
if (StringUtils.equalsIgnoreCase(fullName, source.getFullName())
247248
&& pullRequest.getSource().getBranch().getName().equals(head.getName())) {
248249
request.listener().getLogger().println("Discard branch " + head.getName()
249250
+ " because current strategy excludes branches that are also filed as a pull request");

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/ForkPullRequestDiscoveryTrait.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import jenkins.scm.api.trait.SCMSourceTraitDescriptor;
4444
import jenkins.scm.impl.ChangeRequestSCMHeadCategory;
4545
import jenkins.scm.impl.trait.Discovery;
46+
import org.apache.commons.lang.StringUtils;
4647
import org.jenkinsci.Symbol;
4748
import org.kohsuke.accmod.Restricted;
4849
import org.kohsuke.accmod.restrictions.NoExternalUse;
@@ -301,7 +302,7 @@ public TrustTeamForks() {
301302
protected boolean checkTrusted(@NonNull BitbucketSCMSourceRequest request, @NonNull PullRequestSCMHead head)
302303
throws IOException, InterruptedException {
303304
if (!head.getOrigin().equals(SCMHeadOrigin.DEFAULT)) {
304-
return head.getRepoOwner().equalsIgnoreCase(request.getRepoOwner());
305+
return StringUtils.equalsIgnoreCase(head.getRepoOwner(), request.getRepoOwner());
305306
}
306307
return false;
307308
}

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/BitbucketCloudApiClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import org.apache.commons.lang.StringUtils;
7676
import org.apache.http.HttpHost;
7777
import org.apache.http.HttpStatus;
78+
import org.apache.http.client.methods.HttpHead;
7879
import org.apache.http.config.SocketConfig;
7980
import org.apache.http.conn.HttpClientConnectionManager;
8081
import org.apache.http.impl.client.CloseableHttpClient;
@@ -344,7 +345,7 @@ public boolean checkPathExists(@NonNull String branchOrHash, @NonNull String pat
344345
.set("branchOrHash", branchOrHash)
345346
.set("path", path.split(Operator.PATH.getSeparator()))
346347
.expand();
347-
int status = headRequestStatus(url);
348+
int status = headRequestStatus(new HttpHead(url));
348349
if (HttpStatus.SC_OK == status) {
349350
return true;
350351
} else if (HttpStatus.SC_NOT_FOUND == status) {

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEvent.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private void reconstructMissingData() {
7676
sourceRepository.setScm(repository.getScm());
7777
}
7878
if (sourceRepository.getOwner() == null) {
79-
if (!sourceRepository.getOwnerName().equals(repository.getOwnerName())) { // i.e., a fork
79+
if (!StringUtils.equalsIgnoreCase(sourceRepository.getOwnerName(), repository.getOwnerName())) { // i.e., a fork
8080
BitbucketCloudRepositoryOwner owner = new BitbucketCloudRepositoryOwner();
8181
owner.setUsername(sourceRepository.getOwnerName());
8282
owner.setDisplayName(this.pullRequest.getAuthorLogin());
@@ -111,8 +111,7 @@ private void reconstructMissingData() {
111111
destination.getRepository().setScm(repository.getScm());
112112
}
113113
if (destination.getRepository().getOwner() == null
114-
&& destination.getRepository().getOwnerName()
115-
.equals(repository.getOwnerName())) {
114+
&& StringUtils.equalsIgnoreCase(destination.getRepository().getOwnerName(), repository.getOwnerName())) {
116115
destination.getRepository().setOwner(repository.getOwner());
117116
destination.getRepository().setPrivate(repository.isPrivate());
118117
}

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import jenkins.scm.api.SCMSource;
5757
import jenkins.scm.api.SCMSourceDescriptor;
5858
import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy;
59+
import org.apache.commons.lang.StringUtils;
5960

6061
public class BitbucketSCMFileSystem extends SCMFileSystem {
6162

@@ -163,7 +164,7 @@ public SCMFileSystem build(@NonNull SCMSource source, @NonNull SCMHead head, @Ch
163164
if (BitbucketApiUtils.isCloud(apiClient)) {
164165
// support lightweight checkout for branches with same owner and repository
165166
if (prHead.getCheckoutStrategy() == ChangeRequestCheckoutStrategy.HEAD &&
166-
prHead.getRepoOwner().equals(src.getRepoOwner()) &&
167+
StringUtils.equalsIgnoreCase(prHead.getRepoOwner(), src.getRepoOwner()) &&
167168
prHead.getRepository().equals(src.getRepository())) {
168169
ref = prHead.getOriginName();
169170
} else {

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/AbstractSCMHeadEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public boolean isMatch(@NonNull SCMNavigator navigator) {
5858
if (!isServerURLMatch(bbNav.getServerUrl())) {
5959
return false;
6060
}
61-
return bbNav.getRepoOwner().equalsIgnoreCase(getRepository().getOwnerName());
61+
return StringUtils.equalsIgnoreCase(bbNav.getRepoOwner(), getRepository().getOwnerName());
6262
}
6363

6464
protected abstract BitbucketRepository getRepository();

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/BitbucketSCMSourcePushHookReceiver.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public class BitbucketSCMSourcePushHookReceiver extends CrumbExclusion implement
5353
public static final String FULL_PATH = PATH + "/notify";
5454

5555
@Override
56-
public boolean process(HttpServletRequest req, HttpServletResponse resp, FilterChain chain)
57-
throws IOException, ServletException {
56+
public boolean process(HttpServletRequest req, HttpServletResponse resp, FilterChain chain) throws IOException, ServletException {
5857
String pathInfo = req.getPathInfo();
5958
if (pathInfo != null && pathInfo.startsWith("/"+FULL_PATH)) {
6059
chain.doFilter(req, resp);

0 commit comments

Comments
 (0)