Jump to >

reviewboard.scmtools.models

class Tool(*args, **kwargs)[source]

A configured source code management tool.

Each SCMTool used by repositories must have a corresponding Tool entry. These provide information on the capabilities of the tool, and accessors to construct a tool for a repository.

Tool entries are populated by running the registerscmtools management command.

property supports_history[source]

Whether or not the SCMTool supports review requests with history.

See SCMTool.supports_history for details.

property supports_raw_file_urls[source]

Whether custom URL masks can be defined to fetching file contents.

See SCMTool.supports_raw_file_urls for details.

property supports_ticket_auth[source]

Whether ticket-based authentication is supported.

See SCMTool.supports_ticket_auth for details.

property supports_pending_changesets[source]

Whether server-side pending changesets are supported.

See SCMTool.supports_pending_changesets for details.

property field_help_text[source]

Overridden help text for the configuration form fields.

See SCMTool.field_help_text for details.

property scmtool_id[source]

The unique ID for the SCMTool.

Type:

unicode

get_scmtool_class()[source]

Return the configured SCMTool class.

Returns

The subclass of SCMTool backed by this Tool entry.

Return type

type

Raises

django.core.exceptions.ImproperlyConfigured – The SCMTool could not be found.

property scmtool_class[source]

Return the configured SCMTool class.

Returns

The subclass of SCMTool backed by this Tool entry.

Return type

type

Raises

django.core.exceptions.ImproperlyConfigured – The SCMTool could not be found.

class Repository(*args, **kwargs)[source]

A configured external source code repository.

Each configured Repository entry represents a source code repository that Review Board can communicate with as part of the diff uploading and viewing process.

Repositories are backed by a SCMTool, which functions as a client for the type of repository and can fetch files, load lists of commits and branches, and more.

Access control is managed by a combination of the public, users, and groups fields. public controls whether a repository is publicly-accessible by all users on the server. When False, only users explicitly listed in users or users who are members of the groups listed in groups will be able to access the repository or view review requests posted against it.

BRANCHES_CACHE_PERIOD = 300[source]

The amount of time branches are cached, in seconds.

Branches are cached for 5 minutes.

COMMITS_CACHE_PERIOD_SHORT = 300[source]

The short period of time to cache commit information, in seconds.

Some commit information (such as retrieving the latest commits in a repository) should result in information cached only for a short period of time. This is set to cache for 5 minutes.

COMMITS_CACHE_PERIOD_LONG = 86400[source]

The long period of time to cache commit information, in seconds.

Commit information that is unlikely to change should be kept around for a longer period of time. This is set to cache for 1 day.

FALLBACK_ENCODING = 'iso-8859-15'[source]

The fallback encoding for text-based files in repositories.

This is used if the file isn’t valid UTF-8, and if the repository doesn’t specify a list of encodings.

NAME_CONFLICT_ERROR = 'A repository with this name already exists'[source]

The error message used to indicate that a repository name conflicts.

PATH_CONFLICT_ERROR = 'A repository with this path already exists'[source]

The error message used to indicate that a repository path conflicts.

ENCRYPTED_PASSWORD_PREFIX = '\t'[source]

The prefix used to indicate an encrypted password.

This is used to indicate whether a stored password is in encrypted form or plain text form.

property password[source]

The password for the repository.

If a password is stored and encrypted, it will be decrypted and returned.

If the stored password is in plain-text, then it will be encrypted, stored in the database, and returned.

property scmtool_class[source]

The SCMTool subclass used for this repository.

Type:

type: A subclass of SCMTool.

hosting_service()[source]

The hosting service providing this repository.

This will be None if this is a standalone repository.

Type:

reviewboard.hostingsvcs.service.HostingService

bug_tracker_service()[source]

The selected bug tracker service for the repository.

This will be None if this repository is not associated with a bug tracker.

Type:

reviewboard.hostingsvcs.service.HostingService

property supports_post_commit[source]

Whether or not this repository supports post-commit creation.

If this is True, the get_branches() and get_commits() methods will be implemented to fetch information about the committed revisions, and get_change will be implemented to fetch the actual diff. This is used by ReviewRequestDraft.update_from_commit_id.

Type:

bool

property supports_pending_changesets[source]

Whether this repository supports server-aware pending changesets.

Type:

bool

diffs_use_absolute_paths()[source]

Whether or not diffs for this repository contain absolute paths.

Some types of source code management systems generate diffs that contain paths relative to the directory where the diff was generated. Most contain absolute paths. This flag indicates which path format this repository can expect.

Type:

bool

get_scmtool()[source]

Return an instance of the SCMTool for this repository.

Each call will construct a brand new instance. The returned value should be stored and used for multiple operations in a single session.

Returns

A new instance of the SCMTool for this repository.

Return type

reviewboard.scmtools.core.SCMTool

get_credentials()[source]

Return the credentials for this repository.

This returns a dictionary with username and password keys. By default, these will be the values stored for the repository, but if a hosting service is used and the repository doesn’t have values for one or both of these, the hosting service’s credentials (if available) will be used instead.

Returns

A dictionary with credentials information.

Return type

dict

get_or_create_hooks_uuid(max_attempts=20)[source]

Return a hooks UUID, creating one if necessary.

A hooks UUID is used for creating unique incoming webhook URLs, allowing services to communicate information to Review Board.

If a hooks UUID isn’t already saved, then this will try to generate one that doesn’t conflict with any other registered hooks UUID. It will try up to max_attempts times, and if it fails, None will be returned.

