Skip to content

Commit 258264e

Browse files
committed
Cleanup code
1 parent bb4300a commit 258264e

File tree

6 files changed

+26
-24
lines changed

6 files changed

+26
-24
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ private void withPullRequestRemote(PullRequestSCMHead head, String headName) {
224224
&& revision instanceof PullRequestSCMRevision;
225225
String targetBranch = head.getTarget().getName();
226226
String branchName = head.getBranchName();
227+
boolean scmCloud = BitbucketApiUtils.isCloud(scmSource.getServerUrl());
227228
if (prFromTargetRepository) {
228229
withRefSpec("+refs/heads/" + branchName + ":refs/remotes/@{remote}/" + branchName);
229230
if (cloneFromMirror) {
@@ -247,7 +248,7 @@ private void withPullRequestRemote(PullRequestSCMHead head, String headName) {
247248
withPrimaryRemote();
248249
}
249250
} else {
250-
if (scmSource.isCloud()) {
251+
if (scmCloud) {
251252
withRefSpec("+refs/heads/" + branchName + ":refs/remotes/@{remote}/" + headName);
252253
String cloneLink = getCloudRepositoryUri(pullRequestRepoOwner, pullRequestRepository);
253254
withRemote(cloneLink);
@@ -260,7 +261,7 @@ private void withPullRequestRemote(PullRequestSCMHead head, String headName) {
260261
if (head.getCheckoutStrategy() == ChangeRequestCheckoutStrategy.MERGE) {
261262
String hash = revision instanceof PullRequestSCMRevision prRevision ? prRevision.getTargetImpl().getHash() : null;
262263
String refSpec = "+refs/heads/" + targetBranch + ":refs/remotes/@{remote}/" + targetBranch;
263-
if (!prFromTargetRepository && scmSource.isCloud()) {
264+
if (!prFromTargetRepository && scmCloud) {
264265
String upstreamRemoteName = remoteName().equals("upstream") ? "upstream-upstream" : "upstream";
265266
withAdditionalRemote(upstreamRemoteName, getCloneLink(primaryCloneLinks), refSpec);
266267
withExtension(new MergeWithGitSCMExtension("remotes/" + upstreamRemoteName + "/" + targetBranch, hash));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public List<Action> retrieveActions(@NonNull SCMNavigatorOwner owner,
345345
}
346346

347347
private boolean showAvatar() {
348-
return traits.stream().anyMatch(ShowBitbucketAvatarTrait.class::isInstance);
348+
return SCMTrait.find(traits, ShowBitbucketAvatarTrait.class) != null;
349349
}
350350

351351
@Symbol("bitbucket")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public Collection<BitbucketRepository> repositories() {
7979
.filter(BitbucketSCMSource.class::isInstance)
8080
.map(BitbucketSCMSource.class::cast)
8181
.map(BitbucketSCMSource::getRepository)
82-
.collect(Collectors.toList());
82+
.toList();
8383
// process new repositories first
8484
final Set<BitbucketRepository> newRepositories = this.repositoryMap.entrySet()
8585
.stream()

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ private void retrievePullRequests(final BitbucketSCMSourceRequest request) throw
439439
class Skip extends IOException {
440440
}
441441

442-
final BitbucketApi originBitbucket = buildBitbucketClient();
443-
if (request.isSkipPublicPRs() && !originBitbucket.isPrivate()) {
442+
final BitbucketApi originClient = buildBitbucketClient();
443+
if (request.isSkipPublicPRs() && !originClient.isPrivate()) {
444444
request.listener().getLogger().printf("Skipping pull requests for %s (public repository)%n", fullName);
445445
return;
446446
}
@@ -460,15 +460,15 @@ class Skip extends IOException {
460460
boolean fork = !StringUtils.equalsIgnoreCase(fullName, pull.getSource().getRepository().getFullName());
461461
String pullRepoOwner = pull.getSource().getRepository().getOwnerName();
462462
String pullRepository = pull.getSource().getRepository().getRepositoryName();
463-
final BitbucketApi client = fork && BitbucketApiUtils.isCloud(originBitbucket)
463+
final BitbucketApi client = fork && BitbucketApiUtils.isCloud(originClient)
464464
? BitbucketApiFactory.newInstance(
465465
getServerUrl(),
466466
authenticator(),
467467
pullRepoOwner,
468468
null,
469469
pullRepository
470470
)
471-
: originBitbucket;
471+
: originClient;
472472
count++;
473473
livePRs.add(pull.getId());
474474
getPullRequestTitleCache()
@@ -507,7 +507,7 @@ public SCMRevision create(@NonNull SCMHead head, @Nullable BitbucketCommit sourc
507507
BranchHeadCommit targetCommit = new BranchHeadCommit(pull.getDestination().getBranch());
508508
return super.create(head, sourceCommit, targetCommit);
509509
} catch (BitbucketRequestException e) {
510-
if (originBitbucket instanceof BitbucketCloudApiClient) {
510+
if (BitbucketApiUtils.isCloud(originClient)) {
511511
if (e.getHttpCode() == 403) {
512512
request.listener().getLogger().printf( //
513513
"Skipping %s because of %s%n", //
@@ -555,15 +555,15 @@ private void retrieveBranches(final BitbucketSCMSourceRequest request)
555555
String fullName = repoOwner + "/" + repository;
556556
request.listener().getLogger().println("Looking up " + fullName + " for branches");
557557

558-
final BitbucketApi bitbucket = buildBitbucketClient();
558+
final BitbucketApi client = buildBitbucketClient();
559559
int count = 0;
560560
for (final BitbucketBranch branch : request.getBranches()) {
561561
request.listener().getLogger().println("Checking branch " + branch.getName() + " from " + fullName);
562562
count++;
563563
if (request.process(new BranchSCMHead(branch.getName()), //
564564
(IntermediateLambda<BitbucketCommit>) () -> new BranchHeadCommit(branch), //
565-
new BitbucketProbeFactory<>(bitbucket, request), //
566-
new BitbucketRevisionFactory<>(bitbucket), //
565+
new BitbucketProbeFactory<>(client, request), //
566+
new BitbucketRevisionFactory<>(client), //
567567
new CriteriaWitness(request))) {
568568
request.listener().getLogger().format("%n %d branches were processed (query completed)%n", count);
569569
return;
@@ -596,16 +596,16 @@ private void retrieveTags(final BitbucketSCMSourceRequest request) throws IOExce
596596

597597
@Override
598598
protected SCMRevision retrieve(SCMHead head, TaskListener listener) throws IOException, InterruptedException {
599-
final BitbucketApi bitbucket = buildBitbucketClient();
599+
final BitbucketApi client = buildBitbucketClient();
600600
try {
601601
if (head instanceof PullRequestSCMHead prHead) {
602602
BitbucketCommit sourceRevision;
603603
BitbucketCommit targetRevision;
604604

605-
if (bitbucket instanceof BitbucketCloudApiClient) {
605+
if (BitbucketApiUtils.isCloud(client)) {
606606
// Bitbucket Cloud /pullrequests/{id} API endpoint only returns short commit IDs of the source
607607
// and target branch. We therefore retrieve the branches directly
608-
BitbucketBranch targetBranch = bitbucket.getBranch(prHead.getTarget().getName());
608+
BitbucketBranch targetBranch = client.getBranch(prHead.getTarget().getName());
609609

610610
if(targetBranch == null) {
611611
listener.getLogger().format("No branch found in {0}/{1} with name [{2}]",
@@ -623,7 +623,7 @@ protected SCMRevision retrieve(SCMHead head, TaskListener listener) throws IOExc
623623
// Retrieve the source branch commit
624624
BitbucketBranch branch;
625625
if (head.getOrigin() == SCMHeadOrigin.DEFAULT) {
626-
branch = bitbucket.getBranch(prHead.getBranchName());
626+
branch = client.getBranch(prHead.getBranchName());
627627
} else {
628628
// In case of a forked branch, retrieve the branch as that owner
629629
branch = buildBitbucketClient(prHead).getBranch(prHead.getBranchName());
@@ -640,7 +640,7 @@ protected SCMRevision retrieve(SCMHead head, TaskListener listener) throws IOExc
640640
} else {
641641
BitbucketPullRequest pr;
642642
try {
643-
pr = bitbucket.getPullRequestById(Integer.parseInt(prHead.getId()));
643+
pr = client.getPullRequestById(Integer.parseInt(prHead.getId()));
644644
} catch (NumberFormatException nfe) {
645645
LOGGER.log(Level.WARNING, "Cannot parse the PR id {0}", prHead.getId());
646646
return null;
@@ -672,7 +672,7 @@ protected SCMRevision retrieve(SCMHead head, TaskListener listener) throws IOExc
672672
new BitbucketGitSCMRevision(prHead, sourceRevision)
673673
);
674674
} else if (head instanceof BitbucketTagSCMHead tagHead) {
675-
BitbucketBranch tag = bitbucket.getTag(tagHead.getName());
675+
BitbucketBranch tag = client.getTag(tagHead.getName());
676676
if(tag == null) {
677677
listener.getLogger().format( "No tag found in {0}/{1} with name [{2}]",
678678
repoOwner, repository, head.getName());
@@ -686,7 +686,7 @@ protected SCMRevision retrieve(SCMHead head, TaskListener listener) throws IOExc
686686
}
687687
return new BitbucketTagSCMRevision(tagHead, revision);
688688
} else {
689-
BitbucketBranch branch = bitbucket.getBranch(head.getName());
689+
BitbucketBranch branch = client.getBranch(head.getName());
690690
if(branch == null) {
691691
listener.getLogger().format("No branch found in {0}/{1} with name [{2}]",
692692
repoOwner, repository, head.getName());
@@ -1093,8 +1093,9 @@ private List<BitbucketHref> getCloneLinksFromPrimary(BitbucketApi bitbucket) thr
10931093
return cloneLinksLocal;
10941094
}
10951095

1096+
@Deprecated(since = "936.0.0", forRemoval = true)
10961097
public boolean isCloud() {
1097-
return BitbucketCloudEndpoint.SERVER_URL.equals(serverUrl);
1098+
return BitbucketApiUtils.isCloud(serverUrl);
10981099
}
10991100

11001101
@Symbol("bitbucket")

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/endpoints/AbstractBitbucketEndpointDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public ListBoxModel doFillCredentialsIdItems(@QueryParameter String serverUrl) {
5959
jenkins.checkPermission(Jenkins.MANAGE);
6060
StandardListBoxModel result = new StandardListBoxModel();
6161
result.includeMatchingAs(
62-
ACL.SYSTEM,
62+
ACL.SYSTEM2,
6363
jenkins,
6464
StandardCredentials.class,
6565
URIRequirementBuilder.fromUri(serverUrl).build(),

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/notifier/BitbucketBuildStatusNotifications.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ private static String getRootURL(@NonNull Run<?, ?> build) {
8686
* Throws an IllegalStateException if it is not valid, or return the url otherwise
8787
*
8888
* @param url the URL of the build to check
89-
* @param bitbucket the bitbucket client we are facing.
89+
* @param client the bitbucket client we are facing.
9090
*/
91-
static String checkURL(@NonNull String url, BitbucketApi bitbucket) {
91+
static String checkURL(@NonNull String url, BitbucketApi client) {
9292
try {
9393
URL anURL = new URL(url);
9494
if ("localhost".equals(anURL.getHost())) {
@@ -97,7 +97,7 @@ static String checkURL(@NonNull String url, BitbucketApi bitbucket) {
9797
if ("unconfigured-jenkins-location".equals(anURL.getHost())) {
9898
throw new IllegalStateException("Could not determine Jenkins URL.");
9999
}
100-
if (bitbucket instanceof BitbucketCloudApiClient && !anURL.getHost().contains(".")) {
100+
if (BitbucketApiUtils.isCloud(client) && !anURL.getHost().contains(".")) {
101101
throw new IllegalStateException(
102102
"Please use a fully qualified name or an IP address for Jenkins URL, this is required by Bitbucket cloud");
103103
}

0 commit comments

Comments
 (0)