-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Using larger page size for open PR searches * Using PR commit stream instead of list
- Loading branch information
1 parent
c95323a
commit 99d3f6d
Showing
2 changed files
with
46 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package com.monitorjbl.plugins; | ||
|
||
import com.atlassian.bitbucket.build.BuildStatusSetEvent; | ||
import com.atlassian.bitbucket.commit.Commit; | ||
import com.atlassian.bitbucket.event.pull.PullRequestParticipantStatusUpdatedEvent; | ||
import com.atlassian.bitbucket.permission.Permission; | ||
import com.atlassian.bitbucket.pull.PullRequest; | ||
|
@@ -12,18 +11,21 @@ | |
import com.atlassian.bitbucket.repository.Repository; | ||
import com.atlassian.bitbucket.user.SecurityService; | ||
import com.atlassian.bitbucket.util.Page; | ||
import com.atlassian.bitbucket.util.PageRequest; | ||
import com.atlassian.bitbucket.util.PageRequestImpl; | ||
import com.atlassian.event.api.EventListener; | ||
import com.monitorjbl.plugins.AsyncProcessor.TaskProcessor; | ||
import com.monitorjbl.plugins.config.Config; | ||
import com.monitorjbl.plugins.config.ConfigDao; | ||
|
||
import java.io.Serializable; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
public class PullRequestListener { | ||
private static final String PR_APPROVE_BUCKET = "AUTOMERGE_PR_APPROVAL"; | ||
private static final String BUILD_APPROVE_BUCKET = "AUTOMERGE_BUILD_APPROVAL"; | ||
public static final int MAX_COMMITS = 1048576; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
public static final int SEARCH_PAGE_SIZE = 50; | ||
|
||
private final AsyncProcessor asyncProcessor; | ||
private final ConfigDao configDao; | ||
|
@@ -69,21 +71,33 @@ void automergePullRequest(PullRequest pr) { | |
} | ||
|
||
PullRequest findPRByCommitId(String commitId) { | ||
int start = 0; | ||
Page<PullRequest> requests = null; | ||
while(requests == null || requests.getSize() > 0) { | ||
requests = prService.search(new PullRequestSearchRequest.Builder() | ||
.state(PullRequestState.OPEN) | ||
.build(), new PageRequestImpl(start, 10)); | ||
for(PullRequest pr : requests.getValues()) { | ||
Page<Commit> commits = prService.getCommits(pr.getToRef().getRepository().getId(), pr.getId(), new PageRequestImpl(0, MAX_COMMITS)); | ||
for(Commit c : commits.getValues()) { | ||
if(c.getId().equals(commitId)) { | ||
return pr; | ||
} | ||
} | ||
PullRequestSearchRequest request = new PullRequestSearchRequest.Builder() | ||
.state(PullRequestState.OPEN) | ||
.withProperties(false) | ||
.build(); | ||
PageRequest nextPage = new PageRequestImpl(0, SEARCH_PAGE_SIZE); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
do { | ||
Page<PullRequest> page = prService.search(request, nextPage); | ||
PullRequest pr = searchForPR(page, commitId); | ||
if(pr != null) { | ||
return pr; | ||
} else { | ||
nextPage = page.getNextPageRequest(); | ||
} | ||
} while(nextPage != null); | ||
return null; | ||
} | ||
|
||
private PullRequest searchForPR(Page<PullRequest> requests, String commitId) { | ||
for(PullRequest pr : requests.getValues()) { | ||
AtomicBoolean found = new AtomicBoolean(false); | ||
This comment has been minimized.
Sorry, something went wrong.
bturner
|
||
prService.streamCommits(pr.getToRef().getRepository().getId(), pr.getId(), commit -> { | ||
found.set(commit.getId().equals(commitId)); | ||
return !found.get(); | ||
}); | ||
if(found.get()) { | ||
return pr; | ||
} | ||
start += 10; | ||
} | ||
return null; | ||
} | ||
|
@@ -130,4 +144,5 @@ public ApprovalTask(Long pullRequestId, Integer repositoryId, String commitId) { | |
this.commitId = commitId; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Is this constant still used? Seems like it might be removable now