Package com.atlassian.bitbucket.scm.http
Class RepositoryUrlFragment
java.lang.Object
com.atlassian.bitbucket.scm.http.RepositoryUrlFragment
Utility class for parsing project keys and repository slugs from scm urls - HTTP and SSH.
This class only works with paths that begin with:
- <baseUrl>/PROJECT_KEY/REPOSITORY_SLUG/
- <baseUrl>/PROJECT_KEY/REPOSITORY_SLUG.git/ (the .git suffix is not captured)
This class captures any path suffix
that did not describe the repository but still may be
useful to identify.
-
Method Summary
Modifier and TypeMethodDescriptionstatic RepositoryUrlFragment
fromKeyAndSlug
(String projectKey, String repositorySlug) static RepositoryUrlFragment
fromPathInfo
(String pathInfo) Extracts the repository URL fragment from the given path info.static RepositoryUrlFragment
fromRepository
(com.atlassian.bitbucket.repository.Repository repository) Formats this fragment as a path suitable for use with aURI
, such as withURI.resolve(String)
, optionally pre-pending a provided base path.Formats this fragment as a path suitable for use with aURI
, such as withURI.resolve(String)
, optionally pre-pending a provided base path.toString()
-
Method Details
-
fromPathInfo
Extracts the repository URL fragment from the given path info.- Parameters:
pathInfo
- the path info as provided by theHttpServletRequest.getPathInfo()
method.- Returns:
- a new repository URL fragment, or null if the path info does not contain a repository URL fragment
- Throws:
NullPointerException
- if the path info is null
-
fromRepository
@Nonnull public static RepositoryUrlFragment fromRepository(@Nonnull com.atlassian.bitbucket.repository.Repository repository) - Parameters:
repository
- the repository to create a fragment for- Returns:
- a URL fragment for the specified repository
-
fromKeyAndSlug
@Nonnull public static RepositoryUrlFragment fromKeyAndSlug(@Nonnull String projectKey, @Nonnull String repositorySlug) - Parameters:
projectKey
- the project key to userepositorySlug
- the repository slug to use- Returns:
- a URL fragment for the specified projectKey and repositorySlug
- Since:
- 6.7
-
getPathSuffix
- Returns:
- the suffix after the project key / repository part of the path or null if there was none
- Since:
- 5.1
-
getProjectKey
-
getRepositorySlug
-
toPath
Formats this fragment as a path suitable for use with aURI
, such as withURI.resolve(String)
, optionally pre-pending a provided base path. Thepath suffix
nor the .git extension if present in the original path are output here.- Parameters:
basePath
- the base path to prepend, ornull
- Returns:
- a URI-suitable path
-
toPath
Formats this fragment as a path suitable for use with aURI
, such as withURI.resolve(String)
, optionally pre-pending a provided base path. Thepath suffix
is included if theincludeSuffix
parameter istrue
.- Parameters:
basePath
- the base path to prepend, ornull
includeSuffix
- whether to include the suffix- Returns:
- a URI-suitable path
- Since:
- 7.18
-
toString
-