From a0512c604c0251ae892e2fb81a337cfe98a9887d Mon Sep 17 00:00:00 2001 From: Florian Baader Date: Tue, 26 Dec 2017 00:02:10 +0100 Subject: [PATCH 1/2] Introduced Job API --- src/main/java/org/gitlab/api/GitlabAPI.java | 744 ++++++++++-------- .../org/gitlab/api/models/GitlabPipeline.java | 5 + 2 files changed, 422 insertions(+), 327 deletions(-) create mode 100644 src/main/java/org/gitlab/api/models/GitlabPipeline.java diff --git a/src/main/java/org/gitlab/api/GitlabAPI.java b/src/main/java/org/gitlab/api/GitlabAPI.java index af933a77..1112f0f7 100644 --- a/src/main/java/org/gitlab/api/GitlabAPI.java +++ b/src/main/java/org/gitlab/api/GitlabAPI.java @@ -2,12 +2,14 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; - import org.gitlab.api.http.GitlabHTTPRequestor; import org.gitlab.api.http.Query; import org.gitlab.api.models.*; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.Serializable; +import java.io.UnsupportedEncodingException; import java.net.Proxy; import java.net.URL; import java.net.URLEncoder; @@ -125,9 +127,10 @@ public List getUsers() throws IOException { /** * Finds users by email address or username. + * * @param emailOrUsername Some portion of the email address or username * @return A non-null List of GitlabUser instances. If the search term is - * null or empty a List with zero GitlabUsers is returned. + * null or empty a List with zero GitlabUsers is returned. * @throws IOException */ public List findUsers(String emailOrUsername) throws IOException { @@ -176,7 +179,7 @@ public GitlabUser getUserViaSudo(String username) throws IOException { * @param isAdmin Is Admin * @param can_create_group Can Create Group * @param skip_confirmation Skip Confirmation - * @return A GitlabUser + * @return A GitlabUser * @throws IOException on gitlab api call error * @see http://doc.gitlab.com/ce/api/users.html */ @@ -208,16 +211,17 @@ public GitlabUser createUser(String email, String password, String username, return dispatch().to(tailUrl, GitlabUser.class); } - + /** * Create a new user. This may succeed only if the requester is an administrator. + * * @param request An object that represents the parameters for the request. * @return {@link GitlabUser} * @throws IOException on gitlab api call error */ public GitlabUser createUser(CreateUserRequest request) throws IOException { - String tailUrl = GitlabUser.USERS_URL + request.toQuery().toString(); - return dispatch().to(tailUrl, GitlabUser.class); + String tailUrl = GitlabUser.USERS_URL + request.toQuery().toString(); + return dispatch().to(tailUrl, GitlabUser.class); } @@ -356,7 +360,7 @@ public GitlabSSHKey getSSHKey(Integer keyId) throws IOException { /** * Delete a user * - * @param targetUserId The target User ID + * @param targetUserId The target User ID * @throws IOException on gitlab api call error */ public void deleteUser(Integer targetUserId) throws IOException { @@ -471,8 +475,8 @@ public GitlabGroup createGroup(String name, String path) throws IOException { /** * Creates a Group * - * @param name The name of the group - * @param path The path for the group + * @param name The name of the group + * @param path The path for the group * @param sudoUser The user to create the group on behalf of * @return The GitLab Group * @throws IOException on gitlab api call error @@ -488,7 +492,6 @@ public GitlabGroup createGroupViaSudo(String name, String path, GitlabUser sudoU * @param path The path for the group * @param ldapCn LDAP Group Name to sync with, null otherwise * @param ldapAccess Access level for LDAP group members, null otherwise - * * @return The GitLab Group * @throws IOException on gitlab api call error */ @@ -502,14 +505,13 @@ public GitlabGroup createGroup(String name, String path, String ldapCn, GitlabAc * * @param request An object that represents the parameters for the request. * @param sudoUser The user for whom we're creating the group - * * @return The GitLab Group * @throws IOException on gitlab api call error */ - public GitlabGroup createGroup(CreateGroupRequest request, GitlabUser sudoUser) throws IOException { + public GitlabGroup createGroup(CreateGroupRequest request, GitlabUser sudoUser) throws IOException { Query query = request.toQuery(); query.appendIf(PARAM_SUDO, sudoUser != null ? sudoUser.getId() : null); - + String tailUrl = GitlabGroup.URL + query.toString(); return dispatch().to(tailUrl, GitlabGroup.class); @@ -522,8 +524,7 @@ public GitlabGroup createGroup(CreateGroupRequest request, GitlabUser sudoUser) * @param path The path for the group * @param ldapCn LDAP Group Name to sync with, null otherwise * @param ldapAccess Access level for LDAP group members, null otherwise - * @param sudoUser The user to create the group on behalf of - * + * @param sudoUser The user to create the group on behalf of * @return The GitLab Group * @throws IOException on gitlab api call error */ @@ -541,7 +542,6 @@ public GitlabGroup createGroup(String name, String path, String ldapCn, GitlabAc * @param sudoUser The user to create the group on behalf of * @param parentId The id of a parent group; the new group will be its subgroup * @return The GitLab Group - * * @throws IOException on gitlab api call error */ public GitlabGroup createGroup(String name, String path, String ldapCn, GitlabAccessLevel ldapAccess, GitlabUser sudoUser, Integer parentId) throws IOException { @@ -632,7 +632,7 @@ public GitlabProject getProject(Serializable projectId) throws IOException { /** * use namespace & project name to get project */ - public GitlabProject getProject(String namespace, String projectName) throws IOException{ + public GitlabProject getProject(String namespace, String projectName) throws IOException { String tailUrl = GitlabProject.URL + "/" + sanitizeGroupId(namespace) + "%2F" + sanitizeProjectId(projectName); return retrieve().to(tailUrl, GitlabProject.class); } @@ -640,7 +640,7 @@ public GitlabProject getProject(String namespace, String projectName) throws IOE /* * use project id to get Project JSON */ - public String getProjectJson (Serializable projectId) throws IOException { + public String getProjectJson(Serializable projectId) throws IOException { String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId); return retrieve().to(tailUrl, String.class); } @@ -654,7 +654,6 @@ public String getProjectJson(String namespace, String projectName) throws IOExce } /** - * * Get a list of projects accessible by the authenticated user. * * @return A list of gitlab projects @@ -666,7 +665,6 @@ public List getProjects() throws IOException { } /** - * * Get a list of projects owned by the authenticated user. * * @return A list of gitlab projects @@ -680,7 +678,6 @@ public List getOwnedProjects() throws IOException { } /** - * * Get a list of projects that the authenticated user is a member of. * * @return A list of gitlab projects @@ -694,7 +691,6 @@ public List getMembershipProjects() throws IOException { } /** - * * Get a list of projects starred by the authenticated user. * * @return A list of gitlab projects @@ -708,7 +704,6 @@ public List getStarredProjects() throws IOException { } /** - * * Get a list of projects accessible by the authenticated user. * * @return A list of gitlab projects @@ -748,7 +743,6 @@ public GitlabUpload uploadFile(GitlabProject project, File file) throws IOExcept } /** - * * Gets a list of a project's jobs in Gitlab * * @param project the project @@ -760,7 +754,6 @@ public List getProjectJobs(GitlabProject project) throws IOException } /** - * * Gets a list of a project's jobs in Gitlab * * @param projectId the project id @@ -772,12 +765,92 @@ public List getProjectJobs(Integer projectId) throws IOException { return retrieve().getAll(tailUrl, GitlabJob[].class); } + /** + * Gets a list of project's jobs of the given pipeline in Gitlab * + * @param project the project + * @param pipelineId + * @return A list of project jobs + * @throws IOException + */ + public List getPipelineJobs(GitlabProject project, Integer pipelineId) throws IOException { + return getPipelineJobs(project.getId(), pipelineId); + } + + /** + * Gets a list of project's jobs of the given pipeline in Gitlab + * + * @param projectId + * @param pipelineId + * @return A list of project jobs + * @throws IOException + */ + public List getPipelineJobs(Integer projectId, Integer pipelineId) { + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabPipeline.URL + "/" + sanitizeId(pipelineId, "PipelineID") + GitlabJob.URL + PARAM_MAX_ITEMS_PER_PAGE; + return retrieve().getAll(tailUrl, GitlabJob[].class); + } + + + /** + * Cancel a single job of a project + * + * @param projectId + * @param jobId + * @return + * @throws IOException + */ + public GitlabJob cancelJob(Integer projectId, Integer jobId) throws IOException { + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabJob.URL + "/" + sanitizeId(jobId, "JobID") + "/cancel"; + return dispatch().to(tailUrl, GitlabJob.class); + } + + /** + * Retry a single job of a project + * + * @param projectId + * @param jobId + * @return + * @throws IOException + */ + public GitlabJob retryJob(Integer projectId, Integer jobId) throws IOException { + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabJob.URL + "/" + sanitizeId(jobId, "JobID") + "/retry"; + return dispatch().to(tailUrl, GitlabJob.class); + } + + /** + * Erase a single job of a project (remove job artifacts and a job trace) + * + * @param projectId + * @param jobId + * @return + * @throws IOException + */ + public GitlabJob eraseJob(Integer projectId, Integer jobId) throws IOException { + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabJob.URL + "/" + sanitizeId(jobId, "JobID") + "/erase"; + return dispatch().to(tailUrl, GitlabJob.class); + } + + + /** + * Triggers a manual action to start a job. + * + * @param projectId + * @param jobId + * @return + * @throws IOException + */ + public GitlabJob playJob(Integer projectId, Integer jobId) throws IOException { + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabJob.URL + "/" + sanitizeId(jobId, "JobID") + "/play"; + return dispatch().to(tailUrl, GitlabJob.class); + } + + + /** * Gets a build for a project * * @param projectId the project id - * @param jobId the build id + * @param jobId the build id * @return A list of project jobs * @throws IOException */ @@ -790,7 +863,7 @@ public GitlabJob getProjectJob(Integer projectId, Integer jobId) throws IOExcept * Get build artifacts of a project build * * @param project The Project - * @param job The build + * @param job The build * @throws IOException on gitlab api call error */ public byte[] getJobArtifact(GitlabProject project, GitlabJob job) throws IOException { @@ -801,7 +874,7 @@ public byte[] getJobArtifact(GitlabProject project, GitlabJob job) throws IOExce * Get build artifacts of a project build * * @param projectId The Project's Id - * @param jobId The build's Id + * @param jobId The build's Id * @throws IOException on gitlab api call error */ public byte[] getJobArtifact(Integer projectId, Integer jobId) throws IOException { @@ -813,7 +886,7 @@ public byte[] getJobArtifact(Integer projectId, Integer jobId) throws IOExceptio * Get build trace of a project build * * @param project The Project - * @param job The build + * @param job The build * @throws IOException on gitlab api call error */ public byte[] getJobTrace(GitlabProject project, GitlabJob job) throws IOException { @@ -824,7 +897,7 @@ public byte[] getJobTrace(GitlabProject project, GitlabJob job) throws IOExcepti * Get build trace of a project build * * @param projectId The Project's Id - * @param jobId The build's Id + * @param jobId The build's Id * @throws IOException on gitlab api call error */ public byte[] getJobTrace(Integer projectId, Integer jobId) throws IOException { @@ -868,7 +941,7 @@ public GitlabProject createProject(GitlabProject project) throws IOException { GitlabNamespace namespace = project.getNamespace(); if (namespace != null) { - query.appendIf("namespace_id", namespace.getId()); + query.appendIf("namespace_id", namespace.getId()); } @@ -916,10 +989,10 @@ public GitlabProject createProjectForGroup(String name, GitlabGroup group, Strin /** * Creates a group Project * - * @param name The name of the project - * @param group The group for which the project should be crated - * @param description The project description - * @param visibility The project visibility level (private: 0, internal: 10, public: 20) + * @param name The name of the project + * @param group The group for which the project should be crated + * @param description The project description + * @param visibility The project visibility level (private: 0, internal: 10, public: 20) * @return The GitLab Project * @throws IOException on gitlab api call error */ @@ -1046,24 +1119,23 @@ public GitlabProject createFork(String namespace, GitlabProject gitlabProject) t * @param mergeRequestsEnabled Whether Merge Requests should be enabled, otherwise null indicates to use GitLab default * @param wikiEnabled Whether a Wiki should be enabled, otherwise null indicates to use GitLab default * @param snippetsEnabled Whether Snippets should be enabled, otherwise null indicates to use GitLab default - * @param visibility The visibility level of the project, otherwise null indicates to use GitLab default + * @param visibility The visibility level of the project, otherwise null indicates to use GitLab default * @return the Gitlab Project * @throws IOException on gitlab api call error */ @Deprecated public GitlabProject updateProject( Integer projectId, - String name, - String description, - String defaultBranch, + String name, + String description, + String defaultBranch, Boolean issuesEnabled, Boolean wallEnabled, Boolean mergeRequestsEnabled, Boolean wikiEnabled, Boolean snippetsEnabled, String visibility) - throws IOException - { + throws IOException { Query query = new Query() .appendIf("name", name) .appendIf("description", description) @@ -1191,17 +1263,17 @@ public List getAllMergeRequests(GitlabProject project) throw * EE only. */ public GitlabMergeRequestApprovals getMergeRequestApprovals(GitlabMergeRequest mr) throws IOException { - String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(mr.getProjectId()) + - GitlabMergeRequest.URL + "/" + mr.getIid() + GitlabMergeRequestApprovals.URL; + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(mr.getProjectId()) + + GitlabMergeRequest.URL + "/" + mr.getIid() + GitlabMergeRequestApprovals.URL; return retrieve().to(tailUrl, GitlabMergeRequestApprovals.class); } /** * Cherry picks a commit. * - * @param projectId The id of the project - * @param sha The sha of the commit - * @param targetBranchName The branch on which the commit must be cherry-picked + * @param projectId The id of the project + * @param sha The sha of the commit + * @param targetBranchName The branch on which the commit must be cherry-picked * @return the commit of the cherry-pick. * @throws IOException on gitlab api call error */ @@ -1231,8 +1303,8 @@ public GitlabMergeRequest getMergeRequestByIid(Serializable projectId, Integer m /** * Return a Merge Request including its changes. * - * @param projectId The id of the project - * @param mergeRequestId The id of the merge request + * @param projectId The id of the project + * @param mergeRequestId The id of the merge request * @return the Gitlab Merge Request * @throws IOException on gitlab api call error */ @@ -1273,18 +1345,17 @@ public GitlabMergeRequest createMergeRequest(Serializable projectId, String sour } - /** * Updates a Merge Request * - * @param projectId The id of the project - * @param mergeRequestId The id of the merge request to update - * @param targetBranch The target branch of the merge request, otherwise null to leave it untouched - * @param assigneeId The id of the assignee, otherwise null to leave it untouched - * @param title The title of the merge request, otherwise null to leave it untouched - * @param description The description of the merge request, otherwise null to leave it untouched - * @param stateEvent The state (close|reopen|merge) of the merge request, otherwise null to leave it untouched - * @param labels A comma separated list of labels, otherwise null to leave it untouched + * @param projectId The id of the project + * @param mergeRequestId The id of the merge request to update + * @param targetBranch The target branch of the merge request, otherwise null to leave it untouched + * @param assigneeId The id of the assignee, otherwise null to leave it untouched + * @param title The title of the merge request, otherwise null to leave it untouched + * @param description The description of the merge request, otherwise null to leave it untouched + * @param stateEvent The state (close|reopen|merge) of the merge request, otherwise null to leave it untouched + * @param labels A comma separated list of labels, otherwise null to leave it untouched * @return the Merge Request * @throws IOException on gitlab api call error */ @@ -1305,8 +1376,8 @@ public GitlabMergeRequest updateMergeRequest(Serializable projectId, Integer mer } /** - * @param project The Project - * @param mergeRequestId Merge Request ID + * @param project The Project + * @param mergeRequestId Merge Request ID * @param mergeCommitMessage optional merge commit message. Null if not set * @return new merge request status * @throws IOException on gitlab api call error @@ -1324,8 +1395,8 @@ public GitlabMergeRequest acceptMergeRequest(GitlabProject project, Integer merg /** * Get a Note from a Merge Request. * - * @param mergeRequest The merge request - * @param noteId The id of the note + * @param mergeRequest The merge request + * @param noteId The id of the note * @return the Gitlab Note * @throws IOException on gitlab api call error */ @@ -1497,9 +1568,9 @@ public GitlabCommitStatus createCommitStatus(GitlabProject project, String commi /** * Get raw file content * - * @param project The Project - * @param sha The commit or branch name - * @param filepath The path of the file + * @param project The Project + * @param sha The commit or branch name + * @param filepath The path of the file * @throws IOException on gitlab api call error */ public byte[] getRawFileContent(GitlabProject project, String sha, String filepath) throws IOException { @@ -1510,8 +1581,8 @@ public byte[] getRawFileContent(GitlabProject project, String sha, String filepa * Get raw file content * * @param projectId The Project - * @param sha The commit or branch name - * @param filepath The path of the file + * @param sha The commit or branch name + * @param filepath The path of the file * @throws IOException on gitlab api call error */ public byte[] getRawFileContent(Integer projectId, String sha, String filepath) throws IOException { @@ -1526,7 +1597,7 @@ public byte[] getRawFileContent(Integer projectId, String sha, String filepath) * Get the raw file contents for a blob by blob SHA. * * @param project The Project - * @param sha The commit or branch name + * @param sha The commit or branch name * @throws IOException on gitlab api call error */ public byte[] getRawBlobContent(GitlabProject project, String sha) throws IOException { @@ -1549,8 +1620,8 @@ public byte[] getFileArchive(GitlabProject project) throws IOException { * Get an archive of the repository * * @param project The Project - * @param path The path inside the repository. Used to get content of subdirectories (optional) - * @param ref The name of a repository branch or tag or if not given the default branch (optional) + * @param path The path inside the repository. Used to get content of subdirectories (optional) + * @param ref The name of a repository branch or tag or if not given the default branch (optional) * @throws IOException on gitlab api call error */ public List getRepositoryTree(GitlabProject project, String path, String ref, boolean recursive) throws IOException { @@ -1561,7 +1632,7 @@ public List getRepositoryTree(GitlabProject project, Strin String tailUrl = GitlabProject.URL + "/" + project.getId() + "/repository" + GitlabRepositoryTree.URL + query.toString(); return retrieve().getAll(tailUrl, GitlabRepositoryTree[].class); - } + } public GitlabRepositoryFile getRepositoryFile(GitlabProject project, String path, String ref) throws IOException { Query query = new Query() @@ -1574,11 +1645,11 @@ public GitlabRepositoryFile getRepositoryFile(GitlabProject project, String path /** * Creates a new file in the repository * - * @param project The Project - * @param path The file path inside the repository + * @param project The Project + * @param path The file path inside the repository * @param branchName The name of a repository branch - * @param commitMsg The commit message - * @param content The base64 encoded content of the file + * @param commitMsg The commit message + * @param content The base64 encoded content of the file * @throws IOException on gitlab api call error */ public GitlabSimpleRepositoryFile createRepositoryFile(GitlabProject project, String path, String branchName, String commitMsg, String content) throws IOException { @@ -1586,21 +1657,21 @@ public GitlabSimpleRepositoryFile createRepositoryFile(GitlabProject project, St GitlabHTTPRequestor requestor = dispatch(); return requestor - .with("branch", branchName) - .with("encoding", "base64") - .with("commit_message", commitMsg) - .with("content", content) - .to(tailUrl, GitlabSimpleRepositoryFile.class); + .with("branch", branchName) + .with("encoding", "base64") + .with("commit_message", commitMsg) + .with("content", content) + .to(tailUrl, GitlabSimpleRepositoryFile.class); } /** * Updates the content of an existing file in the repository * - * @param project The Project - * @param path The file path inside the repository + * @param project The Project + * @param path The file path inside the repository * @param branchName The name of a repository branch - * @param commitMsg The commit message - * @param content The base64 encoded content of the file + * @param commitMsg The commit message + * @param content The base64 encoded content of the file * @throws IOException on gitlab api call error */ public GitlabSimpleRepositoryFile updateRepositoryFile(GitlabProject project, String path, String branchName, String commitMsg, String content) throws IOException { @@ -1608,26 +1679,26 @@ public GitlabSimpleRepositoryFile updateRepositoryFile(GitlabProject project, St GitlabHTTPRequestor requestor = retrieve().method("PUT"); return requestor - .with("branch", branchName) - .with("encoding", "base64") - .with("commit_message", commitMsg) - .with("content", content) - .to(tailUrl, GitlabSimpleRepositoryFile.class); + .with("branch", branchName) + .with("encoding", "base64") + .with("commit_message", commitMsg) + .with("content", content) + .to(tailUrl, GitlabSimpleRepositoryFile.class); } /** * Deletes an existing file in the repository * - * @param project The Project - * @param path The file path inside the repository + * @param project The Project + * @param path The file path inside the repository * @param branchName The name of a repository branch - * @param commitMsg The commit message + * @param commitMsg The commit message * @throws IOException on gitlab api call error */ public void deleteRepositoryFile(GitlabProject project, String path, String branchName, String commitMsg) throws IOException { Query query = new Query() - .append("branch", branchName) - .append("commit_message", commitMsg); + .append("branch", branchName) + .append("commit_message", commitMsg); String tailUrl = GitlabProject.URL + "/" + project.getId() + "/repository/files/" + sanitizePath(path) + query.toString(); retrieve().method("DELETE").to(tailUrl, Void.class); } @@ -1635,9 +1706,9 @@ public void deleteRepositoryFile(GitlabProject project, String path, String bran /** * Update a Merge Request Note * - * @param mergeRequest The merge request - * @param noteId The id of the note - * @param body The content of the note + * @param mergeRequest The merge request + * @param noteId The id of the note + * @param body The content of the note * @return the Gitlab Note * @throws IOException on gitlab api call error */ @@ -1661,15 +1732,15 @@ public GitlabNote createNote(GitlabMergeRequest mergeRequest, String body) throw /** * Delete a Merge Request Note * - * @param mergeRequest The merge request - * @param noteToDelete The note to delete + * @param mergeRequest The merge request + * @param noteToDelete The note to delete * @throws IOException on gitlab api call error */ public void deleteNote(GitlabMergeRequest mergeRequest, GitlabNote noteToDelete) throws IOException { - String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() + GitlabMergeRequest.URL + "/" - + mergeRequest.getIid() + GitlabNote.URL + "/" + noteToDelete.getId(); - retrieve().method("DELETE").to(tailUrl, GitlabNote.class); - } + String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() + GitlabMergeRequest.URL + "/" + + mergeRequest.getIid() + GitlabNote.URL + "/" + noteToDelete.getId(); + retrieve().method("DELETE").to(tailUrl, GitlabNote.class); + } public List getBranches(Serializable projectId) throws IOException { String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabBranch.URL + PARAM_MAX_ITEMS_PER_PAGE; @@ -1684,12 +1755,12 @@ public List getBranches(GitlabProject project) throws IOException /** * Create Branch. * - * Create Repository Branch Documentation + * Create Repository Branch Documentation * * - * @param project The gitlab project + * @param project The gitlab project * @param branchName The name of the branch to create - * @param ref The branch name or commit SHA to create branch from + * @param ref The branch name or commit SHA to create branch from * @throws IOException on gitlab api call error */ public void createBranch(GitlabProject project, String branchName, String ref) throws IOException { @@ -1699,13 +1770,12 @@ public void createBranch(GitlabProject project, String branchName, String ref) t /** * Create Branch. * - * Create Repository Branch Documentation + * Create Repository Branch Documentation * * - * * @param projectId The id of the project * @param branchName The name of the branch to create - * @param ref The branch name or commit SHA to create branch from + * @param ref The branch name or commit SHA to create branch from * @throws IOException on gitlab api call error */ public void createBranch(Serializable projectId, String branchName, String ref) throws IOException { @@ -1731,7 +1801,7 @@ public GitlabBranch getBranch(Serializable projectId, String branchName) throws } public GitlabBranch getBranch(GitlabProject project, String branchName) throws IOException { - return getBranch(project.getId(),branchName); + return getBranch(project.getId(), branchName); } public void protectBranch(GitlabProject project, String branchName) throws IOException { @@ -1917,31 +1987,32 @@ public GitlabNote createNote(GitlabIssue issue, String message) throws IOExcepti /** * Delete an Issue Note * - * @param projectId The project id - * @param issueId The issue id - * @param noteToDelete The note to delete + * @param projectId The project id + * @param issueId The issue id + * @param noteToDelete The note to delete * @throws IOException on gitlab api call error */ - public void deleteNote(Serializable projectId, Integer issueId, GitlabNote noteToDelete) throws IOException { - String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) - + GitlabIssue.URL + "/" + issueId + GitlabNote.URL - + "/" + noteToDelete.getId(); - retrieve().method("DELETE").to(tailUrl, GitlabNote.class); - } + public void deleteNote(Serializable projectId, Integer issueId, GitlabNote noteToDelete) throws IOException { + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + + GitlabIssue.URL + "/" + issueId + GitlabNote.URL + + "/" + noteToDelete.getId(); + retrieve().method("DELETE").to(tailUrl, GitlabNote.class); + } - /** + /** * Delete an Issue Note * - * @param issue The issue - * @param noteToDelete The note to delete + * @param issue The issue + * @param noteToDelete The note to delete * @throws IOException on gitlab api call error */ - public void deleteNote(GitlabIssue issue, GitlabNote noteToDelete) throws IOException { - deleteNote(String.valueOf(issue.getProjectId()), issue.getId(), noteToDelete); - } + public void deleteNote(GitlabIssue issue, GitlabNote noteToDelete) throws IOException { + deleteNote(String.valueOf(issue.getProjectId()), issue.getId(), noteToDelete); + } /** * Gets labels associated with a project. + * * @param projectId The ID of the project. * @return A non-null list of labels. * @throws IOException @@ -1955,6 +2026,7 @@ public List getLabels(Serializable projectId) /** * Gets labels associated with a project. + * * @param project The project associated with labels. * @return A non-null list of labels. * @throws IOException @@ -1966,9 +2038,10 @@ public List getLabels(GitlabProject project) /** * Creates a new label. + * * @param projectId The ID of the project containing the new label. - * @param name The name of the label. - * @param color The color of the label (eg #ff0000). + * @param name The name of the label. + * @param color The color of the label (eg #ff0000). * @return The newly created label. * @throws IOException */ @@ -1978,14 +2051,15 @@ public GitlabLabel createLabel( String color) throws IOException { String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabLabel.URL; return dispatch().with("name", name) - .with("color", color) - .to(tailUrl, GitlabLabel.class); + .with("color", color) + .to(tailUrl, GitlabLabel.class); } /** * Creates a new label. + * * @param projectId The ID of the project containing the label. - * @param label The label to create. + * @param label The label to create. * @return The newly created label. */ public GitlabLabel createLabel(Serializable projectId, GitlabLabel label) @@ -1997,8 +2071,9 @@ public GitlabLabel createLabel(Serializable projectId, GitlabLabel label) /** * Deletes an existing label. + * * @param projectId The ID of the project containing the label. - * @param name The name of the label to delete. + * @param name The name of the label to delete. * @throws IOException */ public void deleteLabel(Serializable projectId, String name) @@ -2014,8 +2089,9 @@ public void deleteLabel(Serializable projectId, String name) /** * Deletes an existing label. + * * @param projectId The ID of the project containing the label. - * @param label The label to delete. + * @param label The label to delete. * @throws IOException */ public void deleteLabel(Serializable projectId, GitlabLabel label) @@ -2025,10 +2101,11 @@ public void deleteLabel(Serializable projectId, GitlabLabel label) /** * Updates an existing label. + * * @param projectId The ID of the project containing the label. - * @param name The name of the label to update. - * @param newName The updated name. - * @param newColor The updated color. + * @param name The name of the label to update. + * @param newName The updated name. + * @param newColor The updated color. * @return The updated, deserialized label. * @throws IOException */ @@ -2068,11 +2145,12 @@ public List getGroupMilestones(Serializable groupId) throws IOE /** * Cretaes a new project milestone. - * @param projectId The ID of the project. - * @param title The title of the milestone. + * + * @param projectId The ID of the project. + * @param title The title of the milestone. * @param description The description of the milestone. (Optional) - * @param dueDate The date the milestone is due. (Optional) - * @param startDate The start date of the milestone. (Optional) + * @param dueDate The date the milestone is due. (Optional) + * @param startDate The start date of the milestone. (Optional) * @return The newly created, de-serialized milestone. * @throws IOException */ @@ -2099,6 +2177,7 @@ public GitlabMilestone createMilestone( /** * Creates a new project milestone. + * * @param projectId The ID of the project. * @param milestone The milestone to create. * @return The newly created, de-serialized milestone. @@ -2116,14 +2195,15 @@ public GitlabMilestone createMilestone( /** * Updates an existing project milestone. - * @param projectId The ID of the project. + * + * @param projectId The ID of the project. * @param milestoneId The ID of the milestone. - * @param title The title of the milestone. (Optional) + * @param title The title of the milestone. (Optional) * @param description The description of the milestone. (Optional) - * @param dueDate The date the milestone is due. (Optional) - * @param startDate The start date of the milestone. (Optional) - * @param stateEvent A value used to update the state of the milestone. - * (Optional) (activate | close) + * @param dueDate The date the milestone is due. (Optional) + * @param startDate The start date of the milestone. (Optional) + * @param stateEvent A value used to update the state of the milestone. + * (Optional) (activate | close) * @return The updated, de-serialized milestone. * @throws IOException */ @@ -2161,8 +2241,9 @@ public GitlabMilestone updateMilestone( /** * Updates an existing project milestone. - * @param projectId The ID of the project. - * @param edited The already edited milestone. + * + * @param projectId The ID of the project. + * @param edited The already edited milestone. * @param stateEvent A value used to update the state of the milestone. * (Optional) (activate | close) * @return The updated, de-serialized milestone. @@ -2183,10 +2264,11 @@ public GitlabMilestone updateMilestone( /** * Updates an existing project milestone. - * @param edited The already edited milestone. - * @return The updated, de-serialized milestone. + * + * @param edited The already edited milestone. * @param stateEvent A value used to update the state of the milestone. * (Optional) (activate | close) + * @return The updated, de-serialized milestone. * @throws IOException */ public GitlabMilestone updateMilestone( @@ -2259,11 +2341,11 @@ public List getProjectMembers(GitlabProject project, Pagina } public List getProjectMembers(Serializable projectId) throws IOException { - return getProjectMembers(projectId, new Pagination()); + return getProjectMembers(projectId, new Pagination()); } public List getProjectMembers(Serializable projectId, Pagination pagination) throws IOException { - String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabProjectMember.URL + pagination.asQuery(); + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabProjectMember.URL + pagination.asQuery(); return Arrays.asList(retrieve().to(tailUrl, GitlabProjectMember[].class)); } @@ -2271,7 +2353,7 @@ public List getProjectMembers(Serializable projectId, Pagin * This will fail, if the given namespace is a user and not a group * * @param namespace The namespace - * @return A list of Gitlab Project members + * @return A list of Gitlab Project members * @throws IOException on gitlab api call error */ public List getNamespaceMembers(GitlabNamespace namespace) throws IOException { @@ -2282,7 +2364,7 @@ public List getNamespaceMembers(GitlabNamespace namespace) * This will fail, if the given namespace is a user and not a group * * @param namespaceId Namespace ID - * @return A list of Gitlab Project members + * @return A list of Gitlab Project members * @throws IOException on gitlab api call error */ public List getNamespaceMembers(Integer namespaceId) throws IOException { @@ -2306,8 +2388,8 @@ public void transfer(Integer namespaceId, Integer projectId) throws IOException * Create a new deploy key for the project * * @param targetProjectId The id of the Gitlab project - * @param title The title of the ssh key - * @param key The public key + * @param title The title of the ssh key + * @param key The public key * @return The new GitlabSSHKey * @throws IOException on gitlab api call error */ @@ -2319,8 +2401,8 @@ public GitlabSSHKey createDeployKey(Integer targetProjectId, String title, Strin * Create a new deploy key for the project which can push. * * @param targetProjectId The id of the Gitlab project - * @param title The title of the ssh key - * @param key The public key + * @param title The title of the ssh key + * @param key The public key * @return The new GitlabSSHKey * @throws IOException on gitlab api call error */ @@ -2344,7 +2426,7 @@ private GitlabSSHKey createDeployKey(Integer targetProjectId, String title, Stri * Delete a deploy key for a project * * @param targetProjectId The id of the Gitlab project - * @param targetKeyId The id of the Gitlab ssh key + * @param targetKeyId The id of the Gitlab ssh key * @throws IOException on gitlab api call error */ public void deleteDeployKey(Integer targetProjectId, Integer targetKeyId) throws IOException { @@ -2435,7 +2517,7 @@ private String sanitizeId(Serializable id, String parameterName) { } } - private String sanitizePath(String branch){ + private String sanitizePath(String branch) { try { return URLEncoder.encode(branch, "UTF-8"); } catch (UnsupportedEncodingException e) { @@ -2446,45 +2528,45 @@ private String sanitizePath(String branch){ /** * Post comment to commit * - * @param projectId (required) - The ID of a project - * @param sha (required) - The name of a repository branch or tag or if not given the default branch - * @param note (required) - Text of comment - * @param path (optional) - The file path - * @param line (optional) - The line number - * @param line_type (optional) - The line type (new or old) - * @return A CommitComment + * @param projectId (required) - The ID of a project + * @param sha (required) - The name of a repository branch or tag or if not given the default branch + * @param note (required) - Text of comment + * @param path (optional) - The file path + * @param line (optional) - The line number + * @param line_type (optional) - The line type (new or old) + * @return A CommitComment * @throws IOException on gitlab api call error * @see http://doc.gitlab.com/ce/api/commits.html#post-comment-to-commit */ public CommitComment createCommitComment(Integer projectId, String sha, String note, - String path, String line, String line_type) throws IOException { + String path, String line, String line_type) throws IOException { - Query query = new Query() - .append("id", projectId.toString()) - .appendIf("sha", sha) - .appendIf("note", note) - .appendIf("path", path) - .appendIf("line", line) - .appendIf("line_type", line_type); - String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + "/repository/commits/" + sha + CommitComment.URL + query.toString(); + Query query = new Query() + .append("id", projectId.toString()) + .appendIf("sha", sha) + .appendIf("note", note) + .appendIf("path", path) + .appendIf("line", line) + .appendIf("line_type", line_type); + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + "/repository/commits/" + sha + CommitComment.URL + query.toString(); - return dispatch().to(tailUrl, CommitComment.class); + return dispatch().to(tailUrl, CommitComment.class); } /** * Get the comments of a commit * - * @param projectId (required) - The ID of a project - * @param sha (required) - The name of a repository branch or tag or if not given the default branch - * @return A CommitComment + * @param projectId (required) - The ID of a project + * @param sha (required) - The name of a repository branch or tag or if not given the default branch + * @return A CommitComment * @throws IOException on gitlab api call error * @see http://doc.gitlab.com/ce/api/commits.html#post-comment-to-commit */ public List getCommitComments(Integer projectId, String sha) throws IOException { - String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + "/repository/commits/" + sha + CommitComment.URL; + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + "/repository/commits/" + sha + CommitComment.URL; - return Arrays.asList(retrieve().to(tailUrl, CommitComment[].class)); + return Arrays.asList(retrieve().to(tailUrl, CommitComment[].class)); } /** @@ -2495,8 +2577,8 @@ public List getCommitComments(Integer projectId, String sha) thro * @throws IOException on gitlab api call error */ public List getTags(Serializable projectId) throws IOException { - String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabTag.URL + PARAM_MAX_ITEMS_PER_PAGE; - return retrieve().getAll(tailUrl, GitlabTag[].class); + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabTag.URL + PARAM_MAX_ITEMS_PER_PAGE; + return retrieve().getAll(tailUrl, GitlabTag[].class); } /** @@ -2507,8 +2589,8 @@ public List getTags(Serializable projectId) throws IOException { * @throws IOException on gitlab api call error */ public List getTags(GitlabProject project) throws IOException { - String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabTag.URL + PARAM_MAX_ITEMS_PER_PAGE; - return retrieve().getAll(tailUrl, GitlabTag[].class); + String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabTag.URL + PARAM_MAX_ITEMS_PER_PAGE; + return retrieve().getAll(tailUrl, GitlabTag[].class); } /** @@ -2523,13 +2605,13 @@ public List getTags(GitlabProject project) throws IOException { * @throws IOException on gitlab api call error */ public GitlabTag addTag(Serializable projectId, String tagName, String ref, String message, String releaseDescription) throws IOException { - String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabTag.URL; - return dispatch() - .with("tag_name", tagName ) - .with("ref", ref) - .with("message", message) - .with("release_description", releaseDescription) - .to(tailUrl, GitlabTag.class); + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabTag.URL; + return dispatch() + .with("tag_name", tagName) + .with("ref", ref) + .with("message", message) + .with("release_description", releaseDescription) + .to(tailUrl, GitlabTag.class); } /** @@ -2544,13 +2626,13 @@ public GitlabTag addTag(Serializable projectId, String tagName, String ref, Stri * @throws IOException on gitlab api call error */ public GitlabTag addTag(GitlabProject project, String tagName, String ref, String message, String releaseDescription) throws IOException { - String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabTag.URL; - return dispatch() - .with("tag_name", tagName ) - .with("ref", ref) - .with("message", message) - .with("release_description", releaseDescription) - .to(tailUrl, GitlabTag.class); + String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabTag.URL; + return dispatch() + .with("tag_name", tagName) + .with("ref", ref) + .with("message", message) + .with("release_description", releaseDescription) + .to(tailUrl, GitlabTag.class); } /** @@ -2561,8 +2643,8 @@ public GitlabTag addTag(GitlabProject project, String tagName, String ref, Strin * @throws IOException on gitlab api call error */ public void deleteTag(Serializable projectId, String tagName) throws IOException { - String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabTag.URL + "/" + tagName; - retrieve().method("DELETE").to(tailUrl, Void.class); + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabTag.URL + "/" + tagName; + retrieve().method("DELETE").to(tailUrl, Void.class); } /** @@ -2573,8 +2655,8 @@ public void deleteTag(Serializable projectId, String tagName) throws IOException * @throws IOException on gitlab api call error */ public void deleteTag(GitlabProject project, String tagName) throws IOException { - String tailUrl = GitlabProject.URL + "/" + project + GitlabTag.URL + "/" + tagName; - retrieve().method("DELETE").to(tailUrl, Void.class); + String tailUrl = GitlabProject.URL + "/" + project + GitlabTag.URL + "/" + tagName; + retrieve().method("DELETE").to(tailUrl, Void.class); } /** @@ -2583,12 +2665,12 @@ public void deleteTag(GitlabProject project, String tagName) throws IOException * @param mergeRequest * @throws IOException on gitlab api call error */ - public List getAllAwards(GitlabMergeRequest mergeRequest) throws IOException { - String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() + GitlabMergeRequest.URL + "/" - + mergeRequest.getIid() + GitlabAward.URL + PARAM_MAX_ITEMS_PER_PAGE; + public List getAllAwards(GitlabMergeRequest mergeRequest) throws IOException { + String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() + GitlabMergeRequest.URL + "/" + + mergeRequest.getIid() + GitlabAward.URL + PARAM_MAX_ITEMS_PER_PAGE; - return retrieve().getAll(tailUrl, GitlabAward[].class); - } + return retrieve().getAll(tailUrl, GitlabAward[].class); + } /** * Get a specific award for a merge request @@ -2597,12 +2679,12 @@ public List getAllAwards(GitlabMergeRequest mergeRequest) throws IO * @param awardId * @throws IOException on gitlab api call error */ - public GitlabAward getAward(GitlabMergeRequest mergeRequest, Integer awardId) throws IOException { - String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() + GitlabMergeRequest.URL + "/" - + mergeRequest.getIid() + GitlabAward.URL + "/" + awardId; + public GitlabAward getAward(GitlabMergeRequest mergeRequest, Integer awardId) throws IOException { + String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() + GitlabMergeRequest.URL + "/" + + mergeRequest.getIid() + GitlabAward.URL + "/" + awardId; - return retrieve().to(tailUrl, GitlabAward.class); - } + return retrieve().to(tailUrl, GitlabAward.class); + } /** * Create an award for a merge request @@ -2611,13 +2693,13 @@ public GitlabAward getAward(GitlabMergeRequest mergeRequest, Integer awardId) th * @param awardName * @throws IOException on gitlab api call error */ - public GitlabAward createAward(GitlabMergeRequest mergeRequest, String awardName) throws IOException { - Query query = new Query().append("name", awardName); - String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() + GitlabMergeRequest.URL + "/" - + mergeRequest.getIid() + GitlabAward.URL + query.toString(); + public GitlabAward createAward(GitlabMergeRequest mergeRequest, String awardName) throws IOException { + Query query = new Query().append("name", awardName); + String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() + GitlabMergeRequest.URL + "/" + + mergeRequest.getIid() + GitlabAward.URL + query.toString(); - return dispatch().to(tailUrl, GitlabAward.class); - } + return dispatch().to(tailUrl, GitlabAward.class); + } /** * Delete an award for a merge request @@ -2626,12 +2708,12 @@ public GitlabAward createAward(GitlabMergeRequest mergeRequest, String awardName * @param award * @throws IOException on gitlab api call error */ - public void deleteAward(GitlabMergeRequest mergeRequest, GitlabAward award) throws IOException { - String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() + GitlabMergeRequest.URL + "/" - + mergeRequest.getIid() + GitlabAward.URL + "/" + award.getId(); + public void deleteAward(GitlabMergeRequest mergeRequest, GitlabAward award) throws IOException { + String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() + GitlabMergeRequest.URL + "/" + + mergeRequest.getIid() + GitlabAward.URL + "/" + award.getId(); - retrieve().method("DELETE").to(tailUrl, Void.class); - } + retrieve().method("DELETE").to(tailUrl, Void.class); + } /** * Get all awards for an issue @@ -2639,12 +2721,12 @@ public void deleteAward(GitlabMergeRequest mergeRequest, GitlabAward award) thro * @param issue * @throws IOException on gitlab api call error */ - public List getAllAwards(GitlabIssue issue) throws IOException { - String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId() - + GitlabAward.URL + PARAM_MAX_ITEMS_PER_PAGE; + public List getAllAwards(GitlabIssue issue) throws IOException { + String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId() + + GitlabAward.URL + PARAM_MAX_ITEMS_PER_PAGE; - return retrieve().getAll(tailUrl, GitlabAward[].class); - } + return retrieve().getAll(tailUrl, GitlabAward[].class); + } /** * Get a specific award for an issue @@ -2653,12 +2735,12 @@ public List getAllAwards(GitlabIssue issue) throws IOException { * @param awardId * @throws IOException on gitlab api call error */ - public GitlabAward getAward(GitlabIssue issue, Integer awardId) throws IOException { - String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId() - + GitlabAward.URL + "/" + awardId; + public GitlabAward getAward(GitlabIssue issue, Integer awardId) throws IOException { + String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId() + + GitlabAward.URL + "/" + awardId; - return retrieve().to(tailUrl, GitlabAward.class); - } + return retrieve().to(tailUrl, GitlabAward.class); + } /** * Create an award for an issue @@ -2667,13 +2749,13 @@ public GitlabAward getAward(GitlabIssue issue, Integer awardId) throws IOExcepti * @param awardName * @throws IOException on gitlab api call error */ - public GitlabAward createAward(GitlabIssue issue, String awardName) throws IOException { - Query query = new Query().append("name", awardName); - String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId() - + GitlabAward.URL + query.toString(); + public GitlabAward createAward(GitlabIssue issue, String awardName) throws IOException { + Query query = new Query().append("name", awardName); + String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId() + + GitlabAward.URL + query.toString(); - return dispatch().to(tailUrl, GitlabAward.class); - } + return dispatch().to(tailUrl, GitlabAward.class); + } /** * Delete an award for an issue @@ -2682,25 +2764,25 @@ public GitlabAward createAward(GitlabIssue issue, String awardName) throws IOExc * @param award * @throws IOException on gitlab api call error */ - public void deleteAward(GitlabIssue issue, GitlabAward award) throws IOException { - String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId() - + GitlabAward.URL + "/" + award.getId(); - retrieve().method("DELETE").to(tailUrl, Void.class); - } + public void deleteAward(GitlabIssue issue, GitlabAward award) throws IOException { + String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId() + + GitlabAward.URL + "/" + award.getId(); + retrieve().method("DELETE").to(tailUrl, Void.class); + } - /** + /** * Get all awards for an issue note * * @param issue * @param noteId * @throws IOException on gitlab api call error */ - public List getAllAwards(GitlabIssue issue, Integer noteId) throws IOException { - String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId() - + GitlabNote.URL + noteId + GitlabAward.URL + PARAM_MAX_ITEMS_PER_PAGE; + public List getAllAwards(GitlabIssue issue, Integer noteId) throws IOException { + String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId() + + GitlabNote.URL + noteId + GitlabAward.URL + PARAM_MAX_ITEMS_PER_PAGE; - return retrieve().getAll(tailUrl, GitlabAward[].class); - } + return retrieve().getAll(tailUrl, GitlabAward[].class); + } /** * Get a specific award for an issue note @@ -2710,12 +2792,12 @@ public List getAllAwards(GitlabIssue issue, Integer noteId) throws * @param awardId * @throws IOException on gitlab api call error */ - public GitlabAward getAward(GitlabIssue issue, Integer noteId, Integer awardId) throws IOException { - String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId() - + GitlabNote.URL + noteId + GitlabAward.URL + "/" + awardId; + public GitlabAward getAward(GitlabIssue issue, Integer noteId, Integer awardId) throws IOException { + String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId() + + GitlabNote.URL + noteId + GitlabAward.URL + "/" + awardId; - return retrieve().to(tailUrl, GitlabAward.class); - } + return retrieve().to(tailUrl, GitlabAward.class); + } /** * Create an award for an issue note @@ -2725,15 +2807,15 @@ public GitlabAward getAward(GitlabIssue issue, Integer noteId, Integer awardId) * @param awardName * @throws IOException on gitlab api call error */ - public GitlabAward createAward(GitlabIssue issue, Integer noteId, String awardName) throws IOException { - Query query = new Query().append("name", awardName); - String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId() - + GitlabNote.URL + noteId + GitlabAward.URL + query.toString(); + public GitlabAward createAward(GitlabIssue issue, Integer noteId, String awardName) throws IOException { + Query query = new Query().append("name", awardName); + String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId() + + GitlabNote.URL + noteId + GitlabAward.URL + query.toString(); - return dispatch().to(tailUrl, GitlabAward.class); - } + return dispatch().to(tailUrl, GitlabAward.class); + } - /** + /** * Delete an award for an issue note * * @param issue @@ -2741,14 +2823,15 @@ public GitlabAward createAward(GitlabIssue issue, Integer noteId, String awardNa * @param award * @throws IOException on gitlab api call error */ - public void deleteAward(GitlabIssue issue, Integer noteId, GitlabAward award) throws IOException { - String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId() - + GitlabNote.URL + noteId + GitlabAward.URL + "/" + award.getId(); - retrieve().method("DELETE").to(tailUrl, Void.class); - } + public void deleteAward(GitlabIssue issue, Integer noteId, GitlabAward award) throws IOException { + String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/" + issue.getId() + + GitlabNote.URL + noteId + GitlabAward.URL + "/" + award.getId(); + retrieve().method("DELETE").to(tailUrl, Void.class); + } /** * Gets build variables associated with a project. + * * @param projectId The ID of the project. * @return A non-null list of variables. * @throws IOException @@ -2762,6 +2845,7 @@ public List getBuildVariables(Integer projectId) /** * Gets build variables associated with a project. + * * @param project The project associated with variables. * @return A non-null list of variables. * @throws IOException @@ -2773,8 +2857,9 @@ public List getBuildVariables(GitlabProject project) /** * Gets build variable associated with a project and key. + * * @param projectId The ID of the project. - * @param key The key of the variable. + * @param key The key of the variable. * @return A variable. * @throws IOException */ @@ -2789,6 +2874,7 @@ public GitlabBuildVariable getBuildVariable(Integer projectId, String key) /** * Gets build variable associated with a project and key. + * * @param project The project associated with the variable. * @return A variable. * @throws IOException @@ -2800,9 +2886,10 @@ public GitlabBuildVariable getBuildVariable(GitlabProject project, String key) /** * Creates a new build variable. + * * @param projectId The ID of the project containing the new variable. - * @param key The key of the variable. - * @param value The value of the variable + * @param key The key of the variable. + * @param value The value of the variable * @return The newly created variable. * @throws IOException */ @@ -2818,8 +2905,9 @@ public GitlabBuildVariable createBuildVariable( /** * Creates a new variable. + * * @param projectId The ID of the project containing the variable. - * @param variable The variable to create. + * @param variable The variable to create. * @return The newly created variable. */ public GitlabBuildVariable createBuildVariable(Integer projectId, GitlabBuildVariable variable) @@ -2831,8 +2919,9 @@ public GitlabBuildVariable createBuildVariable(Integer projectId, GitlabBuildVar /** * Deletes an existing variable. + * * @param projectId The ID of the project containing the variable. - * @param key The key of the variable to delete. + * @param key The key of the variable to delete. * @throws IOException */ public void deleteBuildVariable(Integer projectId, String key) @@ -2846,8 +2935,9 @@ public void deleteBuildVariable(Integer projectId, String key) /** * Deletes an existing variable. + * * @param projectId The ID of the project containing the variable. - * @param variable The variable to delete. + * @param variable The variable to delete. * @throws IOException */ public void deleteBuildVariable(Integer projectId, GitlabBuildVariable variable) @@ -2857,15 +2947,16 @@ public void deleteBuildVariable(Integer projectId, GitlabBuildVariable variable) /** * Updates an existing variable. + * * @param projectId The ID of the project containing the variable. - * @param key The key of the variable to update. - * @param newValue The updated value. + * @param key The key of the variable to update. + * @param newValue The updated value. * @return The updated, deserialized variable. * @throws IOException */ public GitlabBuildVariable updateBuildVariable(Integer projectId, - String key, - String newValue) throws IOException { + String key, + String newValue) throws IOException { String tailUrl = GitlabProject.URL + "/" + projectId + GitlabBuildVariable.URL + "/" + @@ -2889,7 +2980,7 @@ public List getPipelineTriggers(GitlabProject project) throws IOE if (!project.isJobsEnabled()) { // if the project has not allowed jobs, you will only get a 403 forbidden message which is // not helpful. - throw new IllegalStateException("Jobs are not enabled for " + project.getNameWithNamespace() ); + throw new IllegalStateException("Jobs are not enabled for " + project.getNameWithNamespace()); } else { return retrieve().getAll(GitlabProject.URL + "/" + project.getId() + GitlabTrigger.URL + PARAM_MAX_ITEMS_PER_PAGE, GitlabTrigger[].class); } @@ -2897,6 +2988,7 @@ public List getPipelineTriggers(GitlabProject project) throws IOE /** * Gets email-on-push service setup for a projectId. + * * @param projectId The ID of the project containing the variable. * @throws IOException */ @@ -2907,7 +2999,8 @@ public GitlabServiceEmailOnPush getEmailsOnPush(Integer projectId) throws IOExce /** * Update recipients for email-on-push service for a projectId. - * @param projectId The ID of the project containing the variable. + * + * @param projectId The ID of the project containing the variable. * @param emailAddress The emailaddress of the recipent who is going to receive push notification. * @return * @throws IOException @@ -2918,18 +3011,16 @@ public boolean updateEmailsOnPush(Integer projectId, String emailAddress) throws GitlabServiceEmailOnPush emailOnPush = this.getEmailsOnPush(projectId); GitlabEmailonPushProperties properties = emailOnPush.getProperties(); String appendedRecipients = properties.getRecipients(); - if(appendedRecipients != "") - { - if(appendedRecipients.contains(emailAddress)) - return true; - appendedRecipients = appendedRecipients + " " + emailAddress; - } - else - appendedRecipients = emailAddress; + if (appendedRecipients != "") { + if (appendedRecipients.contains(emailAddress)) + return true; + appendedRecipients = appendedRecipients + " " + emailAddress; + } else + appendedRecipients = emailAddress; Query query = new Query() - .appendIf("active", true) - .appendIf("recipients", appendedRecipients); + .appendIf("active", true) + .appendIf("recipients", appendedRecipients); tailUrl = GitlabProject.URL + "/" + projectId + GitlabServiceEmailOnPush.URL + query.toString(); return retrieve().method("PUT").to(tailUrl, Boolean.class); @@ -2943,9 +3034,9 @@ public boolean updateEmailsOnPush(Integer projectId, String emailAddress) throws * @return * @throws IOException */ - public GitlabServiceJira getJiraService(Integer projectId) throws IOException{ - String tailUrl = GitlabProject.URL+ "/" + projectId + GitlabServiceJira.URL; - return retrieve().to(tailUrl, GitlabServiceJira.class); + public GitlabServiceJira getJiraService(Integer projectId) throws IOException { + String tailUrl = GitlabProject.URL + "/" + projectId + GitlabServiceJira.URL; + return retrieve().to(tailUrl, GitlabServiceJira.class); } /** @@ -2956,58 +3047,57 @@ public GitlabServiceJira getJiraService(Integer projectId) throws IOException{ * @return * @throws IOException */ - public boolean deleteJiraService(Integer projectId) throws IOException{ - String tailUrl = GitlabProject.URL+ "/" + projectId + GitlabServiceJira.URL; - return retrieve().method("DELETE").to(tailUrl, Boolean.class); + public boolean deleteJiraService(Integer projectId) throws IOException { + String tailUrl = GitlabProject.URL + "/" + projectId + GitlabServiceJira.URL; + return retrieve().method("DELETE").to(tailUrl, Boolean.class); } /** * Set JIRA service for a project. * https://docs.gitlab.com/ce/api/services.html#create-edit-jira-service * - * @param projectId The ID of the project containing the variable. + * @param projectId The ID of the project containing the variable. * @param jiraPropties * @return * @throws IOException */ - public boolean createOrEditJiraService(Integer projectId, GitlabJiraProperties jiraPropties) throws IOException{ + public boolean createOrEditJiraService(Integer projectId, GitlabJiraProperties jiraPropties) throws IOException { - Query query = new Query() - .appendIf("url", jiraPropties.getUrl()) - .appendIf("project_key", jiraPropties.getProjectKey()); + Query query = new Query() + .appendIf("url", jiraPropties.getUrl()) + .appendIf("project_key", jiraPropties.getProjectKey()); - if(!jiraPropties.getUsername().isEmpty()){ - query.appendIf("username", jiraPropties.getUsername()); - } + if (!jiraPropties.getUsername().isEmpty()) { + query.appendIf("username", jiraPropties.getUsername()); + } - if(!jiraPropties.getPassword().isEmpty()){ - query.appendIf("password", jiraPropties.getPassword()); - } + if (!jiraPropties.getPassword().isEmpty()) { + query.appendIf("password", jiraPropties.getPassword()); + } - if(jiraPropties.getIssueTransitionId() != null){ - query.appendIf("jira_issue_transition_id", jiraPropties.getIssueTransitionId()); - } + if (jiraPropties.getIssueTransitionId() != null) { + query.appendIf("jira_issue_transition_id", jiraPropties.getIssueTransitionId()); + } - String tailUrl = GitlabProject.URL+ "/" + projectId + GitlabServiceJira.URL+ query.toString(); - return retrieve().method("PUT").to(tailUrl, Boolean.class); + String tailUrl = GitlabProject.URL + "/" + projectId + GitlabServiceJira.URL + query.toString(); + return retrieve().method("PUT").to(tailUrl, Boolean.class); } /** - * - * Get a list of projects accessible by the authenticated user by search. - * - * @return A list of gitlab projects - * @throws IOException - */ - public List searchProjects(String search) throws IOException { - Query query = new Query() - .append("search", search); - String tailUrl = GitlabProject.URL + query.toString(); - GitlabProject[] response = retrieve().to(tailUrl, GitlabProject[].class); - return Arrays.asList(response); - } + * Get a list of projects accessible by the authenticated user by search. + * + * @return A list of gitlab projects + * @throws IOException + */ + public List searchProjects(String search) throws IOException { + Query query = new Query() + .append("search", search); + String tailUrl = GitlabProject.URL + query.toString(); + GitlabProject[] response = retrieve().to(tailUrl, GitlabProject[].class); + return Arrays.asList(response); + } /** * Share a project with a group. @@ -3065,7 +3155,7 @@ public String getUserAgent() { } public GitlabVersion getVersion() throws IOException { - return retrieve().to("version",GitlabVersion.class); + return retrieve().to("version", GitlabVersion.class); } /** @@ -3088,7 +3178,7 @@ public List getRunners() throws IOException { public List getRunners(GitlabRunner.RunnerScope scope) throws IOException { StringBuilder tailUrl = new StringBuilder("runners/all"); Query query = new Query() - .appendIf("scope", scope.getScope()); + .appendIf("scope", scope.getScope()); tailUrl.append(query.toString()); return retrieve().getAll(tailUrl.toString(), GitlabRunner[].class); } diff --git a/src/main/java/org/gitlab/api/models/GitlabPipeline.java b/src/main/java/org/gitlab/api/models/GitlabPipeline.java new file mode 100644 index 00000000..acf8c254 --- /dev/null +++ b/src/main/java/org/gitlab/api/models/GitlabPipeline.java @@ -0,0 +1,5 @@ +package org.gitlab.api.models; + +public class GitlabPipeline { + public static final String URL = "/pipelines"; +} From 57c979b9f90147745c94763558196fa9f98bf6a0 Mon Sep 17 00:00:00 2001 From: Florian Baader Date: Tue, 26 Dec 2017 18:37:55 +0100 Subject: [PATCH 2/2] Add pipeline field of GitlabCommit --- .../org/gitlab/api/models/GitlabCommit.java | 15 +++++- .../org/gitlab/api/models/GitlabPipeline.java | 47 +++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gitlab/api/models/GitlabCommit.java b/src/main/java/org/gitlab/api/models/GitlabCommit.java index 0fb5812d..f99bc32f 100644 --- a/src/main/java/org/gitlab/api/models/GitlabCommit.java +++ b/src/main/java/org/gitlab/api/models/GitlabCommit.java @@ -1,10 +1,10 @@ package org.gitlab.api.models; +import com.fasterxml.jackson.annotation.JsonProperty; + import java.util.Date; import java.util.List; -import com.fasterxml.jackson.annotation.JsonProperty; - public class GitlabCommit { public final static String URL = "/commits"; @@ -34,6 +34,9 @@ public class GitlabCommit { @JsonProperty("parent_ids") private List parentIds; + @JsonProperty("last_pipeline") + private GitlabPipeline lastPipeline; + public String getId() { return id; } @@ -131,4 +134,12 @@ public boolean equals(Object obj) { public int hashCode() { return this.getId().hashCode(); } + + public GitlabPipeline getLastPipeline() { + return lastPipeline; + } + + public void setLastPipeline(GitlabPipeline lastPipeline) { + this.lastPipeline = lastPipeline; + } } diff --git a/src/main/java/org/gitlab/api/models/GitlabPipeline.java b/src/main/java/org/gitlab/api/models/GitlabPipeline.java index acf8c254..31927db5 100644 --- a/src/main/java/org/gitlab/api/models/GitlabPipeline.java +++ b/src/main/java/org/gitlab/api/models/GitlabPipeline.java @@ -1,5 +1,52 @@ package org.gitlab.api.models; +import com.fasterxml.jackson.annotation.JsonProperty; + public class GitlabPipeline { public static final String URL = "/pipelines"; + + + @JsonProperty("id") + private Integer id; + + @JsonProperty("ref") + private String ref; + + @JsonProperty("sha") + private String sha; + + @JsonProperty("status") + private String status; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getRef() { + return ref; + } + + public void setRef(String ref) { + this.ref = ref; + } + + public String getSha() { + return sha; + } + + public void setSha(String sha) { + this.sha = sha; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } }