public interface RepositoryService extends RepositorySupplier
Modifier and Type | Method and Description |
---|---|
int |
countByProject(Project project)
Get the number of repositories that belong to a project.
|
Repository |
create(RepositoryCreateRequest request)
Create a new repository.
|
void |
delete(Repository repository)
Delete the repository.
|
Page<Repository> |
findAll(PageRequest pageRequest)
Find all repositories in the system in the default namespace.
|
Page<Repository> |
findByOrigin(Repository origin,
PageRequest pageRequest)
Retrieves a page of
repositories which have been forked from the specified origin . |
Page<Repository> |
findByOwner(ApplicationUser owner,
PageRequest pageRequest)
Retrieves a page of
repositories owned by the specified user . |
Page<Repository> |
findByProjectId(int projectId,
PageRequest pageRequest)
Retrieves a page of
repositories in the project with the given id. |
Page<Repository> |
findByProjectKey(String projectKey,
PageRequest pageRequest)
List the names of the repositories in the project with the given key and with a default (null) namespace.
|
Repository |
findPersonalFork(Repository repository)
Retrieves the current user's personal fork of the specified
repository . |
Page<Repository> |
findRelated(Repository repository,
PageRequest pageRequest)
Retrieves a page of
repositories which belong to the same hierarchy as the specified repository. |
Repository |
fork(RepositoryForkRequest request)
Create a new repository by forking from an existing repository.
|
Repository |
getById(int id)
Retrieves a
Repository by its ID . |
Repository |
getBySlug(String projectKey,
String slug)
Retrieves a
Repository by its slug . |
Set<NamedLink> |
getCloneLinks(RepositoryCloneLinksRequest request)
Retrieves
links that can be used to clone the supplied
repository via the repository's SCM's supported protocols. |
String |
getDefaultBranch()
Retrieves the configured global default branch.
|
MinimalRef |
getDefaultBranch(Repository repository)
Retrieves the configured default branch for the specified repository.
|
long |
getSize(Repository repository)
Calculates the size (in bytes) for the specified repository.
|
boolean |
isEmpty(Repository repository)
Retrieves a flag indicating whether the specified repository is empty or not.
|
boolean |
isForkingEnabled()
Retrieves a flag indicating whether the system has been configured to allow forking repositories.
|
Repository |
retryCreate(Repository repository)
If a create operation fails, calling this method will clean up the broken repository and try again.
|
Page<Repository> |
search(RepositorySearchRequest request,
PageRequest pageRequest)
Searches for
repositories that match the provided request . |
void |
setDefaultBranch(String defaultBranch)
Sets the global default branch to use when creating new repositories.
|
Repository |
setReadOnly(Repository repository,
boolean readOnly)
Enable/disable read-only mode for the given repository.
|
Repository |
update(RepositoryUpdateRequest request)
Update the metadata of a repository.
|
int countByProject(@Nonnull Project project)
project
- the project@Nonnull Repository create(@Nonnull RepositoryCreateRequest request)
slug
will be derived from the name. Both
the name and the generated slug must be unique within the project
.
Before the repository is created, a creation
requested event
is raised. This event is cancelable, allowing plugins to prevent repository creation based on
arbitrary considerations. If any listener cancels creation, the repository will not be created. It does
not require consensus among all registered listeners. If no listeners cancel, the repository will be created.
Events raised:
request
- describes the repository to createRepositoryCreationCanceledException
- if creation is canceled by an event listenervoid delete(@Nonnull Repository repository)
Before the repository is deleted, a deletion
requested event
is raised. This event is cancelable, allowing plugins to prevent repository deletion based on
arbitrary considerations. If any listener cancels deletion, the repository will not be deleted. It does
not require consensus among all registered listeners. If no listeners cancel, the repository will be deleted.
Events raised:
repository
- the repository to be deleted.RepositoryDeletionCanceledException
- if deletion is canceled by an event listenerAuthorisationException
- if the user does not have sufficient permission to delete a repository (as
specified by the instance repository delete policy)@Nonnull Page<Repository> findAll(@Nonnull PageRequest pageRequest)
pageRequest
- the page of repositories to return.@Nonnull Page<Repository> findByOrigin(@Nonnull Repository origin, @Nonnull PageRequest pageRequest)
repositories
which have been forked from the specified origin
.
The returned list is not guaranteed to be complete; it will be filtered to contain only those repositories which the requesting user has access to. This may not include forks in other users' personal projects, for example.
origin
- the origin repository for which forks should be foundpageRequest
- the bounds of the page@Nonnull Page<Repository> findByOwner(@Nonnull ApplicationUser owner, @Nonnull PageRequest pageRequest)
repositories
owned by the specified user
. These
are personal
repositories, which may be personal forks of other repositories or
the user's own repositories.
Only repositories visible to the current user will be returned, which may not be the full set of repositories owned by the specified user.
owner
- the user to retrieve personal repositories forpageRequest
- the bounds of the page@Nonnull Page<Repository> findByProjectId(int projectId, @Nonnull PageRequest pageRequest) throws NoSuchProjectException
repositories
in the project with the given id.projectId
- the ID of the project for which to list the repositoriespageRequest
- the page parameters for this querynull
NoSuchProjectException
- if the specified project does not exist@Nonnull Page<Repository> findByProjectKey(@Nonnull String projectKey, @Nonnull PageRequest pageRequest) throws NoSuchProjectException
projectKey
- the key of the project for which to list the repositoriespageRequest
- the page parameters for this querynull
NoSuchProjectException
- if the specified project does not exist@Nullable Repository findPersonalFork(@Nonnull Repository repository)
repository
. If the current
user has not yet forked the repository, or has forked it with a different name
,
null
will be returned.repository
- the repository to retrieve the current user's personal fork fornull
if the current user
has not forked the repository or has forked it with a different name@Nonnull Page<Repository> findRelated(@Nonnull Repository repository, @Nonnull PageRequest pageRequest)
repositories
which belong to the same hierarchy
as the specified repository. The specified repository will never itself be returned, even though it
is also part of the hierarchy.
The related repositories returned are not guaranteed to be the complete hierarchy; they will be filtered to contain only those repositories which the requesting user has access to. This may not include other users' personal forks of the repository, for example.
repository
- the repository to retrieve related repositories forpageRequest
- the bounds of the page@Nonnull Repository fork(@Nonnull RepositoryForkRequest request)
creating
a repository from scratch, the fork's slug
will be derived from its name,
and both the name and the slug must be unique within the target project.
project
is provided, the fork will be created
in the forking user's personal project
.name
is provided, the
parent
repository's name is retained for the fork.fork requested event
is raised. This event is cancelable, allowing plugins to prevent fork creation based on arbitrary considerations.
If any listener cancels forking, the fork will not be created. It does not require consensus among all
registered listeners. If no listeners cancel, the fork will be created.
Events raised:
request
- describes the repository to fork, as well as the project in which the fork should be created and
the name that should be assigned to itRepositoryForkCanceledException
- if forking is canceled by an event listenerFeatureUnsupportedScmException
- if the SCM for the parent repository does not support forkingjavax.validation.ConstraintViolationException
- if the fork's slug matches another repository within the
user's personal project@Nullable Repository getById(int id)
Repository
by its ID
.getById
in interface RepositorySupplier
id
- the repository's IDnull
if there is no repository with the specified IDAuthorisationException
- if the current user does not have permission to access the requested repository@Nullable Repository getBySlug(@Nonnull String projectKey, @Nonnull String slug)
Repository
by its slug
. Slugs are only unique within a given
Project
, so the project key
is also required.getBySlug
in interface RepositorySupplier
projectKey
- the key
of the project to search inslug
- the slug
of the repository to search fornull
if no repository matches the specified slug within the specified projectAuthorisationException
- if the current user does not have permission to access the requested repository@Nonnull Set<NamedLink> getCloneLinks(@Nonnull RepositoryCloneLinksRequest request)
links
that can be used to clone the supplied
repository
via the repository's SCM's
supported protocols.
Where appropriate to the underlying SCM type, SCM protocols may return link URLs that are customised to the
supplied user
or the
currently authenticated user
(if any). This might be
achieved, for instance, by inserting the user's name
in the
URL's authority part. Whether and how this customisation takes place is entirely up to each protocol.
Each link has a name
that indicates the protocol it supports
e.g. "ssh"
or "http"
.
request
- the request used to generate clone linksAuthorisationException
- if the current user does not have permission to access the requested repository@Nullable String getDefaultBranch()
Note: SCMs may change their default branch between versions, so relying on their default may produce inconsistent results over time.
null
if no default has been configuredsetDefaultBranch(String)
@Nonnull MinimalRef getDefaultBranch(@Nonnull Repository repository)
This method differs from RefService.getDefaultBranch(com.atlassian.bitbucket.repository.Repository)
in that, where that method will throw an
exception if the configured default branch does not exist (i.e. is not a ref in the repository pointing
to some commit), this method will not. Every repository has a configured default branch, even if
no ref exists with the configured name.
repository
- the repository to retrieve the configured default branch forRefService.getDefaultBranch(Repository)
long getSize(@Nonnull Repository repository)
Repository
does not exist,
its size is always 0
.
Note: Calculating the size can be an expensive operation. The returned value may be a best effort estimation of the repository size.
repository
- the repository whose size should be calculatedboolean isEmpty(@Nonnull Repository repository)
repository
- the repository to checktrue
if the repository is empty; otherwise false
boolean isForkingEnabled()
In addition to this system-wide setting, each Repository
may be explicitly configured as
Repository.isForkable()
or not. If forking is disabled system-wide, even repositories
configured as forkable cannot be forked. By the same token, even if forking is enabled system-wide,
any repository which is explicitly configured to disallow forks cannot be forked.
true
if the system is configured to allow repository forking; otherwise, false
Repository.isForkable()
@Nonnull Repository retryCreate(@Nonnull Repository repository)
The repository must be in INITIALISATION_FAILED
state
in order to retry creation.
repository
- the repository to retryIllegalRepositoryStateException
- if the repository is not in the required state@Nonnull Page<Repository> search(@Nonnull RepositorySearchRequest request, @Nonnull PageRequest pageRequest)
repositories
that match the provided request
.request
- a request object describing the repositories to returnpageRequest
- the bounds of the pagerepositories
that match the provided
criteria
RepositorySearchRequest
void setDefaultBranch(@Nullable String defaultBranch)
defaultBranch
- the new default branch name to use when creating repositories, which may be
null
to clear a previously-set defaultgetDefaultBranch()
@Nonnull Repository setReadOnly(@Nonnull Repository repository, boolean readOnly)
Note: If a repository is archived
, its read-only state cannot be
cleared. It must first be unarchived, and then it can be restored to read/write access.
repository
- the repository to enable/disable read-only mode onreadOnly
- true
to enable read-only mode; false
to disableRepositoryArchivedException
- if attempting to clear read-only from an archived repository@Nonnull Repository update(@Nonnull RepositoryUpdateRequest request)
RepositoryUpdateRequest
documentation.
Repository slugs
are derived from their names
.
Updating a repository's name may change its slug, which will also change all browser and clone URLs for the
affected repository. Old URLs will no longer work after such an update.
Before the repository is updated, a modification requested event
is raised. This event is cancelable, allowing plugins to prevent repository
modification based on arbitrary considerations. If any listener cancels modification, the repository
will not be updated. It does not require consensus among all registered listeners. If no listeners cancel,
the repository will be updated with the provided name
.
Events raised:
request
- describes the repository to update and the updates to applyArchiveRepositoryFailedException
- if repository archiving or unarchiving failedForbiddenException
- if the authenticated user does not have appropriate permissionsNoSuchEntityException
- if the repository does not existRepositoryArchivedException
- if the repository is archivedRepositoryModificationCanceledException
- if modification is canceled by an event listenerCopyright © 2024 Atlassian. All rights reserved.