public interface PullRequestService extends PullRequestSupplier
About pull request IDs: Each pull request has two repositories associated with it: The repository commits will be
merged from
, and the repository they will be merged
to
. Pull request ID
s are scoped to the target
repository,
and each method accepting a repository ID, unless otherwise documented, expects the ID of that repository. Also note
that pull request IDs start from 1 in each target repository; they are not globally unique.
Modifier and Type | Method and Description |
---|---|
PullRequestParticipant |
addReviewer(int repositoryId,
long pullRequestId,
String username)
Adds the user specified by 'username' as
REVIEWER to the provided PR. |
boolean |
canDelete(int repositoryId,
long pullRequestId)
Verifies if the current user can delete the specified
pull request . |
PullRequestMergeability |
canMerge(int repositoryId,
long pullRequestId)
Retrieves a flag indicating whether the specified pull request can be
merged
by the system or must be manually merged by a user. |
long |
count(PullRequestSearchRequest request)
Counts the number of pull requests which match the specified search criteria.
|
long |
countByCommit(PullRequestCommitSearchRequest request)
Counts the number of pull requests containing a specified commit which match the given
search criteria . |
long |
countCommits(int repositoryId,
long pullRequestId)
Counts the number of commits a pull request has.
|
TaskCount |
countTasks(PullRequestTaskSearchRequest searchRequest)
Counts the number of tasks in a pull request.
|
PullRequest |
create(PullRequestCreateRequest request)
Creates a pull request from the supplied details.
|
PullRequest |
decline(PullRequestDeclineRequest request)
Declines a pull request.
|
void |
delete(PullRequestDeleteRequest request)
Deletes the specified pull request, removing all activities and comments.
|
void |
deleteMergeConfig(DeletePullRequestMergeConfigRequest request)
Deletes the
merge configuration for the specified scope. |
Page<PullRequestActivity> |
getActivities(int repositoryId,
long pullRequestId,
PageRequest pageRequest)
Retrieves a page of the activities for a given pull request.
|
Set<PullRequestActivity> |
getActivitiesById(int repositoryId,
long pullRequestId,
Set<Long> activityIds)
Retrieves the specified activities of the given pull request.
|
PullRequestActivityPage<PullRequestActivity> |
getActivitiesStartingAt(int repositoryId,
long pullRequestId,
PullRequestEntityType fromType,
long fromId,
PageRequest pageRequest)
Retrieves the page of activities that start with an entity (given its type and id) for the given pull request.
|
PullRequest |
getById(int repositoryId,
long pullRequestId)
Retrieves a pull request by its ID, within the specified repository.
|
Page<Commit> |
getCommits(int repositoryId,
long pullRequestId,
PageRequest pageRequest)
Deprecated.
in 6.0 for removal in 7.0. Use
getCommits(PullRequestCommitsRequest, PageRequest) instead |
Page<Commit> |
getCommits(PullRequestCommitsRequest request,
PageRequest pageRequest)
Retrieves a page of the commits for a given pull request.
|
PullRequestMergeConfig |
getMergeConfig(GetPullRequestMergeConfigRequest request)
Retrieves the
merge configuration for the specified source. |
Page<PullRequestParticipant> |
getParticipants(int repositoryId,
long pullRequestId,
PageRequest pageRequest)
Retrieves a page of the participants for a given pull request.
|
PullRequest |
merge(PullRequestMergeRequest request)
Merges a pull request.
|
void |
removeReviewer(int repositoryId,
long pullRequestId,
String username)
Removes a
REVIEWER from a pull request. |
PullRequest |
reopen(int repositoryId,
long pullRequestId,
int version)
Reopens a pull request.
|
Page<PullRequest> |
search(PullRequestSearchRequest request,
PageRequest pageRequest)
Finds a single page of pull requests depending on the
request passed in. |
Page<PullRequestActivity> |
searchActivities(PullRequestActivitySearchRequest request,
PageRequest pageRequest)
Finds a single page of pull request activities depending on the
request
passed in. |
Page<PullRequest> |
searchByCommit(PullRequestCommitSearchRequest request,
PageRequest pageRequest)
Finds a single page of pull requests containing a specified commit which match the given
search criteria . |
Page<Task> |
searchTasks(PullRequestTaskSearchRequest searchRequest,
PageRequest pageRequest)
Finds a single page of @{link Task tasks} belonging to this pull request depending on the
request passed in. |
Page<ApplicationUser> |
searchUsers(PullRequestParticipantSearchRequest searchRequest,
PageRequest pageRequest)
Finds
users who have participated in pull requests based on the provided
search request . |
void |
setMergeConfig(SetPullRequestMergeConfigRequest request)
Sets the
merge configuration for the specified source, setting the
default strategy and the complete set of enabled strategies. |
PullRequestParticipant |
setReviewerStatus(int repositoryId,
long pullRequestId,
PullRequestParticipantStatus status)
Allows a user to update their participation status in a pull request.
|
void |
streamChanges(PullRequestChangesRequest request,
ChangeCallback callback)
|
void |
streamCommits(int repositoryId,
long pullRequestId,
CommitCallback callback)
Deprecated.
in 6.0 for removal in 7.0. Use
streamCommits(PullRequestCommitsRequest, CommitCallback)
instead |
void |
streamCommits(PullRequestCommitsRequest request,
CommitCallback callback)
Streams commits for the specified pull request.
|
void |
streamDiff(PullRequestDiffRequest request,
DiffContentCallback callback)
Streams the
Diff for the specified file path within the PullRequest to the provided
DiffContentCallback . |
void |
streamDiff(PullRequestDiffRequest request,
TypeAwareOutputSupplier outputSupplier)
Streams a raw diff for a given
PullRequest . |
PullRequest |
update(PullRequestUpdateRequest request)
Updates a pull request's title, description, and participants.
|
@Nonnull PullRequestParticipant addReviewer(int repositoryId, long pullRequestId, @Nonnull String username)
REVIEWER
to the provided PR.
If the user is already a reviewer this method has no effect.repositoryId
- the ID of the repository to which the pull request will be mergedpullRequestId
- the ID of the pull request within the repositoryusername
- the username for the user to be added as a reviewerNoSuchPullRequestException
- if no pull request with the specified ID can be found in the repositoryUnmodifiablePullRequestRoleException
- if the participant is already assigned the
AUTHOR
role.InvalidPullRequestParticipantException
- if the user cannot be made a reviewer because they have
insufficient access to the repositoryIllegalPullRequestStateException
- if the pull request is either MERGED
or DECLINED
boolean canDelete(int repositoryId, long pullRequestId)
pull request
.repositoryId
- the ID of the repository to which the pull request will be mergedpullRequestId
- the ID of the pull request within the repositorytrue
if the current user has sufficient permissions to delete(PullRequestDeleteRequest)
delete} the provided pull request, otherwise false
. Note that the required permissions may vary depending
on the role of the user in the pull request.PullRequestMergeability canMerge(int repositoryId, long pullRequestId)
merged
by the system or must be manually merged by a user.
Even if this method returns true
, there are still a variety of reasons for which merging may fail,
including but not limited to:
Note: If the specified pull request is declined
or
PullRequestState.MERGED
, this method will always return false
.
repositoryId
- the ID of the repository to which the pull request will be mergedpullRequestId
- the ID of the pull request within the repositoryRepositoryMergeCheck
s may have raisedIllegalPullRequestStateException
- if the pull request is not openlong countCommits(int repositoryId, long pullRequestId)
repositoryId
- the ID of the repository to which the pull request will be mergedpullRequestId
- the ID of the pull request within the repositoryNoSuchPullRequestException
- if no pull request with the specified ID can be found in the repositorylong count(@Nonnull PullRequestSearchRequest request)
request
- the search criteria to uselong countByCommit(@Nonnull PullRequestCommitSearchRequest request)
search criteria
.
Similar to count(PullRequestSearchRequest)
, if the request doesn't limit the search to a repository
that the user has access to, the count may include pull requests the user can't see.request
- the search request to use@Nonnull TaskCount countTasks(@Nonnull PullRequestTaskSearchRequest searchRequest)
searchRequest
- the search criteria to useTaskCount
object containing the number of tasks in each stateNoSuchPullRequestException
- if no pull request with the specified ID can be found in the repository@Nonnull PullRequest create(@Nonnull PullRequestCreateRequest request)
Events raised:
request
- the details for the new pull requestDuplicatePullRequestException
- if there is already an open pull request with identical to and from
repositories and branchesEmptyPullRequestException
- if the to branch is up-to-date with all of the changes on the from branch,
resulting in a pull request with nothing to mergeInvalidPullRequestTargetException
- if the from or to repositories are not the same or if the from
and to branches are the sameInvalidPullRequestReviewersException
- if one or more of the reviewers could not be addedPullRequestOpenCanceledException
- if opening the pull request is canceled by an event listenerNoSuchCommitException
- if the the from or to branches do not exist@Nonnull PullRequest decline(@Nonnull PullRequestDeclineRequest request)
request
- details for declining a pull requestIllegalPullRequestStateException
- if the pull request is not openNoSuchPullRequestException
- if no pull request with the specified ID can be found in the repositoryPullRequestOutOfDateException
- if the version of the specified pull request does not match the expected versionvoid delete(@Nonnull PullRequestDeleteRequest request)
The from
and to
refs are not deleted
with the pull request, to prevent accidental data loss. However, other SCM-specific data such as cached
merges or special refs to provide access to pull request state will be deleted along with the pull request.
request
- details for deleting a pull requestAuthorisationException
- if the current user does not have permission to delete the pull requestNoSuchPullRequestException
- if no pull request with the specified ID can be found in the repositoryPullRequestDeletionDisabledException
- if deletion
has
been disabledcanDelete(int, long)
void deleteMergeConfig(@Nonnull DeletePullRequestMergeConfigRequest request)
merge configuration
for the specified scope.
Repositories inherit their merge configuration from the nearest configured scope. For example, deleting a repository's merge config may cause it to inherit project or global configuration rather than reverting to the SCM's defaults.
request
- describes which merge configuration is to be deletedsetMergeConfig(SetPullRequestMergeConfigRequest)
@Nonnull Page<PullRequestActivity> getActivities(int repositoryId, long pullRequestId, @Nonnull PageRequest pageRequest)
repositoryId
- the ID of the repository to which the pull request will be mergedpullRequestId
- the ID of the pull request within the repositorypageRequest
- the request specifying the start and limit of the page@Nonnull PullRequestActivityPage<PullRequestActivity> getActivitiesStartingAt(int repositoryId, long pullRequestId, @Nonnull PullRequestEntityType fromType, long fromId, @Nonnull PageRequest pageRequest)
Entity types currently accepted:
PullRequestEntityType.ACTIVITY
to search for the page of activities starting with
the supplied activity
PullRequestEntityType.COMMENT
to search for the page of activities starting with
the activity of the supplied comment. If the comment is not a root comment, the comment's
root's activity is used.
repositoryId
- the ID of the repository to which the pull request will be mergedpullRequestId
- the ID of the pull request within the repositoryfromType
- the type of the entity to search forfromId
- ID of the entity to search for - either a comment ID or activity IDpageRequest
- the request specifying the limit of the page. Note: the start property is ignored.NoSuchEntityException
- if the activity can't be found.@Nonnull Set<PullRequestActivity> getActivitiesById(int repositoryId, long pullRequestId, Set<Long> activityIds)
repositoryId
- the ID of the repository to which the pull request will be mergedpullRequestId
- the ID of the pull request within the repositoryactivityIds
- the activity IDs that should be retrieved@Nullable PullRequest getById(int repositoryId, long pullRequestId)
getById
in interface PullRequestSupplier
repositoryId
- the ID of the repository to which the pull request will be mergedpullRequestId
- the ID of the pull request within the repository@Nonnull Page<Commit> getCommits(@Nonnull PullRequestCommitsRequest request, @Nonnull PageRequest pageRequest)
request
- the repository, pull request and other properties describing the commits to returnpageRequest
- the request specifying the start and limit of the pageNoSuchPullRequestException
- if no pull request with the specified ID can be found in the repository@Deprecated @Nonnull Page<Commit> getCommits(int repositoryId, long pullRequestId, @Nonnull PageRequest pageRequest)
getCommits(PullRequestCommitsRequest, PageRequest)
insteadrepositoryId
- the ID of the repository to which the pull request will be mergedpullRequestId
- the ID of the pull request within the repositorypageRequest
- the request specifying the start and limit of the pageNoSuchPullRequestException
- if no pull request with the specified ID can be found in the repository@Nonnull PullRequestMergeConfig getMergeConfig(@Nonnull GetPullRequestMergeConfigRequest request)
merge configuration
for the specified source. All of
the supported merge strategies
are returned, but only
enabled
strategies can be specified when merging
pull requests. At least one strategy, the default
, is guaranteed to be enabled.
For cross-repository
pull requests, the configuration for the
target repository
controls how the pull request can be merged.
Merge configuration can be applied at 3 different levels, listed from most specific to most generic:
Repository
Project
and SCM
PullRequestMergeConfigType.SCM
defaults
for the appropriate SCM are returned.
SCMs are not required to support merge strategies. Plugins should check support
for the MERGE_STRATEGIES
feature prior to calling
this method. If the SCM does not support merge strategies, an exception will be thrown.
request
- a request describing the repository, project-and-SCM or SCM to retrieve configuration forto
the specified repository,
repositories within the specified project, or repositories of the specified SCMAuthorisationException
- if the requesting user does not have access to the source they're retrieving
merge configuration forFeatureUnsupportedScmException
- if the SCM does not support merge strategies@Nonnull Page<PullRequestParticipant> getParticipants(int repositoryId, long pullRequestId, @Nonnull PageRequest pageRequest)
repositoryId
- the ID of the repository to which the pull request will be mergedpullRequestId
- the ID of the pull request within the repositorypageRequest
- the request specifying the start and limit of the page@Nonnull PullRequest merge(@Nonnull PullRequestMergeRequest request)
request
- details for merging the pull request, specifying the pull request to merge, the expected
version, and, optionally, a commit message and additional contextIllegalPullRequestStateException
- if the pull request is not openNoSuchPullRequestException
- if no pull request with the specified ID can be found in the repositoryPullRequestMergeVetoedException
- if the merge was canceled by an event listener or hookPullRequestOutOfDateException
- if the version of the specified pull request does not match the expected versionvoid removeReviewer(int repositoryId, long pullRequestId, @Nonnull String username)
REVIEWER
from a pull request.
If the user is the AUTHOR
of the pull request this method will throw
IllegalPullRequestStateException
; the author may not be removed.
If the user has no activity
items associated with them in the
pull request they will be completely removed. Otherwise they will be made a PARTICIPANT
instead.
repositoryId
- the ID of the repository to which the pull request will be mergedpullRequestId
- the ID of the pull request within the repositoryusername
- the reviewer's user nameNoSuchPullRequestException
- if no pull request with the specified ID can be found in the repositoryUnmodifiablePullRequestRoleException
- if the user is the AUTHOR
of the PRIllegalPullRequestStateException
- if the pull request is either MERGED
or DECLINED
@Nonnull PullRequest reopen(int repositoryId, long pullRequestId, int version)
repositoryId
- the ID of the repository to which the pull request will be mergedpullRequestId
- the ID of the pull request within the repositoryversion
- the expected version of the pull requestDuplicatePullRequestException
- if a pull request with the same source and target refs already existsIllegalPullRequestStateException
- if the pull request is not declinedNoSuchPullRequestException
- if no pull request with the specified ID can be found in the repositoryPullRequestOutOfDateException
- if the version of the specified pull request does not match the expected version@Nonnull Page<PullRequest> search(@Nonnull PullRequestSearchRequest request, @Nonnull PageRequest pageRequest)
request
passed in.
If the request specifies that the results should be sorted by participant status
then only one participant may be specified in the requestrequest
- the search criteria to usepageRequest
- the request specifying the start and limit of the searchIllegalPullRequestSearchRequestException
- if PARTICIPANT_STATUS
order
was requested but PullRequestSearchRequest.getParticipants()
is empty or contains more than one participant (since 4.4)@Nonnull Page<PullRequestActivity> searchActivities(@Nonnull PullRequestActivitySearchRequest request, @Nonnull PageRequest pageRequest)
request
passed in.request
- the search criteria to usepageRequest
- the request specifying the start and limit of the search@Nonnull Page<PullRequest> searchByCommit(@Nonnull PullRequestCommitSearchRequest request, @Nonnull PageRequest pageRequest)
search criteria
.request
- the search request to usepageRequest
- the request specifying the start and limit of the search@Nonnull Page<Task> searchTasks(@Nonnull PullRequestTaskSearchRequest searchRequest, @Nonnull PageRequest pageRequest)
request
passed in.searchRequest
- the search criteria to usepageRequest
- the request specifying the start and limit of the search@Nonnull Page<ApplicationUser> searchUsers(@Nonnull PullRequestParticipantSearchRequest searchRequest, @Nonnull PageRequest pageRequest)
users
who have participated in pull requests based on the provided
search request
.searchRequest
- the search criteria to usepageRequest
- the request specifying the start and limit of the searchvoid setMergeConfig(@Nonnull SetPullRequestMergeConfigRequest request)
merge configuration
for the specified source, setting the
default strategy and the complete set of enabled strategies. Any enabled strategy may be requested
when merging a pull request, and the specified default must be enabled. The enabled strategies
are verified against the SCM to ensure they are all supported.
For cross-repository
pull requests, the configuration for the
target repository
controls how the pull request can be merged.
Merge configuration can be applied at 3 different levels, listed from most specific to most generic, and can only be updated by administrators:
Repository
REPO_ADMIN
permissionProject
and SCM
PROJECT_ADMIN
permissionPullRequestMergeConfigType.SCM
global ADMIN
permission
SCMs are not required to support merge strategies. Plugins should check support
for the MERGE_STRATEGIES
feature prior to calling
this method. If the SCM does not support merge strategies, an exception will be thrown.
request
- a request describing the repository, project-and-SCM or SCM to set configuration for, the
default strategy to use and the set of strategies that should be enabledArgumentValidationException
- if the default merge strategy is not enabled, or if any of the enabled
strategies are not supported by the associated SCMAuthorisationException
- if the updating user does not have the required administrator permissionFeatureUnsupportedScmException
- if the SCM does not support merge strategies@Nonnull PullRequestParticipant setReviewerStatus(int repositoryId, long pullRequestId, @Nonnull PullRequestParticipantStatus status)
UNAPPROVED
.
A user may only update their status if a pull request is OPEN
.
This operation has no effect if the user already has their status set to the provided value.
Authors may not have their status changed.
repositoryId
- the ID of the repository to which the pull request will be mergedpullRequestId
- the ID of the pull request within the repositorystatus
- the participant status to set for the current userInvalidPullRequestParticipantException
- if the user cannot be made a participant because they have
insufficient privileges to read the repositoryIllegalPullRequestStateException
- if the pull request is not openvoid streamChanges(@Nonnull PullRequestChangesRequest request, @Nonnull ChangeCallback callback)
changes
for the specified PullRequest
to the provided ChangeCallback
.
Note: Internal hard limits are applied to the number of changes
which will be returned. When
changes are truncated for exceeding those limits, it will be signalled to the callback.
request
- the repository, pull request and other properties describing the changes to streamcallback
- the callback to receive changes
NoSuchPullRequestException
- if no pull request with the specified ID can be found in the repositoryvoid streamCommits(@Nonnull PullRequestCommitsRequest request, @Nonnull CommitCallback callback)
request
- the repository, pull request and other properties describing the commits to streamcallback
- the request specifying the start and limit of the pageNoSuchPullRequestException
- if no pull request with the specified ID can be found in the repository@Deprecated void streamCommits(int repositoryId, long pullRequestId, @Nonnull CommitCallback callback)
streamCommits(PullRequestCommitsRequest, CommitCallback)
insteadrepositoryId
- the ID of the repository to which the pull request will be mergedpullRequestId
- the ID of the pull request within the repositorycallback
- the request specifying the start and limit of the pageNoSuchPullRequestException
- if no pull request with the specified ID can be found in the repositoryvoid streamDiff(@Nonnull PullRequestDiffRequest request, @Nonnull DiffContentCallback callback)
Diff
for the specified file path
within the PullRequest
to the provided
DiffContentCallback
. Comment anchors will be offered
to the callback prior to streaming the diff, allowing them to be merged into the diff output as desired.
If the Change
indicated the path
being diffed was moved/renamed
or
copied
, the srcPath
should also be provided. Failure to
provide both paths may result in an incorrect diff in some SCMs.
Note: Internal hard limits are applied to the diff being streamed, limiting the number of lines that can be returned. When a diff is truncated for exceeding those limits, it will be signalled to the callback.
request
- the repository, pull request, path and other properties describing the diff to streamcallback
- the callback to receive the streamed Diff
NoSuchPullRequestException
- if no pull request with the specified ID can be found in the repositoryvoid streamDiff(@Nonnull PullRequestDiffRequest request, @Nonnull TypeAwareOutputSupplier outputSupplier)
PullRequest
.request
- the repository, pull request, path and other properties describing the diff to streamoutputSupplier
- a supplier which will provide an output stream@Nonnull PullRequest update(@Nonnull PullRequestUpdateRequest request)
This method will fire:
PullRequestUpdatedEvent
to inform listeners that the title or description have changedPullRequestReviewersUpdatedEvent
to inform listeners of any reviewers assigned or unassigned from this rolePullRequestParticipantsAddedEvent
to inform listeners of any users who have participated in the pull request for the first timePullRequestRescopedEvent
to inform listeners the the destination branch has been updated and rescope has occurredrequest
- details for updating a pull request, including a title, description and reviewers.NoSuchPullRequestException
- if no pull request with the specified ID can be found in the repositoryPullRequestOutOfDateException
- if the version of the specified pull request does not match the expected versionInvalidPullRequestReviewersException
- if one or more of the reviewers could not be addedDuplicatePullRequestException
- if there is already an open pull request with an identical to branchInvalidPullRequestTargetException
- if the from and new to branch are the sameEmptyPullRequestException
- if the new destination branch up-to-date is up-to-date with all of the changes
from the from branch, resulting in a pull request with nothing to mergeIllegalPullRequestStateException
- if trying to update a merged pull requestCopyright © 2019 Atlassian. All rights reserved.