Parameters

max_attempts (int, optional) – The maximum number of UUID generation attempts to try before giving up.

Returns

The resulting UUID.

Return type

unicode

Raises

Exception – The maximum number of attempts has been reached.

get_encoding_list()[source]

Return a list of candidate text encodings for files.

This will return a list based on a comma-separated list of encodings in encoding. If no encodings are configured, the default of iso-8859-15 will be used.

Returns

The list of text encodings to try for files in the repository.

Return type

list of unicode

get_file(path, revision, base_commit_id=None, request=None, context=None)[source]

Return a file from the repository.

This will attempt to retrieve the file from the repository. If the repository is backed by a hosting service, it will go through that. Otherwise, it will attempt to directly access the repository.

This will send the fetching_file signal before beginning a file fetch from the repository (if not cached), and the fetched_file signal after.

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

  • revision (unicode) – The revision of the file to retrieve.

  • base_commit_id (unicode, optional) –

    The ID of the commit containing the revision of the file to retrieve. This is required for some types of repositories where the revision of a file and the ID of a commit differ.

    Deprecated since version 4.0.5: Callers should provide this in context instead.

  • request (django.http.HttpRequest, optional) –

    The current HTTP request from the client. This is used for logging purposes.

    Deprecated since version 4.0.5: Callers should provide this in context instead.

  • context (reviewboard.scmtools.core.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.

    New in version 4.0.5.

Returns

The resulting file contents.

Return type

bytes

Raises

TypeError – One or more of the provided arguments is an invalid type. Details are contained in the error message.

get_file_exists(path, revision, base_commit_id=None, request=None, context=None)[source]

Return whether or not a file exists in the repository.

If the repository is backed by a hosting service, this will go through that. Otherwise, it will attempt to directly access the repository.

The result of this call will be cached, making future lookups of this path and revision on this repository faster.

This will send the checking_file_exists signal before beginning a file fetch from the repository (if not cached), and the checked_file_exists signal after.

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

  • revision (unicode) – The revision of the file to check.

  • base_commit_id (unicode, optional) –

    The ID of the commit containing the revision of the file to check. This is required for some types of repositories where the revision of a file and the ID of a commit differ.

    Deprecated since version 4.0.5: Callers should provide this in context instead.

  • request (django.http.HttpRequest, optional) –

    The current HTTP request from the client. This is used for logging purposes.

    Deprecated since version 4.0.5: Callers should provide this in context instead.

  • context (reviewboard.scmtools.core.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.

    New in version 4.0.5.

Returns

True if the file exists in the repository. False if it does not.

Return type

bool

Raises

TypeError – One or more of the provided arguments is an invalid type. Details are contained in the error message.

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.

Returns

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

Return type

list of reviewboard.scmtools.core.Branch

Raises
get_commit_cache_key(commit_id)[source]

Return the cache key used for a commit ID.

The resulting cache key is used to cache information about a commit retrieved from the repository that matches the provided ID. This can be used to delete information already in cache.

Parameters

commit_id (unicode) – The ID of the commit to generate a cache key for.

Returns

The resulting cache key.

Return type

unicode

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

Return a list of commits.

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.

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 retrieved commits.

Return type

list of reviewboard.scmtools.core.Commit

Raises
get_change(revision)[source]

Return an individual change/commit in the repository.

Parameters

revision (unicode) – The commit ID or revision to retrieve.

Returns

The commit from the repository.

Return type

reviewboard.scmtools.core.Commit

Raises
normalize_patch(patch, filename, revision)[source]

Normalize a diff/patch file before it’s applied.

This can be used to take an uploaded diff file and modify it so that it can be properly applied. This may, for instance, uncollapse keywords or remove metadata that would confuse patch.

This passes the request on to the hosting service or repository tool backend.

Parameters
  • patch (bytes) – The diff/patch file to normalize.

  • filename (unicode) – The name of the file being changed in the diff.

  • revision (unicode) – The revision of the file being changed in the diff.

Returns

The resulting diff/patch file.

Return type

bytes

is_accessible_by(user)[source]

Return whether or not the user has access to the repository.

The repository is accessibly by the user if it is public or the user has access to it (either by being explicitly on the allowed users list, or by being a member of a review group on that list).

Parameters

user (django.contrib.auth.models.User) – The user to check.

Returns

True if the repository is accessible by the user. False if it is not.

Return type

bool

is_mutable_by(user)[source]

Return whether or not the user can modify or delete the repository.

The repository is mutable by the user if the user is an administrator with proper permissions or the repository is part of a LocalSite and the user has permissions to modify it.

Parameters

user (django.contrib.auth.models.User) – The user to check.

Returns

True if the repository can modify or delete the repository. False if they cannot.

Return type

bool

archive(save=True)[source]

Archive a repository.

The repository won’t appear in any public lists of repositories, and won’t be used when looking up repositories. Review requests can’t be posted against an archived repository.

New repositories can be created with the same information as the archived repository.

Parameters

save (bool, optional) – Whether to save the repository immediately.

save(**kwargs)[source]

Save the repository.

This will perform any data normalization needed, and then save the repository to the database.

Parameters

**kwargs (dict) – Keyword arguments to pass to the parent method.

clean()[source]

Clean method for checking null unique_together constraints.

Django has a bug where unique_together constraints for foreign keys aren’t checked properly if one of the relations is null. This means that users who aren’t using local sites could create multiple groups with the same name.

Raises

django.core.exceptions.ValidationError – Validation of the model’s data failed. Details are in the exception.