Commit c2f3c1b2 authored by 六幻's avatar 六幻
Browse files
parents 302c26f7 be334cb3
......@@ -23,6 +23,7 @@ MergeRequestApi
ProjectApi
RepositoryApi
RepositoryFileApi
ServicesApi
SessionApi
UserApi
```
......@@ -63,6 +64,12 @@ RepositoryFileApi:
RepositoryFile file = gitLabApi.getRepositoryFileApi().getFile("file-path", 1234, "ref");
```
ServicesApi:
```java
// Activates the gitlab-ci service.
getLabApi.getServicesApi().setGitLabCI("project-name", "auth-token", "project-ci-url");
```
SessionApi:
```java
// Log in to the GitLab server and get the session info
......
......@@ -5,7 +5,7 @@
<groupId>com.messners</groupId>
<artifactId>gitlab-api</artifactId>
<packaging>jar</packaging>
<version>2.0.2-SNAPSHOT</version>
<version>2.0.5-SNAPSHOT</version>
<name>gitlab-api</name>
<description>GitLab API provides a full featured Java API for working with GitLab repositories via the GitLab REST API</description>
<url>http://www.messners.com/#gitlab-api/gitlab-api.html</url>
......
package com.messners.gitlab.api;
/**
* This class is provides a simplified interface to a GitLab API server, and divides the API up into
* a separate API class for each concern.
......@@ -8,119 +7,113 @@ package com.messners.gitlab.api;
* @author Greg Messner <greg@messners.com>
*/
public class GitLabApi {
GitLabApiClient apiClient;
private CommitsApi commitsApi;
private GroupApi groupApi;
private MergeRequestApi mergeRequestApi;
private ProjectApi projectApi;
private RepositoryApi repositoryApi;
private SessionApi sessoinApi;
private UserApi userApi;
private RepositoryFileApi repositoryFileApi;
/**
* Logs into GitLab using provided {@code username} and {@code password}, and creates a new
* {@code GitLabApi} instance using returned private token
* @param url GitLab URL
* @param username user name for which private token should be obtained
* @param password password for a given {@code username}
* @return new {@code GitLabApi} instance configured for a user-specific token
*/
static public GitLabApi create(String url, String username, String password) throws GitLabApiException {
String token = new SessionApi(new GitLabApi(url, null)).login(username, null, password).getPrivateToken();
return new GitLabApi(url, token);
}
GitLabApiClient apiClient;
private CommitsApi commitsApi;
private GroupApi groupApi;
private MergeRequestApi mergeRequestApi;
private ProjectApi projectApi;
private RepositoryApi repositoryApi;
private RepositoryFileApi repositoryFileApi;
private ServicesApi servicesApi;
private SessionApi sessoinApi;
private UserApi userApi;
/**
* Logs into GitLab using provided {@code username} and {@code password}, and creates a new {@code GitLabApi} instance using returned private token
*
* @param url GitLab URL
* @param username user name for which private token should be obtained
* @param password password for a given {@code username}
* @return new {@code GitLabApi} instance configured for a user-specific token
*/
static public GitLabApi create(String url, String username, String password) throws GitLabApiException {
String token = new SessionApi(new GitLabApi(url, null)).login(username, null, password).getPrivateToken();
return new GitLabApi(url, token);
}
/**
* Constructs a GitLabApi instance set up to interact with the GitLab server
* specified by hostUrl.
*
* @param hostUrl
* @param privateToken
*/
public GitLabApi(String hostUrl, String privateToken) {
apiClient = new GitLabApiClient(hostUrl, privateToken);
commitsApi = new CommitsApi(this);
groupApi = new GroupApi(this);
mergeRequestApi = new MergeRequestApi(this);
projectApi = new ProjectApi(this);
repositoryApi = new RepositoryApi(this);
servicesApi = new ServicesApi(this);
sessoinApi = new SessionApi(this);
userApi = new UserApi(this);
repositoryFileApi = new RepositoryFileApi(this);
}
/**
* Constructs a GitLabApi instance set up to interact with the GitLab server
* specified by hostUrl.
*
* @param hostUrl
* @param privateToken
*/
public GitLabApi (String hostUrl, String privateToken) {
apiClient = new GitLabApiClient(hostUrl, privateToken);
commitsApi = new CommitsApi(this);
groupApi = new GroupApi(this);
mergeRequestApi = new MergeRequestApi(this);
projectApi = new ProjectApi(this);
repositoryApi = new RepositoryApi(this);
sessoinApi = new SessionApi(this);
userApi = new UserApi(this);
repositoryFileApi = new RepositoryFileApi(this);
}
/**
* Return the GitLabApiClient associated with this instance. This is used by all the sub API classes
* to communicate with the GitLab API.
*
* @return the GitLabApiClient associated with this instance
*/
GitLabApiClient getApiClient () {
return (apiClient);
}
/**
* Gets the CommitsApi instance owned by this GitLabApi instance. The CommitsApi is used
* to perform all commit related API calls.
*
* @return the CommitsApi instance owned by this GitLabApi instance
*/
public CommitsApi getCommitsApi () {
return (commitsApi);
}
/**
* Gets the MergeRequestApi instance owned by this GitLabApi instance. The MergeRequestApi is used
* to perform all merge request related API calls.
*
* @return the MergeRequestApi instance owned by this GitLabApi instance
*/
public MergeRequestApi getMergeRequestApi () {
return (mergeRequestApi);
}
/**
* Gets the GroupApi instance owned by this GitLabApi instance. The GroupApi is used
* to perform all group related API calls.
*
* @return the GroupApi instance owned by this GitLabApi instance
*/
public GroupApi getGroupApi () {
return (groupApi);
}
/**
* Return the GitLabApiClient associated with this instance. This is used by all the sub API classes
* to communicate with the GitLab API.
*
* @return the GitLabApiClient associated with this instance
*/
GitLabApiClient getApiClient() {
return (apiClient);
}
/**
* Gets the ProjectApi instance owned by this GitLabApi instance. The ProjectApi is used
* to perform all project related API calls.
*
* @return the ProjectApi instance owned by this GitLabApi instance
*/
public ProjectApi getProjectApi () {
return (projectApi);
}
/**
* Gets the RepositoryApi instance owned by this GitLabApi instance. The RepositoryApi is used
* to perform all repository related API calls.
*
* @return the RepositoryApi instance owned by this GitLabApi instance
*/
public RepositoryApi getRepositoryApi () {
return (repositoryApi);
}
/**
* Gets the CommitsApi instance owned by this GitLabApi instance. The CommitsApi is used
* to perform all commit related API calls.
*
* @return the CommitsApi instance owned by this GitLabApi instance
*/
public CommitsApi getCommitsApi() {
return (commitsApi);
}
/**
* Gets the MergeRequestApi instance owned by this GitLabApi instance. The MergeRequestApi is used
* to perform all merge request related API calls.
*
* @return the MergeRequestApi instance owned by this GitLabApi instance
*/
public MergeRequestApi getMergeRequestApi() {
return (mergeRequestApi);
}
/**
* Gets the RepositoryFileApi instance owned by this GitLabApi instance. The RepositoryFileApi is used
/**
* Gets the GroupApi instance owned by this GitLabApi instance. The GroupApi is used
* to perform all group related API calls.
*
* @return the GroupApi instance owned by this GitLabApi instance
*/
public GroupApi getGroupApi() {
return (groupApi);
}
/**
* Gets the ProjectApi instance owned by this GitLabApi instance. The ProjectApi is used
* to perform all project related API calls.
*
* @return the ProjectApi instance owned by this GitLabApi instance
*/
public ProjectApi getProjectApi() {
return (projectApi);
}
/**
* Gets the RepositoryApi instance owned by this GitLabApi instance. The RepositoryApi is used
* to perform all repository related API calls.
*
* @return the RepositoryApi instance owned by this GitLabApi instance
*/
public RepositoryApi getRepositoryApi() {
return (repositoryApi);
}
/**
* Gets the RepositoryFileApi instance owned by this GitLabApi instance. The RepositoryFileApi is used
* to perform all repository files related API calls.
*
* @return the RepositoryFileApi instance owned by this GitLabApi instance
......@@ -129,25 +122,33 @@ public class GitLabApi {
return repositoryFileApi;
}
/**
* Gets the ServicesApi instance owned by this GitLabApi instance. The ServicesApi is used
* to perform all services related API calls.
*
* @return the ServicesApi instance owned by this GitLabApi instance
*/
public ServicesApi getServicesApi() {
return (servicesApi);
}
/**
* Gets the SessionApi instance owned by this GitLabApi instance. The SessionApi is used
* to perform a login to the GitLab API.
*
* @return the SessionApi instance owned by this GitLabApi instance
*/
public SessionApi getSessionApi () {
return (sessoinApi);
}
/**
* Gets the UserApi instance owned by this GitLabApi instance. The UserApi is used
* to perform all user related API calls.
*
* @return the UserApi instance owned by this GitLabApi instance
*/
public UserApi getUserApi () {
return (userApi);
}
/**
* Gets the SessionApi instance owned by this GitLabApi instance. The SessionApi is used
* to perform a login to the GitLab API.
*
* @return the SessionApi instance owned by this GitLabApi instance
*/
public SessionApi getSessionApi() {
return (sessoinApi);
}
/**
* Gets the UserApi instance owned by this GitLabApi instance. The UserApi is used
* to perform all user related API calls.
*
* @return the UserApi instance owned by this GitLabApi instance
*/
public UserApi getUserApi() {
return (userApi);
}
}
......@@ -9,7 +9,6 @@ import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
import java.util.List;
/**
* This class provides an entry point to all the GitLab API repository calls.
*
......@@ -17,125 +16,120 @@ import java.util.List;
*/
public class RepositoryApi extends AbstractApi {
public RepositoryApi (GitLabApi gitLabApi) {
super(gitLabApi);
}
/**
* Get a list of repository branches from a project, sorted by name alphabetically.
*
* GET /projects/:id/repository/branches
*
* @param projectId
* @return the list of repository branches for mthe specified project ID
* @throws GitLabApiException
*/
public List<Branch> getBranches (Integer projectId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "repository", "branches");
return (response.readEntity(new GenericType<List<Branch>>() {}));
}
public RepositoryApi(GitLabApi gitLabApi) {
super(gitLabApi);
}
/**
* Get a single project repository branch.
*
* GET /projects/:id/repository/branches/:branch
*
* @param projectId
* @param branchName
* @return the branch info for the specified project ID/branch name pair
* @throws GitLabApiException
*/
public Branch getBranch (Integer projectId, String branchName) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "repository", "branches", branchName);
return (response.readEntity(Branch.class));
}
/**
* Get a list of repository branches from a project, sorted by name alphabetically.
*
* GET /projects/:id/repository/branches
*
* @param projectId
* @return the list of repository branches for the specified project ID
* @throws GitLabApiException
*/
public List<Branch> getBranches(Integer projectId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "repository", "branches");
return (response.readEntity(new GenericType<List<Branch>>() {
}));
}
/**
* Get a single project repository branch.
*
* GET /projects/:id/repository/branches/:branch
*
* @param projectId
* @param branchName
* @return the branch info for the specified project ID/branch name pair
* @throws GitLabApiException
*/
public Branch getBranch(Integer projectId, String branchName) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "repository", "branches", branchName);
return (response.readEntity(Branch.class));
}
/**
* Creates a branch for the project. Support as of version 6.8.x
*
* POST /projects/:id/repository/branches
*
* @param projectId the project to create the branch for
* @param branchName the name of the branch to create
* @param ref Source to create the branch from, can be an existing branch, tag or commit SHA
* @return the branch info for the created branch
* @throws GitLabApiException
*/
public Branch createBranch (Integer projectId, String branchName, String ref) throws GitLabApiException {
/**
* Creates a branch for the project. Support as of version 6.8.x
*
* POST /projects/:id/repository/branches
*
* @param projectId the project to create the branch for
* @param branchName the name of the branch to create
* @param ref Source to create the branch from, can be an existing branch, tag or commit SHA
* @return the branch info for the created branch
* @throws GitLabApiException
*/
public Branch createBranch(Integer projectId, String branchName, String ref) throws GitLabApiException {
Form formData = new Form();
formData.param("branch_name ", branchName);
formData.param("ref ", ref);
Response response = post(Response.Status.OK, formData, "projects", projectId, "repository", "branches");
return (response.readEntity(Branch.class));
}
/**
* Protects a single project repository branch. This is an idempotent function,
* protecting an already protected repository branch will not produce an error.
*
* PUT /projects/:id/repository/branches/:branch/protect
*
* @param projectId
* @param branchName
* @return the branch info for the protected branch
* @throws GitLabApiException
*/
public Branch protectBranch (Integer projectId, String branchName) throws GitLabApiException {
Response response = put(Response.Status.OK, null, "projects", projectId, "repository", "branches", branchName, "protect");
return (response.readEntity(Branch.class));
}
/**
* Unprotects a single project repository branch. This is an idempotent function, unprotecting an
* already unprotected repository branch will not produce an error.
*
* PUT /projects/:id/repository/branches/:branch/unprotect
*
* @param projectId
* @param branchName
* @return the branch info for the unprotected branch
* @throws GitLabApiException
*/
public Branch unprotectBranch (Integer projectId, String branchName) throws GitLabApiException {
Response response = put(Response.Status.OK, null, "projects", projectId, "repository", "branches", branchName, "unprotect");
return (response.readEntity(Branch.class));
}
/**
* Get a list of repository tags from a project, sorted by name in reverse alphabetical order.
*
* GET /projects/:id/repository/tags
*
* @param projectId
* @return the list of tags for the specified project ID
* @throws GitLabApiException
*/
public List<Tag> getTags (Integer projectId) throws GitLabApiException {
Response response = put(Response.Status.OK, null, "projects", projectId, "repository", "tags");
return (response.readEntity(new GenericType<List<Tag>>() {}));
}
/**
* Get a list of repository files and directories in a project.
*
* GET /projects/:id/repository/tree
*
* @param projectId
* @return a tree with the root directories and files of a project
* @throws GitLabApiException
*/
public List<TreeItem> getTree (Integer projectId) throws GitLabApiException {
return this.getTree(projectId, "/", "master");
}
/**
/**
* Protects a single project repository branch. This is an idempotent function,
* protecting an already protected repository branch will not produce an error.
*
* PUT /projects/:id/repository/branches/:branch/protect
*
* @param projectId
* @param branchName
* @return the branch info for the protected branch
* @throws GitLabApiException
*/
public Branch protectBranch(Integer projectId, String branchName) throws GitLabApiException {
Response response = put(Response.Status.OK, null, "projects", projectId, "repository", "branches", branchName, "protect");
return (response.readEntity(Branch.class));
}
/**
* Unprotects a single project repository branch. This is an idempotent function, unprotecting an
* already unprotected repository branch will not produce an error.
*
* PUT /projects/:id/repository/branches/:branch/unprotect
*
* @param projectId
* @param branchName
* @return the branch info for the unprotected branch
* @throws GitLabApiException
*/
public Branch unprotectBranch(Integer projectId, String branchName) throws GitLabApiException {
Response response = put(Response.Status.OK, null, "projects", projectId, "repository", "branches", branchName, "unprotect");
return (response.readEntity(Branch.class));
}
/**
* Get a list of repository tags from a project, sorted by name in reverse alphabetical order.
*
* GET /projects/:id/repository/tags
*
* @param projectId
* @return the list of tags for the specified project ID
* @throws GitLabApiException
*/
public List<Tag> getTags(Integer projectId) throws GitLabApiException {
Response response = put(Response.Status.OK, null, "projects", projectId, "repository", "tags");
return (response.readEntity(new GenericType<List<Tag>>() {
}));
}
/**
* Get a list of repository files and directories in a project.
*
* GET /projects/:id/repository/tree
*
* @param projectId
* @return a tree with the root directories and files of a project
* @throws GitLabApiException
*/
public List<TreeItem> getTree(Integer projectId) throws GitLabApiException {
return this.getTree(projectId, "/", "master");
}
/**
* Get a list of repository files and directories in a project.
*
* GET /projects/:id/repository/tree
......@@ -143,49 +137,52 @@ public class RepositoryApi extends AbstractApi {
* id (required) - The ID of a project
* path (optional) - The path inside repository. Used to get contend of subdirectories
* ref_name (optional) - The name of a repository branch or tag or if not given the default branch
*
* @param projectId
* @param filePath
* @param refName
* @return a tree with the directories and files of a project
* @throws GitLabApiException
*/
public List<TreeItem> getTree (Integer projectId, String filePath, String refName) throws GitLabApiException {
public List<TreeItem> getTree(Integer projectId, String filePath, String refName) throws GitLabApiException {
Form formData = new Form();
addFormParam(formData, "id", projectId, true);
addFormParam(formData, "path", filePath, false);
addFormParam(formData, "ref_name", refName, false);
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "repository", "tree");
return (response.readEntity(new GenericType<List<TreeItem>>() {}));
return (response.readEntity(new GenericType<List<TreeItem>>() {
}));
}
/**
* Get the raw file contents for a file by commit sha and path.
*
* GET /projects/:id/repository/blobs/:sha
*
* @param projectId
* @param commitOrBranchName
* @return a string with the file content for the specified file
* @throws GitLabApiException
*/
public String getRawFileContent(Integer projectId, String commitOrBranchName, String filepath) throws GitLabApiException {
Form formData = new Form();
addFormParam(formData, "filepath", filepath, true);
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "repository", "blobs", commitOrBranchName);
return (response.readEntity(String.class));
}
/**
* Get the raw file contents for a file by commit sha and path.
*
* GET /projects/:id/repository/blobs/:sha
*
* @param projectId
* @param commitOrBranchName
* @return a string with the file content for the specified file
* @throws GitLabApiException
*/
public String getRawFileContent (Integer projectId, String commitOrBranchName, String filepath) throws GitLabApiException {
Form formData = new Form();
addFormParam(formData, "filepath", filepath, true);
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "repository", "blobs", commitOrBranchName);
return (response.readEntity(String.class));
}
/**
* Get the raw file contents for a blob by blob SHA.
*
* GET /projects/:id/repository/raw_blobs/:sha
*
* @param projectId
* @param sha
* @return the raw file contents for the blob
* @throws GitLabApiException
*/
public String getRawBlobCotent(Integer projectId, String sha) throws GitLabApiException{
/**
* Get the raw file contents for a blob by blob SHA.
*
* GET /projects/:id/repository/raw_blobs/:sha
*
* @param projectId
* @param sha
* @return the raw file contents for the blob
* @throws GitLabApiException
*/
public String getRawBlobCotent(Integer projectId, String sha) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "repository", "raw_blobs", sha);
return (response.readEntity(String.class));
}
}
}
......@@ -5,7 +5,6 @@ import javax.ws.rs.core.Response;
import com.messners.gitlab.api.models.RepositoryFile;
/**
* This class provides an entry point to all the GitLab API repository files calls.
*
......@@ -13,95 +12,94 @@ import com.messners.gitlab.api.models.RepositoryFile;
*/
public class RepositoryFileApi extends AbstractApi {
public RepositoryFileApi (GitLabApi gitLabApi) {
super(gitLabApi);
}
public RepositoryFileApi(GitLabApi gitLabApi) {
super(gitLabApi);
}
/**
* Get file from repository
* Allows you to receive information about file in repository like name, size, content.
* Get file from repository. Allows you to receive information about file in repository like name, size, content.
* Note that file content is Base64 encoded.
*
* GET /projects/:id/repository/files
*
* @param file_path (required) - Full path to new file. Ex. lib/class.rb
* @param filePath (required) - Full path to new file. Ex. lib/class.rb
* @param projectId
* @param ref (required) - The name of branch, tag or commit
* @return
* @return a RepositoryFile instance with the file info
* @throws GitLabApiException
*/
public RepositoryFile getFile(String filePath, Integer projectId, String ref) throws GitLabApiException {
public RepositoryFile getFile(String filePath, Integer projectId, String ref) throws GitLabApiException {
Form form = new Form();
addFormParam(form, "file_path", filePath, true);
addFormParam(form, "ref", ref, true);
Response response = get(Response.Status.OK, form.asMap(),"projects", projectId, "repository", "files");
Response response = get(Response.Status.OK, form.asMap(), "projects", projectId, "repository", "files");
return (response.readEntity(RepositoryFile.class));
}
/**
* Create new file in repository
*
* POST /projects/:id/repository/files
*
* file_path (required) - Full path to new file. Ex. lib/class.rb
/**
* Create new file in repository
*
* POST /projects/:id/repository/files
*
* file_path (required) - Full path to new file. Ex. lib/class.rb
* branch_name (required) - The name of branch
* encoding (optional) - 'text' or 'base64'. Text is default.
* content (required) - File content
* commit_message (required) - Commit message
*
* @param file
* @param projectId
* @param branchName
* @param commitMessage
* @return
* @throws GitLabApiException
*/
public RepositoryFile createFile (RepositoryFile file, Integer projectId, String branchName, String commitMessage) throws GitLabApiException {
Form formData = file2form(file, branchName, commitMessage);
*
* @param file
* @param projectId
* @param branchName
* @param commitMessage
* @return a RepositoryFile instance with the created file info
* @throws GitLabApiException
*/
public RepositoryFile createFile(RepositoryFile file, Integer projectId, String branchName, String commitMessage) throws GitLabApiException {
Form formData = file2form(file, branchName, commitMessage);
Response response = post(Response.Status.CREATED, formData, "projects", projectId, "repository", "files");
return (response.readEntity(RepositoryFile.class));
}
/**
* Update existing file in repository
*
* PUT /projects/:id/repository/files
*
* file_path (required) - Full path to new file. Ex. lib/class.rb
/**
* Update existing file in repository
*
* PUT /projects/:id/repository/files
*
* file_path (required) - Full path to new file. Ex. lib/class.rb
* branch_name (required) - The name of branch
* encoding (optional) - 'text' or 'base64'. Text is default.
* content (required) - File content
* commit_message (required) - Commit message
*
* @param file
* @param projectId
* @param branchName
* @param commitMessage
* @return
* @throws GitLabApiException
*/
public RepositoryFile updateFile (RepositoryFile file, Integer projectId, String branchName, String commitMessage) throws GitLabApiException {
Form form = file2form(file, branchName, commitMessage);
* @param file
* @param projectId
* @param branchName
* @param commitMessage
* @return a RepositoryFile instance with the updated file info
* @throws GitLabApiException
*/
public RepositoryFile updateFile(RepositoryFile file, Integer projectId, String branchName, String commitMessage) throws GitLabApiException {
Form form = file2form(file, branchName, commitMessage);
Response response = put(Response.Status.OK, form.asMap(), "projects", projectId, "repository", "files");
return (response.readEntity(RepositoryFile.class));
}
/**
* Delete existing file in repository
*
* DELETE /projects/:id/repository/files
*
* file_path (required) - Full path to file. Ex. lib/class.rb
/**
* Delete existing file in repository
*
* DELETE /projects/:id/repository/files
*
* file_path (required) - Full path to file. Ex. lib/class.rb
* branch_name (required) - The name of branch
* commit_message (required) - Commit message
*
* @param filePath
* @param projectId
* @param branchName
* @param commitMessage
* @throws GitLabApiException
*/
public void deleteFile (String filePath, Integer projectId, String branchName, String commitMessage) throws GitLabApiException {
* @param filePath
* @param projectId
* @param branchName
* @param commitMessage
* @throws GitLabApiException
*/
public void deleteFile(String filePath, Integer projectId, String branchName, String commitMessage) throws GitLabApiException {
if (filePath == null) {
throw new RuntimeException("filePath cannot be null");
......@@ -114,13 +112,13 @@ public class RepositoryFileApi extends AbstractApi {
delete(Response.Status.OK, form.asMap(), "projects", projectId, "repository", "files");
}
private Form file2form(RepositoryFile file, String branchName, String commitMessage){
Form form = new Form();
addFormParam(form, "file_path", file.getFilePath(), true);
addFormParam(form, "branch_name", branchName, true);
addFormParam(form, "encoding", file.getEncoding(), false);
addFormParam(form, "content", file.getContent(), true);
addFormParam(form, "commit_message", commitMessage, true);
return form;
}
private Form file2form(RepositoryFile file, String branchName, String commitMessage) {
Form form = new Form();
addFormParam(form, "file_path", file.getFilePath(), true);
addFormParam(form, "branch_name", branchName, true);
addFormParam(form, "encoding", file.getEncoding(), false);
addFormParam(form, "content", file.getContent(), true);
addFormParam(form, "commit_message", commitMessage, true);
return form;
}
}
package com.messners.gitlab.api;
import com.messners.gitlab.api.models.Project;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.Response;
/**
* Access for the services API.
* See
* <a href="https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/services.md">GitLab documentation</a>.
* It is quite restricted as you may not retrieve the API but only set or delete.
*/
public class ServicesApi extends AbstractApi {
public ServicesApi(GitLabApi gitLabApi) {
super(gitLabApi);
}
/**
* Activates the gitlab-ci service.
*
* PUT /projects/:id/services/gitlab-ci
* @param projectId id of the project
* @param token for authentication
* @param projectCIUrl URL of the GitLab-CI project
*/
public void setGitLabCI(Integer projectId, String token, String projectCIUrl) throws GitLabApiException {
final Form formData = new Form();
formData.param("token", token);
formData.param("project_url", projectCIUrl);
put(Response.Status.OK, formData.asMap(), "projects", projectId, "services", "gitlab-ci");
}
/**
* Activates the gitlab-ci service.
*
* PUT /projects/:id/services/gitlab-ci
* @param project the project
* @param token for authentication
* @param projectCIUrl URL of the GitLab-CI project
*/
public void setGitLabCI(Project project, String token, String projectCIUrl) throws GitLabApiException {
setGitLabCI(project.getId(), token, projectCIUrl);
}
/**
* Deletes the gitlab-ci service.
*
* DELETE /projects/:id/services/gitlab-ci
*
* @param projectId id of the project
* @throws GitLabApiException
*/
public void deleteGitLabCI(Integer projectId) throws GitLabApiException {
delete(Response.Status.OK, null, "projects", projectId, "services", "gitlab-ci");
}
/**
* DELETE /projects/:id/services/gitlab-ci
* @param project to delete
* @throws GitLabApiException
*/
public void deleteGitLabCI(Project project) throws GitLabApiException {
deleteGitLabCI(project.getId());
}
/**
* Activates HipChat notifications.
*
* PUT /projects/:id/services/hipchat
*
* @param projectId id of the project
* @param token for authentication
* @param room HipChat Room
* @param server HipChat Server URL
*
* @throws GitLabApiException
*/
public void setHipChat(Integer projectId, String token, String room, String server) throws GitLabApiException {
final Form formData = new Form();
formData.param("token", token);
formData.param("room", room);
formData.param("server", server);
put(Response.Status.OK, formData.asMap(), "projects", projectId, "services", "hipchat");
}
/**
* Activates HipChat notifications.
*
* PUT /projects/:id/services/hipchat
*
* @param project
* @param token
* @param room
* @param server
* @throws GitLabApiException
*/
public void setHipChat(Project project, String token, String room, String server) throws GitLabApiException {
setHipChat(project.getId(), token, room, server);
}
/**
* Deletes the gitlab-ci service.
*
* DELETE /projects/:id/services/hipchat
*
* @param projectId id of the project
* @throws GitLabApiException
*/
public void deleteHipChat(Integer projectId) throws GitLabApiException {
delete(Response.Status.OK, null, "projects", projectId, "services", "hipchat");
}
/**
* Deletes the gitlab-ci service.
*
* DELETE /projects/:id/services/hipchat
*
* @param project the project
* @throws GitLabApiException
*/
public void deleteHipChat(Project project) throws GitLabApiException {
deleteHipChat(project.getId());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment