Interface AutoMergeService


public interface AutoMergeService
Since:
8.15
  • Method Details

    • cancelAutoMerge

      @Nonnull PullRequest cancelAutoMerge(int repositoryId, long pullRequestId, @Nonnull AutoMergeCancelledReason cancelledReason)
      Cancels the automatic merging of the pull request by the system with a provided reason, and logs the cancellation as a pull request activity. If a pull request was set to auto-merge, and it has not been merged yet, invoking this method will ensure that the system does not try to merge this pull request, and it has to be merged manually. If the pull request is not set to auto-merge this method is a no-op.
      Parameters:
      repositoryId - the ID of the repository to which the pull request is supposed to merge
      pullRequestId - the ID of the pull request within the repository
      cancelledReason - the reason the auto-merge request has been cancelled
      Returns:
      The pull request for which the cancellation of auto-merge is requested
      Throws:
      NoSuchPullRequestException - if the pull request is not found
      IllegalPullRequestStateException - if the pull request is currently locked for some other operation.
    • getAutoMergeRequest

      @Nonnull Optional<AutoMergeRequest> getAutoMergeRequest(@Nonnull PullRequest pullRequest)
      Finds an auto-merge request for the given pull request.
      Parameters:
      pullRequest - the pull request for which auto-merge request has to be fetched
      Returns:
      an Optional containing auto-merge request for the pull request, if one exists, otherwise Optional.empty()
    • isSettingEnabledForPullRequest

      boolean isSettingEnabledForPullRequest(@Nonnull PullRequest pullRequest)
      Parameters:
      pullRequest - the pull request to check if its target repository has auto-merge settings enabled
      Returns:
      true if auto-merge is enabled for the repository containing the pull request; otherwise, false if it is disabled
      Since:
      8.15
    • submitAutoMergeRequest

      @Nonnull PullRequest submitAutoMergeRequest(@Nonnull PullRequestMergeRequest pullRequestMergeRequest)
      Creates an auto-merge request for the provided pull request with all the parameters from the provided merge request, if all the following conditions are met:
      • the setting is enabled for the repository that the pull request targets
      • auto-merge is not already requested for this pull request
      • there are no merge conflicts on the pull request
      • the pull request cannot be merged immediately

      If the auto-merge request is submitted successfully, the system will merge this pull request on behalf of the user that requested auto-merge once the pull request is ready to merge. If the pull request is already mergeable, it will be merged immediately.

      Parameters:
      pullRequestMergeRequest - the parameters to be used to auto-merge the pull request when it is ready to merge
      Returns:
      the updated pull request
      Throws:
      AutoMergeSettingNotEnabledException - if the auto-merge setting is not enabled for this repository
      IllegalPullRequestStateException - if the pull request has merge conflict(s)
    • tryAutoMerge

      @Nonnull AutoMergeProcessingResult tryAutoMerge(int repositoryId, long pullRequestId)
      Requests the system to try auto-merging a pull request. A merge will be attempted if the following conditions are met:
      • There is a valid auto-merge request associated with the provided pull request. If the request is invalid, e.g. because changes have been made to the source branch or the auto-merge request has expired, then the request is cancelled.
      • The pull request can be merged. If the pull request cannot be merged, e.g. because it is locked due to rescoping or has conflicts with the target branch, then the request is cancelled.

      If both conditions are met, then the merge will be attempted.

      Parameters:
      repositoryId - the ID of the repository to which the pull request is supposed to merge
      pullRequestId - the ID of the pull request within the repository
      Returns:
      the result of auto-merge processing
      Throws:
      AutoMergeNotRequestedException - if no auto-merge request is found for the specified pull request
      AutoMergeSettingNotEnabledException - if the auto-merge setting is not enabled for this repository
      NoSuchPullRequestException - if the pull request is not found
      PullRequestMergeVetoedException - if the pull request was vetoed while merging but not during dry run