public interface

RepositoryRescopeContext

implements Iterable<T>
com.atlassian.stash.scm.pull.RepositoryRescopeContext

Class Overview

Provides a context for SCMs to perform rescope calculations and update affected pull requests when a repository is updated.

Rescoping candidates are accessed by iterating over the context. The candidates are guaranteed to:

  • Be non-empty: At least one candidate will be returned
  • Be stable: The same candidates will be retrieved in the same order each time
From the candidate pull requests, the SCM may take one of four possible actions. Each action has a specific contract which SCMs are expected to honour:
  • No action: If the pull request has not been updated, the SCM shall not update it in any way
  • Decline: If the source or target ref for the pull request has been removed, the SCM shall mark the pull request as declined
    • Some SCMs allow updating multiple branches in a single push
    • For such SCMs, if the source ref has been removed but the target ref has not, the SCM shall attempt to determine whether the pull request was merged and its source deleted in the same push
  • Merge: If the source or target ref for the pull request has been updated in such a way that there are no commits on the source that are not also on the target, the SCM shall mark the pull request as merged
    • SCMs which allow rewriting history must detect cases where such actions effectively remove all of the pending commits from a pull request
    • For example, force pushing a historical commit to the source ref may result in it referencing the same commit as the target ref, or one of its ancestors, effectively making the pull request "merged"
  • Update: If new commits have been added to the source or target refs, the SCM shall update the pull request with the new hashes
    • There must be at least one commit to be merged, or the pull request shall be marked as merged, not updated
    • SCMs which allow rewriting history must detect when commits are removed from a pull request's source or target refs and update or merge the pull request accordingly
Each pull request in the context may have exactly one operation performed on it. Additionally, only pull requests retrieved from the context may be provided back to it for declining, merging or updating.

Summary

Public Methods
void decline(MinimalPullRequest pullRequest)
Marks the pull request as declined.
void merge(MinimalPullRequest pullRequest)
Marks the pull request as remotely merged.
void update(MinimalPullRequest pullRequest, String newFromHash, String newToHash)
Updates the commits for the pull request's from and to refs to the hashes from their current tips in the repository.
[Expand]
Inherited Methods
From interface java.lang.Iterable

Public Methods

public void decline (MinimalPullRequest pullRequest)

Marks the pull request as declined.

Parameters
pullRequest the pull request to decline
Throws
IllegalArgumentException if the provided pullRequest was not returned by this context

public void merge (MinimalPullRequest pullRequest)

Marks the pull request as remotely merged.

When a pull request is remotely merged, the SCM is not required to detect the commit which actually carried out the merge. It is only required to detect that the pull request's refs have changed in a way which removes all of the pull request's incoming commits.

Parameters
pullRequest the pull request to mark as merged
Throws
IllegalArgumentException if the provided pullRequest was not returned by this context

public void update (MinimalPullRequest pullRequest, String newFromHash, String newToHash)

Updates the commits for the pull request's from and to refs to the hashes from their current tips in the repository.

Both hashes are required, but either one may be identical to its ref's existing value. If both hashes match the existing values the SCM should not call this method.

Parameters
pullRequest the pull request for which refs should be updated
newFromHash the hash for the current tip of the from ref
newToHash the hash for the current tip of the to ref
Throws
IllegalArgumentException if the provided pullRequest was not returned by this context