Jump to >

reviewboard.testing.scmtool

class TestTool(*args, **kwargs)[source]
get_repository_info()[source]

Return information on the repository.

The information will vary based on the repository. This data will be used in the API, and may be used by clients to better locate or match particular repositories.

It is recommended that it contain a uuid field containing a unique identifier for the repository, if available.

This is optional, and does not need to be implemented by subclasses.

Returns

A dictionary containing information on the repository.

Return type

dict

Raises

NotImplementedError – Repository information retrieval is not implemented by this type of repository. Callers should specifically check for this, as it’s considered a valid result.

get_branches()[source]

Return a list of all branches on the repository.

This will fetch a list of all known branches for use in the API and New Review Request page.

Subclasses that override this must be sure to always return one (and only one) Branch result with default set to True.

Callers should check supports_post_commit before calling this.

Returns

The list of branches in the repository. One (and only one) will be marked as the default branch.

Return type

list of Branch

Raises
get_commits(branch=None, start=None)[source]

Return a list of commits backward in history from a given point.

This will fetch a batch of commits from the repository for use in the API and New Review Request page.

The resulting commits will be in order from newest to oldest, and should return upwards of a fixed number of commits (usually 30, but this depends on the type of repository and its limitations). It may also be limited to commits that exist on a given branch (if supported by the repository).

This can be called multiple times in succession using the Commit.parent of the last entry as the start parameter in order to paginate through the history of commits in the repository.

Callers should check supports_post_commit before calling this.

Parameters
  • branch (unicode, optional) – The branch to limit commits to. This may not be supported by all repositories.

  • start (unicode, optional) – The commit to start at. If not provided, this will fetch the first commit in the repository.

Returns

The list of commits, in order from newest to oldest.

Return type

list of Commit

Raises
get_change(commit_id)[source]

Return an individual change/commit with the given revision.

This will fetch information on the given commit, if found, including its commit message and list of modified files.

Callers should check supports_post_commit before calling this.

Parameters

revision (unicode) – The revision/ID of the commit.

Returns

The resulting commit with the given revision/ID.

Return type

Commit

Raises
get_file(path, revision, **kwargs)[source]

Return a file from the repository.

This testing tool allows for special paths that allow callers to optionally define the data to return and the encoding to use for that data.

If the path starts with /data:, then what comes after will be returned as data (with a newline appended to the data). Otherwise, a standard Hello, world!\n will be returned.

If the path ends with ;encoding=..., then whatever is returned will be encoded in the specified encoding type.

Parameters
  • path (unicode) – The path to retrieve, optionally with custom data and an encoding.

  • revision (unicode, unused) – The revision to retrieve. This is ignored.

  • **kwargs (dict, unused) – Additional keyword arguments for the request.

Returns

The resulting file contents.

Return type

bytes

file_exists(path, revision, **kwargs)[source]

Return whether a particular file exists in a repository.

Like get_file(), this may take a base commit ID, which is the ID (SHA or revision number) of a commit changing or introducing the file. This depends on the type of repository, and may not be provided.

Subclasses should only override this if they have a more efficient way of checking for a file’s existence than fetching the file contents.

Changed in version 4.0.5: Added context, which deprecates base_commit_id and adds new capabilities for file lookups.

Parameters
  • path (unicode) – The path to the file in the repository.

  • revision (Revision, optional) – The revision to fetch. Subclasses should default this to HEAD.

  • base_commit_id (unicode, optional) –

    The ID of the commit that the file was changed in. This may not be provided, and is dependent on the type of repository.

    Deprecated since version 4.0.5: This will still be provided, but implementations should use FileLookupContext.base_commit_id` instead when running on Review Board 4.0.5+.

  • context (FileLookupContext, optional) –

    Extra context used to help look up this file.

    This contains information about the HTTP request, requesting user, and parsed diff information, which may be useful as part of the repository lookup process.

    This is always provided on Review Board 4.0.5 and higher. Implementations should be careful to validate the presence and values of any metadata stored within this.

    New in version 4.0.5.

  • **kwargs (dict) – Additional keyword arguments. This is not currently used, but is available for future expansion.

Returns

True if the file exists in the repository. False if it does not (or the parameters supplied were invalid).

Return type

bool

classmethod check_repository(path, *args, **kwargs)[source]

Performs checks on a repository to test its validity.

This should check if a repository exists and can be connected to. This will also check if the repository requires an HTTPS certificate.

The result is returned as an exception. The exception may contain extra information, such as a human-readable description of the problem. If the repository is valid and can be connected to, no exception will be thrown.

class TestToolSupportsPendingChangeSets(*args, **kwargs)[source]
get_changeset(changesetid, allow_empty=False)[source]

Return information on a server-side changeset with the given ID.

This only needs to be implemented if supports_pending_changesets is True.

Parameters
  • changesetid (unicode) – The server-side changeset ID.

  • allow_empty (bool, optional) –

    Whether or not an empty changeset (one containing no modified files) can be returned.

    If True, the changeset will be returned with whatever data could be provided. If False, a reviewboard.scmtools.errors.EmptyChangeSetError will be raised.

    Defaults to False.

Returns

The resulting changeset containing information on the commit and modified files.

Return type

ChangeSet

Raises
class TestToolDiffX(*args, **kwargs)[source]

SCMTool that uses DiffX diffs.

New in version 4.0.6.

get_parser(data)[source]

Return a diff parser used to parse diff data.

Parameters

data (bytes) – The diff data to parse.

Returns

The diff parser used to parse this data.

Return type

reviewboard.diffviewer.diffparser.DiffXParser