Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ public class BitbucketSCMSource extends SCMSource {
*/
private String excludes = "";

/**
* If true, branches are included when scanning in the retrieve process.
*/
private boolean scanBranches = true;

/**
* If true, pull requests are included when scanning in the retrieve process.
*/
private boolean scanPullRequests = true;

/**
* If true, a webhook will be auto-registered in the repository managed by this source.
*/
Expand Down Expand Up @@ -213,6 +223,24 @@ public void setExcludes(@NonNull String excludes) {
Pattern.compile(getPattern(excludes));
this.excludes = excludes;
}

@DataBoundSetter
public void setScanBranches(boolean scanBranches) {
this.scanBranches = scanBranches;
}

public boolean getScanBranches() {
return scanBranches;
}

@DataBoundSetter
public void setScanPullRequests(boolean scanPullRequests) {
this.scanPullRequests = scanPullRequests;
}

public boolean getScanPullRequests() {
return scanPullRequests;
}

public String getRepoOwner() {
return repoOwner;
Expand Down Expand Up @@ -304,9 +332,13 @@ protected void retrieve(@CheckForNull SCMSourceCriteria criteria, @NonNull SCMHe
}

// Search branches
retrieveBranches(criteria, observer, listener);
if (getScanBranches()) {
retrieveBranches(criteria, observer, listener);
}
// Search pull requests
retrievePullRequests(criteria, observer, listener);
if (getScanPullRequests()) {
retrievePullRequests(criteria, observer, listener);
}
}

private void retrievePullRequests(SCMSourceCriteria criteria, SCMHeadObserver observer, final TaskListener listener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<f:entry title="${%Exclude branches}" field="excludes">
<f:textbox/>
</f:entry>
<f:entry field="scanBranches">
<f:checkbox title="${%Scan branches}" default="true"/>
</f:entry>
<f:entry field="scanPullRequests">
<f:checkbox title="${%Scan pull requests}" default="true"/>
</f:entry>
<f:entry title="${%Checkout Credentials}" field="checkoutCredentialsId">
<c:select default="${descriptor.SAME}"/>
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout">
<l:ajax>
<div>
<p>
If this option is activated, branches are included for scanning. Deactivate
it if only pull requests should be returned by scanning.
</p>
</div>
</l:ajax>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout">
<l:ajax>
<div>
<p>
If this option is activated, pull requests are included for scanning.
Deactivate it if pull request should should not be returned by scanning.
</p>
</div>
</l:ajax>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,30 @@ public void scanTestPullRequests() throws IOException, InterruptedException {
assertEquals("branch1", observer.getBranches().get(0));
assertEquals("PR-23", observer.getBranches().get(1));
}

@Test
public void scanTestDeactivatedPullRequests() throws IOException, InterruptedException {
BitbucketSCMSource source = getBitbucketSCMSourceMock(RepositoryType.GIT, true);
source.setScanPullRequests(false);
SCMHeadObserverImpl observer = new SCMHeadObserverImpl();
source.fetch(observer, BitbucketClientMockUtils.getTaskListenerMock());

// Only branch1 must be observed
assertEquals(1, observer.getBranches().size());
assertEquals("branch1", observer.getBranches().get(0));
}

@Test
public void scanTestDeactivatedBranches() throws IOException, InterruptedException {
BitbucketSCMSource source = getBitbucketSCMSourceMock(RepositoryType.GIT, true);
source.setScanBranches(false);
SCMHeadObserverImpl observer = new SCMHeadObserverImpl();
source.fetch(observer, BitbucketClientMockUtils.getTaskListenerMock());

// Only my-feature-branch PR must be observed
assertEquals(1, observer.getBranches().size());
assertEquals("PR-23", observer.getBranches().get(0));
}

@Test
public void gitSCMTest() {
Expand Down