I need to get a pull request from the project, repository and pull request number with Script Runner. Usually I use the event but in this case I only have the repository slug and pull request ID.
After viewing some examples here https://www.programcreek.com/java-api-examples/index.php?api=com.atlassian.bitbucket.pull.PullRequest:
Figured this out:
import com.atlassian.bitbucket.pull.PullRequestSearchRequest
import com.atlassian.bitbucket.util.PageRequestImpl
import com.atlassian.bitbucket.util.PageRequest
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.bitbucket.repository.RepositoryService
import com.atlassian.bitbucket.repository.Repository
import com.atlassian.bitbucket.repository.RefService
import com.atlassian.bitbucket.pull.PullRequest
import static com.atlassian.bitbucket.pull.PullRequestState.OPEN;
import com.atlassian.bitbucket.pull.PullRequestService
import com.atlassian.bitbucket.pull.PullRequestUpdateRequest
def repositoryService = ComponentLocator.getComponent(RepositoryService.class);
def refService = ComponentLocator.getComponent(RefService.class);
Repository rep = repositoryService.getBySlug("Project1","Repo1");
int id = rep.getId();
log.warn(id.toString())
def pullRequestService = ComponentLocator.getComponent(PullRequestService)
PageRequest page = new PageRequestImpl(0, 10)
PullRequestSearchRequest pullr = new PullRequestSearchRequest.Builder().toRepositoryId(id).state(OPEN).build()
long pullrequestID
int version
log.warn(pullRequestService.search(pullr, page).getValues().toString())
pullRequestService.search(pullr,page).getValues().forEach( val -> {
//log.warn("ID: "+val.id+" Description "+val.getDescription())
pullrequestID = val.id
version = val.version
}
)
log.warn(pullRequestService.getById(id,pullrequestID).getDescription())
@Infantino Benitono need to make a paged request if you have a Project Key, Repository slug and pull request id. The following script should get you a single pull request where :
- Project Key = 'PROJECT_1'
- Repository Slug = 'rep_1'
- Pull Request id = '1'
```
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.