Class GitLab
- java.lang.Object
-
- com.mooltiverse.oss.nyx.services.gitlab.GitLab
-
- All Implemented Interfaces:
GitHostingService,ReleaseService,Service,UserService
public class GitLab extends Object implements GitHostingService, ReleaseService, UserService
The entry point to the GitLab remote service.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.mooltiverse.oss.nyx.services.Service
Service.Feature
-
-
Field Summary
Fields Modifier and Type Field Description static StringAUTHENTICATION_TOKEN_OPTION_NAMEThe name of the option used to pass the authentication token (Personal Access Token, OAuth) to this object instance.static StringBASE_URI_OPTION_NAMEThe name of the option used to pass the base URI to this object instance.static StringREMOTES_OPTION_NAMEThe name of the option used to pass the list of supported remotes to this object instance.static StringREPOSITORY_NAME_OPTION_NAMEThe name of the option used to pass the name of the Git repository to this object instance.static StringREPOSITORY_OWNER_OPTION_NAMEThe name of the option used to pass the owner of the Git repository to this object instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description GitLabRepositorycreateGitRepository(String name, String description, boolean restricted, boolean initialize)Creates a new Git repository for the currently authenticated user.voiddeleteGitRepository(String name)Deletes a Git repository for the currently authenticated user.GitLabUsergetAuthenticatedUser()Retrieves informations about the currently authenticated user.GitLabReleasegetReleaseByTag(String owner, String repository, String tag)Finds the release in the given repository by the release tag.static GitLabinstance(Map<String,String> options)Returns an instance using the given options.GitLabReleasepublishRelease(String owner, String repository, String title, String tag, String description)Publishes a new release.GitLabReleasepublishReleaseAssets(String owner, String repository, Release release, Set<Attachment> assets)Publishes a set of assets for a release.booleansupports(Service.Feature feature)Safely checks if the underlying implementation supports the given operation.
-
-
-
Field Detail
-
BASE_URI_OPTION_NAME
public static final String BASE_URI_OPTION_NAME
The name of the option used to pass the base URI to this object instance. This is the value of the key inside the options passed to get a new instance of this class. If this option is not passed the default URI is used. Value: "BASE_URI"- See Also:
- Constant Field Values
-
AUTHENTICATION_TOKEN_OPTION_NAME
public static final String AUTHENTICATION_TOKEN_OPTION_NAME
The name of the option used to pass the authentication token (Personal Access Token, OAuth) to this object instance. This is the value of the key inside the options passed to get a new instance of this class. If this option is not passed the service will not be able to authenticate and perform any of the authentication protected operations. Value: "AUTHENTICATION_TOKEN"- See Also:
- Constant Field Values
-
REMOTES_OPTION_NAME
public static final String REMOTES_OPTION_NAME
The name of the option used to pass the list of supported remotes to this object instance. This is the value of the key inside the options passed to get a new instance of this class. If this option is not passed the service will not be able to perform some of its operations. Value: "REMOTES"- See Also:
- Constant Field Values
-
REPOSITORY_NAME_OPTION_NAME
public static final String REPOSITORY_NAME_OPTION_NAME
The name of the option used to pass the name of the Git repository to this object instance. If the repository ishttps://gitlab.com/jdoe/project, the value to pass for this option isproject, while if it's a hierarchical project likehttps://gitlab.com/acme/project/at/some/depth, the value to pass for this option isproject/at/some/depth. Leading and trailing slashes must be omitted, if any. This is the value of the key inside the options passed to get a new instance of this class. If this option is not passed the service will not be able to perform some of its operations. Value: "REPOSITORY_NAME"- See Also:
- Constant Field Values
-
REPOSITORY_OWNER_OPTION_NAME
public static final String REPOSITORY_OWNER_OPTION_NAME
The name of the option used to pass the owner of the Git repository to this object instance. If the repository ishttps://gitlab.com/jdoe/project, the value to pass for this option isjdoe, and if it's a hierarchical project likehttps://gitlab.com/acme/project/at/some/depth, the value to pass for this option isacme. Leading and trailing slashes must be omitted, if any. This is the value of the key inside the options passed to get a new instance of this class. If this option is not passed the service will not be able to perform some of its operations. Value: "REPOSITORY_OWNER"- See Also:
- Constant Field Values
-
-
Method Detail
-
instance
public static GitLab instance(Map<String,String> options)
Returns an instance using the given options.- Parameters:
options- the map of options for the requested service. It can't benull. Valid options are documented as constants on this class.- Returns:
- an instance using the given options.
- Throws:
NullPointerException- if the given options map isnullIllegalArgumentException- if some entries in the given options map are missing or illegal for some reason
-
createGitRepository
public GitLabRepository createGitRepository(String name, String description, boolean restricted, boolean initialize) throws SecurityException, TransportException
Creates a new Git repository for the currently authenticated user.
Please note that if the service has been configured with repository owner and name those attributes are ignored by this method as the owner is always the authenticated user (the one owning the configured credentials) and the name is always thenameattribute.- Specified by:
createGitRepositoryin interfaceGitHostingService- Parameters:
name- the repository name. Cannot benulldescription- the repository description. It may benullrestricted- whentruethe repository will have private visibility, otherwise it will be publicinitialize- whentruethe repository is also initialized (usually with a default README file)- Returns:
- the object representing the newly created repository
- Throws:
SecurityException- if authentication or authorization fails or there is no currently authenticated userTransportException- if communication to the remote endpoint fails
-
deleteGitRepository
public void deleteGitRepository(String name) throws SecurityException, TransportException
Deletes a Git repository for the currently authenticated user.
Please note that if the service has been configured with repository owner and name those attributes are ignored by this method as the owner is always the authenticated user (the one owning the configured credentials) and the name is always thenameattribute.- Specified by:
deleteGitRepositoryin interfaceGitHostingService- Parameters:
name- the repository name. Cannot benull- Throws:
SecurityException- if authentication or authorization fails or there is no currently authenticated userTransportException- if communication to the remote endpoint fails
-
getAuthenticatedUser
public GitLabUser getAuthenticatedUser() throws TransportException, SecurityException
Retrieves informations about the currently authenticated user. The authenticated user is the one owning the configured credentials.- Specified by:
getAuthenticatedUserin interfaceUserService- Returns:
- the authenticated user
- Throws:
TransportException- if communication to the remote endpoint failsSecurityException- if authentication or authorization fails or there is no currently authenticated user
-
getReleaseByTag
public GitLabRelease getReleaseByTag(String owner, String repository, String tag) throws SecurityException, TransportException
Finds the release in the given repository by the release tag.- Specified by:
getReleaseByTagin interfaceReleaseService- Parameters:
owner- the name of the repository owner to get the release for. It may benull, in which case, the repository owner must be passed as a service option (see services implementing this interface for more details on the options they accept). If notnullthis value overrides the option passed to the service.repository- the name of the repository to get the release for. It may benull, in which case, the repository name must be passed as a service option (see services implementing this interface for more details on the options they accept). If notnullthis value overrides the option passed to the service.tag- the tag the release refers to (i.e.1.2.3,v4.5.6). It can't benull- Returns:
- the release for the given tag, or
nullif there is no such release - Throws:
SecurityException- if authentication or authorization failsTransportException- if communication to the remote endpoint fails
-
publishRelease
public GitLabRelease publishRelease(String owner, String repository, String title, String tag, String description) throws SecurityException, TransportException
Publishes a new release.- Specified by:
publishReleasein interfaceReleaseService- Parameters:
owner- the name of the repository owner to create the release for. It may benull, in which case, the repository owner must be passed as a service option (see services implementing this interface for more details on the options they accept). If notnullthis value overrides the option passed to the service.repository- the name of the repository to create the release for. It may benull, in which case, the repository name must be passed as a service option (see services implementing this interface for more details on the options they accept). If notnullthis value overrides the option passed to the service.title- the release title, it may be the same oftagbut not necessarily. It may benulltag- tag to publish the release for (i.e.1.2.3,v4.5.6). It can't benulldescription- the release description. This is usually a Markdown text containing release notes or a changelog or something like that giving an overall description of the release- Returns:
- the newly created release
- Throws:
SecurityException- if authentication or authorization failsTransportException- if communication to the remote endpoint fails
-
publishReleaseAssets
public GitLabRelease publishReleaseAssets(String owner, String repository, Release release, Set<Attachment> assets) throws SecurityException, TransportException
Publishes a set of assets for a release. Even when the service supports theService.Feature.RELEASE_ASSETSfeature not all types of assets may be supported. Please check the implementation class for any restrictions on the supported assets.- Specified by:
publishReleaseAssetsin interfaceReleaseService- Parameters:
owner- the name of the repository owner to create the assets for. It may benull, in which case, the repository owner must be passed as a service option (see services implementing this interface for more details on the options they accept). If notnullthis value overrides the option passed to the service.repository- the name of the repository to create the assets for. It may benull, in which case, the repository name must be passed as a service option (see services implementing this interface for more details on the options they accept). If notnullthis value overrides the option passed to the service.release- the release to publish the assets for. It must be an object created by the same service implementationassets- the set of assets to publish. Assets may be interpreted differently depending on theirpathandtype. Please check the implementation class for restrictions on the supported assets- Returns:
- the given release with also the links to the uploaded assets. The returned object represents the same release provided as parameter but may be a different instance. Only the assets that were actually published are returned while those not supported by the implementing service are not within the list of assets referred by the returned object
- Throws:
SecurityException- if authentication or authorization failsTransportException- if communication to the remote endpoint fails
-
supports
public boolean supports(Service.Feature feature)
Safely checks if the underlying implementation supports the given operation. If this method returnstruethen the underlying class will not raise anyUnsupportedOperationExceptionwhen invoking the specific methods.
-
-