Commit 71efa977 authored by timols's avatar timols

Updated code conventions to not use _ variables, fixed whitespace, resolved backwards compat issues

parent 3dbfade8
......@@ -3,29 +3,18 @@ package org.gitlab.api;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
import org.gitlab.api.http.GitlabHTTPRequestor;
import org.gitlab.api.models.GitlabBranch;
import org.gitlab.api.models.GitlabCommit;
import org.gitlab.api.models.GitlabIssue;
import org.gitlab.api.models.GitlabMergeRequest;
import org.gitlab.api.models.GitlabMilestone;
import org.gitlab.api.models.GitlabNamespace;
import org.gitlab.api.models.GitlabNote;
import org.gitlab.api.models.GitlabProject;
import org.gitlab.api.models.GitlabProjectHook;
import org.gitlab.api.models.GitlabProjectMember;
import org.gitlab.api.models.GitlabSession;
import org.gitlab.api.models.GitlabUser;
import org.gitlab.api.http.Query;
import org.gitlab.api.models.*;
import java.io.IOException;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.gitlab.api.http.Query;
import org.gitlab.api.models.*;
/**
* Gitlab API Wrapper class
......@@ -33,23 +22,27 @@ import org.gitlab.api.models.*;
* @author @timols
*/
public class GitlabAPI {
private final String _hostUrl;
private final String _apiToken;
private boolean _ignoreCertificateErrors = false;
public static final ObjectMapper MAPPER = new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
private static final String API_NAMESPACE = "/api/v3";
private static final String PARAM_SUDO = "sudo";
public static final ObjectMapper MAPPER = new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
private final String hostUrl;
private final String apiToken;
private boolean ignoreCertificateErrors = false;
private GitlabAPI(String hostUrl, String apiToken) {
_hostUrl = hostUrl.endsWith("/") ? hostUrl.replaceAll("/$", "") : hostUrl;
_apiToken = apiToken;
this.hostUrl = hostUrl.endsWith("/") ? hostUrl.replaceAll("/$", "") : hostUrl;
this.apiToken = apiToken;
}
public static GitlabSession connect(String hostUrl, String username, String password) throws IOException {
String tailUrl = GitlabSession.URL;
GitlabAPI api = connect(hostUrl, null);
return api.dispatch().with("login", username).with("password", password)
.to(tailUrl, GitlabSession.class);
String tailUrl = GitlabSession.URL;
GitlabAPI api = connect(hostUrl, null);
return api.dispatch().with("login", username).with("password", password)
.to(tailUrl, GitlabSession.class);
}
public static GitlabAPI connect(String hostUrl, String apiToken) {
......@@ -57,7 +50,7 @@ public class GitlabAPI {
}
public GitlabAPI ignoreCertificateErrors(boolean ignoreCertificateErrors) {
_ignoreCertificateErrors = ignoreCertificateErrors;
this.ignoreCertificateErrors = ignoreCertificateErrors;
return this;
}
......@@ -70,18 +63,18 @@ public class GitlabAPI {
}
public boolean isIgnoreCertificateErrors() {
return _ignoreCertificateErrors;
return ignoreCertificateErrors;
}
public URL getAPIUrl(String tailAPIUrl) throws IOException {
if (_apiToken != null) {
tailAPIUrl = tailAPIUrl + (tailAPIUrl.indexOf('?') > 0 ? '&' : '?') + "private_token=" + _apiToken;
if (apiToken != null) {
tailAPIUrl = tailAPIUrl + (tailAPIUrl.indexOf('?') > 0 ? '&' : '?') + "private_token=" + apiToken;
}
if (!tailAPIUrl.startsWith("/")) {
tailAPIUrl = "/" + tailAPIUrl;
}
return new URL(_hostUrl + API_NAMESPACE + tailAPIUrl);
return new URL(hostUrl + API_NAMESPACE + tailAPIUrl);
}
public URL getUrl(String tailAPIUrl) throws IOException {
......@@ -89,12 +82,12 @@ public class GitlabAPI {
tailAPIUrl = "/" + tailAPIUrl;
}
return new URL(_hostUrl + tailAPIUrl);
return new URL(hostUrl + tailAPIUrl);
}
public List<GitlabUser> getUsers() throws IOException {
String tailUrl = GitlabUser.URL;
return retrieve().getAll( tailUrl, GitlabUser[].class );
return retrieve().getAll(tailUrl, GitlabUser[].class);
}
// Search users by Email or username
......@@ -109,17 +102,15 @@ public class GitlabAPI {
String tailUrl = GitlabUser.URL + "/" + userId;
return retrieve().to(tailUrl, GitlabUser.class);
}
public GitlabUser getUserViaSudo(String username) throws IOException {
String tailUrl = GitlabUser.USER_URL + "?" + PARAM_SUDO + "=" + username;
return retrieve().to(tailUrl, GitlabUser.class);
}
/**
* Create a new User
*
* @see http://doc.gitlab.com/ce/api/users.html
*
*
* @param email
* @param password
* @param username
......@@ -135,17 +126,17 @@ public class GitlabAPI {
* @param isAdmin
* @param can_create_group
* @param skip_confirmation
*
* @return
* @throws IOException
* @see http://doc.gitlab.com/ce/api/users.html
*/
public GitlabUser createUser(String email, String password, String username,
String fullName, String skypeId, String linkedIn,
String twitter, String website_url, Integer projects_limit,
String extern_uid, String extern_provider_name,
String bio, Boolean isAdmin, Boolean can_create_group,
Boolean skip_confirmation) throws IOException {
public GitlabUser createUser(String email, String password, String username,
String fullName, String skypeId, String linkedIn,
String twitter, String website_url, Integer projects_limit,
String extern_uid, String extern_provider_name,
String bio, Boolean isAdmin, Boolean can_create_group,
Boolean skip_confirmation) throws IOException {
Query query = new Query()
.append("email", email)
.appendIf("skip_confirmation", skip_confirmation)
......@@ -159,20 +150,19 @@ public class GitlabAPI {
.appendIf("projects_limit", projects_limit)
.appendIf("extern_uid", extern_uid)
.appendIf("provider", extern_provider_name)
.appendIf("bio",bio)
.appendIf("admin",isAdmin)
.appendIf("can_create_group",can_create_group);
.appendIf("bio", bio)
.appendIf("admin", isAdmin)
.appendIf("can_create_group", can_create_group);
String tailUrl = GitlabUser.USERS_URL + query.toString();
return dispatch().to(tailUrl, GitlabUser.class);
}
/**
* Update a user
*
*
* @param targetUserId
* @param email
* @param password
......@@ -189,18 +179,17 @@ public class GitlabAPI {
* @param isAdmin
* @param can_create_group
* @param skip_confirmation
*
* @return
* @throws IOException
*/
public GitlabUser updateUser(Integer targetUserId,
String email, String password, String username,
String fullName, String skypeId, String linkedIn,
String twitter, String website_url, Integer projects_limit,
String extern_uid, String extern_provider_name,
String bio, Boolean isAdmin, Boolean can_create_group,
Boolean skip_confirmation) throws IOException {
public GitlabUser updateUser(Integer targetUserId,
String email, String password, String username,
String fullName, String skypeId, String linkedIn,
String twitter, String website_url, Integer projects_limit,
String extern_uid, String extern_provider_name,
String bio, Boolean isAdmin, Boolean can_create_group,
Boolean skip_confirmation) throws IOException {
Query query = new Query()
.append("email", email)
.appendIf("skip_confirmation", skip_confirmation)
......@@ -214,24 +203,24 @@ public class GitlabAPI {
.appendIf("projects_limit", projects_limit)
.appendIf("extern_uid", extern_uid)
.appendIf("provider", extern_provider_name)
.appendIf("bio",bio)
.appendIf("admin",isAdmin)
.appendIf("can_create_group",can_create_group);
.appendIf("bio", bio)
.appendIf("admin", isAdmin)
.appendIf("can_create_group", can_create_group);
String tailUrl = GitlabUser.USERS_URL + "/"+targetUserId + query.toString();
String tailUrl = GitlabUser.USERS_URL + "/" + targetUserId + query.toString();
return retrieve().method("PUT").to(tailUrl, GitlabUser.class);
return retrieve().method("PUT").to(tailUrl, GitlabUser.class);
}
/**
* Delete a user
*
*
* @param targetUserId
* @throws IOException
*/
public void deleteUser(Integer targetUserId) throws IOException {
String tailUrl = GitlabUser.USERS_URL + "/"+targetUserId;
retrieve().method("DELETE").to(tailUrl, Void.class);
String tailUrl = GitlabUser.USERS_URL + "/" + targetUserId;
retrieve().method("DELETE").to(tailUrl, Void.class);
}
public GitlabGroup getGroup(Integer groupId) throws IOException {
......@@ -248,7 +237,6 @@ public class GitlabAPI {
* Gets all members of a Group
*
* @param group The GitLab Group
*
* @return The Group Members
*/
public List<GitlabGroupMember> getGroupMembers(GitlabGroup group) throws IOException {
......@@ -259,7 +247,6 @@ public class GitlabAPI {
* Gets all members of a Group
*
* @param groupId The id of the GitLab Group
*
* @return The Group Members
*/
public List<GitlabGroupMember> getGroupMembers(Integer groupId) throws IOException {
......@@ -273,7 +260,6 @@ public class GitlabAPI {
* @param name The name of the group. The
* name will also be used as the path
* of the group.
*
* @return The GitLab Group
*/
public GitlabGroup createGroup(String name) throws IOException {
......@@ -285,7 +271,6 @@ public class GitlabAPI {
*
* @param name The name of the group
* @param path The path for the group
*
* @return The GitLab Group
*/
public GitlabGroup createGroup(String name, String path) throws IOException {
......@@ -295,11 +280,10 @@ public class GitlabAPI {
/**
* Creates a Group
*
* @param name The name of the group
* @param path The path for the group
* @param ldapCn LDAP Group Name to sync with, null otherwise
* @param name The name of the group
* @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
*/
public GitlabGroup createGroup(String name, String path, String ldapCn, GitlabAccessLevel ldapAccess) throws IOException {
......@@ -318,8 +302,8 @@ public class GitlabAPI {
/**
* Add a group member.
*
* @param group the GitlabGroup
* @param user the GitlabUser
* @param group the GitlabGroup
* @param user the GitlabUser
* @param accessLevel the GitlabAccessLevel
* @return the GitlabGroupMember
* @throws IOException on gitlab api call error
......@@ -331,8 +315,8 @@ public class GitlabAPI {
/**
* Add a group member.
*
* @param groupId the group id
* @param userId the user id
* @param groupId the group id
* @param userId the user id
* @param accessLevel the GitlabAccessLevel
* @return the GitlabGroupMember
* @throws IOException on gitlab api call error
......@@ -350,7 +334,7 @@ public class GitlabAPI {
* Delete a group member.
*
* @param group the GitlabGroup
* @param user the GitlabUser
* @param user the GitlabUser
* @throws IOException on gitlab api call error
*/
public void deleteGroupMember(GitlabGroup group, GitlabUser user) throws IOException {
......@@ -361,7 +345,7 @@ public class GitlabAPI {
* Delete a group member.
*
* @param groupId the group id
* @param userId the user id
* @param userId the user id
* @throws IOException on gitlab api call error
*/
public void deleteGroupMember(Integer groupId, Integer userId) throws IOException {
......@@ -371,18 +355,16 @@ public class GitlabAPI {
/**
* Delete a group.
*
* @param groupId
* the group id
* @throws IOException
* on gitlab api call error
*
* @param groupId the group id
* @throws IOException on gitlab api call error
*/
public void deleteGroup(Integer groupId) throws IOException {
String tailUrl = GitlabGroup.URL + "/" + groupId;
retrieve().method("DELETE").to(tailUrl, Void.class);
}
public GitlabProject getProject(String projectId) throws IOException {
public GitlabProject getProject(Serializable projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId);
return retrieve().to(tailUrl, GitlabProject.class);
}
......@@ -396,12 +378,11 @@ public class GitlabAPI {
String tailUrl = GitlabProject.URL + "/all";
return retrieve().getAll(tailUrl, GitlabProject[].class);
}
/**
* Creates a private Project
*
* @param name The name of the project
*
* @return The GitLab Project
*/
public GitlabProject createProject(String name) throws IOException {
......@@ -411,18 +392,17 @@ public class GitlabAPI {
/**
* Creates a Project
*
* @param name The name of the project
* @param namespaceId The Namespace for the new project, otherwise null indicates to use the GitLab default (user)
* @param description A description for the project, null otherwise
* @param issuesEnabled Whether Issues should be enabled, otherwise null indicates to use GitLab default
* @param wallEnabled Whether The Wall should be enabled, otherwise null indicates to use GitLab default
* @param name The name of the project
* @param namespaceId The Namespace for the new project, otherwise null indicates to use the GitLab default (user)
* @param description A description for the project, null otherwise
* @param issuesEnabled Whether Issues should be enabled, otherwise null indicates to use GitLab default
* @param wallEnabled Whether The Wall should be enabled, otherwise null indicates to use GitLab default
* @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 publik Whether the project is public or private, if true same as setting visibilityLevel = 20, otherwise null indicates to use GitLab default
* @param visibilityLevel The visibility level of the project, otherwise null indicates to use GitLab default
* @param importUrl The Import URL for the project, otherwise null
*
* @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 publik Whether the project is public or private, if true same as setting visibilityLevel = 20, otherwise null indicates to use GitLab default
* @param visibilityLevel The visibility level of the project, otherwise null indicates to use GitLab default
* @param importUrl The Import URL for the project, otherwise null
* @return the Gitlab Project
*/
public GitlabProject createProject(String name, Integer namespaceId, String description, Boolean issuesEnabled, Boolean wallEnabled, Boolean mergeRequestsEnabled, Boolean wikiEnabled, Boolean snippetsEnabled, Boolean publik, Integer visibilityLevel, String importUrl) throws IOException {
......@@ -448,8 +428,7 @@ public class GitlabAPI {
* Creates a Project for a specific User
*
* @param userId The id of the user to create the project for
* @param name The name of the project
*
* @param name The name of the project
* @return The GitLab Project
*/
public GitlabProject createUserProject(Integer userId, String name) throws IOException {
......@@ -459,18 +438,17 @@ public class GitlabAPI {
/**
* Creates a Project for a specific User
*
* @param userId The id of the user to create the project for
* @param name The name of the project
* @param description A description for the project, null otherwise
* @param defaultBranch The default branch for the project, otherwise null indicates to use GitLab default (master)
* @param issuesEnabled Whether Issues should be enabled, otherwise null indicates to use GitLab default
* @param wallEnabled Whether The Wall should be enabled, otherwise null indicates to use GitLab default
* @param userId The id of the user to create the project for
* @param name The name of the project
* @param description A description for the project, null otherwise
* @param defaultBranch The default branch for the project, otherwise null indicates to use GitLab default (master)
* @param issuesEnabled Whether Issues should be enabled, otherwise null indicates to use GitLab default
* @param wallEnabled Whether The Wall should be enabled, otherwise null indicates to use GitLab default
* @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 publik Whether the project is public or private, if true same as setting visibilityLevel = 20, otherwise null indicates to use GitLab default
* @param visibilityLevel The visibility level of the project, 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 publik Whether the project is public or private, if true same as setting visibilityLevel = 20, otherwise null indicates to use GitLab default
* @param visibilityLevel The visibility level of the project, otherwise null indicates to use GitLab default
* @return The GitLab Project
*/
public GitlabProject createUserProject(Integer userId, String name, String description, String defaultBranch, Boolean issuesEnabled, Boolean wallEnabled, Boolean mergeRequestsEnabled, Boolean wikiEnabled, Boolean snippetsEnabled, Boolean publik, Integer visibilityLevel) throws IOException {
......@@ -493,13 +471,11 @@ public class GitlabAPI {
/**
* Delete a Project.
*
* @param projectId
* The id of the project to delete
* @throws IOException
* on gitlab api call error
*
* @param projectId The id of the project to delete
* @throws IOException on gitlab api call error
*/
public void deleteProject(String projectId) throws IOException {
public void deleteProject(Serializable projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId);
retrieve().method("DELETE").to(tailUrl, Void.class);
}
......@@ -518,7 +494,7 @@ public class GitlabAPI {
return openMergeRequests;
}
public List<GitlabMergeRequest> getMergeRequests(String projectId) throws IOException {
public List<GitlabMergeRequest> getMergeRequests(Serializable projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabMergeRequest.URL;
return fetchMergeRequests(tailUrl);
}
......@@ -551,14 +527,14 @@ public class GitlabAPI {
String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() +
GitlabMergeRequest.URL + "/" + mergeRequest.getId() +
GitlabNote.URL;
return retrieve().getAll(tailUrl, GitlabNote[].class);
}
// Get a specific commit identified by the commit hash or name of a branch or tag
// GET /projects/:id/repository/commits/:sha
public GitlabCommit getCommit(String projectId, String commitHash) throws IOException {
public GitlabCommit getCommit(Serializable projectId, String commitHash) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + "/repository/commits/" + commitHash;
GitlabCommit commit = retrieve().to(tailUrl, GitlabCommit.class);
return commit;
......@@ -571,7 +547,7 @@ public class GitlabAPI {
}
Query query = new Query()
.append("ref_name", mergeRequest.getSourceBranch());
.append("ref_name", mergeRequest.getSourceBranch());
String tailUrl = GitlabProject.URL + "/" + projectId +
"/repository" + GitlabCommit.URL + query.toString();
......@@ -581,14 +557,14 @@ public class GitlabAPI {
}
// gets all commits for a project
public List<GitlabCommit> getAllCommits(String projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + "/repository" + GitlabCommit.URL;
return retrieve().getAll(tailUrl, GitlabCommit[].class);
public List<GitlabCommit> getAllCommits(Serializable projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + "/repository" + GitlabCommit.URL;
return retrieve().getAll(tailUrl, GitlabCommit[].class);
}
// List commit diffs for a project ID and commit hash
// GET /projects/:id/repository/commits/:sha/diff
public List<GitlabCommitDiff> getCommitDiffs(String projectId, String commitHash) throws IOException {
public List<GitlabCommitDiff> getCommitDiffs(Serializable projectId, String commitHash) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + "/repository/commits/" + commitHash + GitlabCommitDiff.URL;
GitlabCommitDiff[] diffs = retrieve().to(tailUrl, GitlabCommitDiff[].class);
return Arrays.asList(diffs);
......@@ -601,61 +577,61 @@ public class GitlabAPI {
return dispatch().with("body", body).to(tailUrl, GitlabNote.class);
}
public List<GitlabBranch> getBranches(String projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabBranch.URL;
public List<GitlabBranch> getBranches(Serializable projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabBranch.URL;
GitlabBranch[] branches = retrieve().to(tailUrl, GitlabBranch[].class);
return Arrays.asList(branches);
}
public List<GitlabBranch> getBranches(GitlabProject project) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabBranch.URL;
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabBranch.URL;
GitlabBranch[] branches = retrieve().to(tailUrl, GitlabBranch[].class);
return Arrays.asList(branches);
}
public GitlabBranch getBranch(GitlabProject project, String branchName) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabBranch.URL + branchName;
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabBranch.URL + branchName;
GitlabBranch branch = retrieve().to(tailUrl, GitlabBranch.class);
return branch;
}
public void protectBranch(GitlabProject project, String branchName) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabBranch.URL + branchName + "/protect";
retrieve().method("PUT").to(tailUrl, Void.class);
}
public void unprotectBranch(GitlabProject project, String branchName) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabBranch.URL + branchName + "/unprotect";
retrieve().method("PUT").to(tailUrl, Void.class);
}
public List<GitlabProjectHook> getProjectHooks(String projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabProjectHook.URL;
GitlabProjectHook[] hooks = retrieve().to(tailUrl, GitlabProjectHook[].class);
return Arrays.asList(hooks);
public List<GitlabProjectHook> getProjectHooks(Serializable projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabProjectHook.URL;
GitlabProjectHook[] hooks = retrieve().to(tailUrl, GitlabProjectHook[].class);
return Arrays.asList(hooks);
}
public List<GitlabProjectHook> getProjectHooks(GitlabProject project) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabProjectHook.URL;
GitlabProjectHook[] hooks = retrieve().to(tailUrl, GitlabProjectHook[].class);
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabProjectHook.URL;
GitlabProjectHook[] hooks = retrieve().to(tailUrl, GitlabProjectHook[].class);
return Arrays.asList(hooks);
}
public GitlabProjectHook getProjectHook(GitlabProject project, String hookId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabProjectHook.URL + "/" + hookId;
GitlabProjectHook hook = retrieve().to(tailUrl, GitlabProjectHook.class);
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabProjectHook.URL + "/" + hookId;
GitlabProjectHook hook = retrieve().to(tailUrl, GitlabProjectHook.class);
return hook;
}
public GitlabProjectHook addProjectHook(GitlabProject project, String url) throws IOException {
Query query = new Query()
.append("url", url);
.append("url", url);
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabProjectHook.URL + query.toString();
return dispatch().to(tailUrl, GitlabProjectHook.class);
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabProjectHook.URL + query.toString();
return dispatch().to(tailUrl, GitlabProjectHook.class);
}
public GitlabProjectHook addProjectHook(String projectId, String url, boolean pushEvents, boolean issuesEvents, boolean mergeRequestEvents) throws IOException {
public GitlabProjectHook addProjectHook(Serializable projectId, String url, boolean pushEvents, boolean issuesEvents, boolean mergeRequestEvents) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabProjectHook.URL;
return dispatch()
......@@ -665,106 +641,106 @@ public class GitlabAPI {
.with("merge_requests_events", mergeRequestEvents ? "true" : "false")
.to(tailUrl, GitlabProjectHook.class);
}
public GitlabProjectHook editProjectHook(GitlabProject project, String hookId, String url) throws IOException {
Query query = new Query()
.append("url", url);
.append("url", url);
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabProjectHook.URL + "/" + hookId + query.toString();
return retrieve().method("PUT").to(tailUrl, GitlabProjectHook.class);
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabProjectHook.URL + "/" + hookId + query.toString();
return retrieve().method("PUT").to(tailUrl, GitlabProjectHook.class);
}
public void deleteProjectHook(GitlabProjectHook hook) throws IOException {
String tailUrl = GitlabProject.URL + "/" + hook.getProjectId() + GitlabProjectHook.URL + "/" + hook.getId();
retrieve().method("DELETE").to(tailUrl, Void.class);
String tailUrl = GitlabProject.URL + "/" + hook.getProjectId() + GitlabProjectHook.URL + "/" + hook.getId();
retrieve().method("DELETE").to(tailUrl, Void.class);
}
public void deleteProjectHook(GitlabProject project, String hookId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabProjectHook.URL + "/" + hookId;
retrieve().method("DELETE").to(tailUrl, Void.class);
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabProjectHook.URL + "/" + hookId;
retrieve().method("DELETE").to(tailUrl, Void.class);
}
private List<GitlabMergeRequest> fetchMergeRequests(String tailUrl) throws IOException {
GitlabMergeRequest[] mergeRequests = retrieve().to(tailUrl, GitlabMergeRequest[].class);
return Arrays.asList(mergeRequests);
}
public List<GitlabIssue> getIssues(GitlabProject project) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabIssue.URL;
return retrieve().getAll(tailUrl, GitlabIssue[].class);
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabIssue.URL;
return retrieve().getAll(tailUrl, GitlabIssue[].class);
}
public GitlabIssue getIssue(String projectId, Integer issueId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabIssue.URL + "/" + issueId;
return retrieve().to(tailUrl, GitlabIssue.class);
public GitlabIssue getIssue(Serializable projectId, Integer issueId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabIssue.URL + "/" + issueId;
return retrieve().to(tailUrl, GitlabIssue.class);
}
public GitlabIssue createIssue(int projectId, int assigneeId, int milestoneId, String labels,
String description, String title) throws IOException {
String tailUrl = GitlabProject.URL + "/" + projectId + GitlabIssue.URL;
GitlabHTTPRequestor requestor = dispatch();
applyIssue(requestor, projectId, assigneeId, milestoneId, labels, description, title);
return requestor.to(tailUrl, GitlabIssue.class);
public GitlabIssue createIssue(int projectId, int assigneeId, int milestoneId, String labels,
String description, String title) throws IOException {
String tailUrl = GitlabProject.URL + "/" + projectId + GitlabIssue.URL;
GitlabHTTPRequestor requestor = dispatch();
applyIssue(requestor, projectId, assigneeId, milestoneId, labels, description, title);
return requestor.to(tailUrl, GitlabIssue.class);
}
public GitlabIssue editIssue(int projectId, int issueId, int assigneeId, int milestoneId, String labels,
String description, String title, GitlabIssue.Action action) throws IOException {
String tailUrl = GitlabProject.URL + "/" + projectId + GitlabIssue.URL + "/" + issueId;
GitlabHTTPRequestor requestor = retrieve().method("PUT");
applyIssue(requestor, projectId, assigneeId, milestoneId, labels, description, title);
if(action != GitlabIssue.Action.LEAVE) {
requestor.with("state_event", action.toString().toLowerCase());
}
return requestor.to(tailUrl, GitlabIssue.class);
}
private void applyIssue(GitlabHTTPRequestor requestor, int projectId,
int assigneeId, int milestoneId, String labels, String description,
String title) {
requestor.with("title", title)
.with("description", description)
.with("labels", labels)
.with("milestone_id", milestoneId);
if(assigneeId != 0) {
requestor.with("assignee_id", assigneeId == -1 ? 0 : assigneeId);
}
}
String description, String title, GitlabIssue.Action action) throws IOException {
String tailUrl = GitlabProject.URL + "/" + projectId + GitlabIssue.URL + "/" + issueId;
GitlabHTTPRequestor requestor = retrieve().method("PUT");
applyIssue(requestor, projectId, assigneeId, milestoneId, labels, description, title);
if (action != GitlabIssue.Action.LEAVE) {
requestor.with("state_event", action.toString().toLowerCase());
}
return requestor.to(tailUrl, GitlabIssue.class);
}
private void applyIssue(GitlabHTTPRequestor requestor, int projectId,
int assigneeId, int milestoneId, String labels, String description,
String title) {
requestor.with("title", title)
.with("description", description)
.with("labels", labels)
.with("milestone_id", milestoneId);
if (assigneeId != 0) {
requestor.with("assignee_id", assigneeId == -1 ? 0 : assigneeId);
}
}
public List<GitlabNote> getNotes(GitlabIssue issue) throws IOException {
String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/"
+ issue.getId() + GitlabNote.URL;
return Arrays.asList(retrieve().to(tailUrl, GitlabNote[].class));
String tailUrl = GitlabProject.URL + "/" + issue.getProjectId() + GitlabIssue.URL + "/"
+ issue.getId() + GitlabNote.URL;
return Arrays.asList(retrieve().to(tailUrl, GitlabNote[].class));
}
public GitlabNote createNote(String projectId, Integer issueId, String message) throws IOException {
String tailUrl = GitlabProject.URL + "/" + projectId + GitlabIssue.URL
+ "/" + issueId + GitlabNote.URL;
return dispatch().with("body", message).to(tailUrl, GitlabNote.class);
public GitlabNote createNote(Serializable projectId, Integer issueId, String message) throws IOException {
String tailUrl = GitlabProject.URL + "/" + projectId + GitlabIssue.URL
+ "/" + issueId + GitlabNote.URL;
return dispatch().with("body", message).to(tailUrl, GitlabNote.class);
}
public GitlabNote createNote(GitlabIssue issue, String message) throws IOException {
return createNote(String.valueOf(issue.getProjectId()), issue.getId(), message);
return createNote(String.valueOf(issue.getProjectId()), issue.getId(), message);
}
public List<GitlabMilestone> getMilestones(GitlabProject project) throws IOException {
return getMilestones(String.valueOf(project.getId()));
return getMilestones(String.valueOf(project.getId()));
}
public List<GitlabMilestone> getMilestones(String projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabMilestone.URL;
return Arrays.asList(retrieve().to(tailUrl, GitlabMilestone[].class));
public List<GitlabMilestone> getMilestones(Serializable projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabMilestone.URL;
return Arrays.asList(retrieve().to(tailUrl, GitlabMilestone[].class));
}
/**
* Add a project member.
*
* @param project the GitlabProject
* @param user the GitlabUser
* @param project the GitlabProject
* @param user the GitlabUser
* @param accessLevel the GitlabAccessLevel
* @return the GitlabProjectMember
* @throws IOException on gitlab api call error
......@@ -776,8 +752,8 @@ public class GitlabAPI {
/**
* Add a project member.
*
* @param projectId the project id
* @param userId the user id
* @param projectId the project id
* @param userId the user id
* @param accessLevel the GitlabAccessLevel
* @return the GitlabProjectMember
* @throws IOException on gitlab api call error
......@@ -795,7 +771,7 @@ public class GitlabAPI {
* Delete a project team member.
*
* @param project the GitlabProject
* @param user the GitlabUser
* @param user the GitlabUser
* @throws IOException on gitlab api call error
*/
public void deleteProjectMember(GitlabProject project, GitlabUser user) throws IOException {
......@@ -806,7 +782,7 @@ public class GitlabAPI {
* Delete a project team member.
*
* @param projectId the project id
* @param userId the user id
* @param userId the user id
* @throws IOException on gitlab api call error
*/
public void deleteProjectMember(Integer projectId, Integer userId) throws IOException {
......@@ -815,41 +791,51 @@ public class GitlabAPI {
}
public List<GitlabProjectMember> getProjectMembers(GitlabProject project) throws IOException {
return getProjectMembers(String.valueOf(project.getId()));
return getProjectMembers(project.getId());
}
public List<GitlabProjectMember> getProjectMembers(String projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabProjectMember.URL;
return Arrays.asList(retrieve().to(tailUrl, GitlabProjectMember[].class));
public List<GitlabProjectMember> getProjectMembers(Serializable projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabProjectMember.URL;
return Arrays.asList(retrieve().to(tailUrl, GitlabProjectMember[].class));
}
/**
* This will fail, if the given namespace is a user and not a group
*
* @param namespace
* @return
* @throws IOException
*/
public List<GitlabProjectMember> getNamespaceMembers(GitlabNamespace namespace) throws IOException {
return getNamespaceMembers(namespace.getId());
return getNamespaceMembers(namespace.getId());
}
/**
* This will fail, if the given namespace is a user and not a group
*
* @param namespaceId
* @return
* @throws IOException
*/
public List<GitlabProjectMember> getNamespaceMembers(Integer namespaceId) throws IOException {
String tailUrl = GitlabNamespace.URL + "/" + namespaceId + GitlabProjectMember.URL;
return Arrays.asList(retrieve().to(tailUrl, GitlabProjectMember[].class));
String tailUrl = GitlabNamespace.URL + "/" + namespaceId + GitlabProjectMember.URL;
return Arrays.asList(retrieve().to(tailUrl, GitlabProjectMember[].class));
}
public GitlabSession getCurrentSession() throws IOException {
String tailUrl = "/user";
return retrieve().to(tailUrl, GitlabSession.class);
String tailUrl = "/user";
return retrieve().to(tailUrl, GitlabSession.class);
}
private String sanitizeProjectId(String projectId) {
return projectId.replace("/","%2F");
private String sanitizeProjectId(Serializable projectId) {
if (!(projectId instanceof String) && !(projectId instanceof Integer)) {
throw new IllegalArgumentException();
}
try {
return URLEncoder.encode(String.valueOf(projectId), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException((e));
}
}
}
package org.gitlab.api.http;
import org.apache.commons.io.IOUtils;
import org.gitlab.api.GitlabAPI;
import org.gitlab.api.models.GitlabCommit;
import javax.net.ssl.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
......@@ -9,39 +14,26 @@ import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.commons.io.IOUtils;
import org.gitlab.api.GitlabAPI;
import org.gitlab.api.models.GitlabCommit;
/**
* Gitlab HTTP Requestor
*
* <p/>
* Responsible for handling HTTP requests to the Gitlab API
*
* @author @timols
*/
public class GitlabHTTPRequestor {
private final GitlabAPI _root;
private String _method = "GET"; // Default to GET requests
private Map<String, Object> _data = new HashMap<String, Object>();
private static final Pattern PAGE_PATTERN = Pattern.compile("([&|?])page=(\\d+)");
private final GitlabAPI root;
private String method = "GET"; // Default to GET requests
private Map<String, Object> data = new HashMap<String, Object>();
private enum METHOD {
GET, PUT, POST, PATCH, DELETE, HEAD, OPTIONS, TRACE;
......@@ -62,20 +54,20 @@ public class GitlabHTTPRequestor {
}
public GitlabHTTPRequestor(GitlabAPI root) {
_root = root;
this.root = root;
}
/**
* Sets the HTTP Request method for the request.
*
* <p/>
* Has a fluent api for method chaining.
*
* @param method The HTTP method
* @return this
* @param method The HTTP method
* @return this
*/
public GitlabHTTPRequestor method(String method) {
try {
_method = METHOD.valueOf(method).toString();
this.method = METHOD.valueOf(method).toString();
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid HTTP Method: " + method + ". Must be one of " + METHOD.prettyValues());
}
......@@ -85,16 +77,16 @@ public class GitlabHTTPRequestor {
/**
* Sets the HTTP Form Post parameters for the request
*
* <p/>
* Has a fluent api for method chaining
*
* @param key
* @param value
* @return this
* @param key
* @param value
* @return this
*/
public GitlabHTTPRequestor with(String key, Object value) {
if (value != null && key != null) {
_data.put(key, value);
data.put(key, value);
}
return this;
}
......@@ -110,22 +102,22 @@ public class GitlabHTTPRequestor {
/**
* Opens the HTTP(S) connection, submits any data and parses the response.
* Will throw an error
* @param tailAPIUrl The url to open a connection to (after the host and namespace)
* @param type The type of the response to be deserialized from
* @param instance The instance to update from the response
*
* @return An object of type T
* @param tailAPIUrl The url to open a connection to (after the host and namespace)
* @param type The type of the response to be deserialized from
* @param instance The instance to update from the response
* @return An object of type T
* @throws java.io.IOException
*/
public <T> T to(String tailAPIUrl, Class<T> type, T instance) throws IOException {
HttpURLConnection connection = setupConnection(_root.getAPIUrl(tailAPIUrl));
HttpURLConnection connection = setupConnection(root.getAPIUrl(tailAPIUrl));
if (hasOutput()) {
submitData(connection);
} else if( "PUT".equals(_method) ) {
// PUT requires Content-Length: 0 even when there is no body (eg: API for protecting a branch)
connection.setDoOutput(true);
connection.setFixedLengthStreamingMode(0);
} else if ("PUT".equals(method)) {
// PUT requires Content-Length: 0 even when there is no body (eg: API for protecting a branch)
connection.setDoOutput(true);
connection.setFixedLengthStreamingMode(0);
}
try {
......@@ -138,8 +130,8 @@ public class GitlabHTTPRequestor {
}
public <T> List<T> getAll(final String tailUrl, final Class<T[]> type) {
List<T> results = new ArrayList<T>();
Iterator<T[]> iterator = asIterator(tailUrl, type);
List<T> results = new ArrayList<T>();
Iterator<T[]> iterator = asIterator(tailUrl, type);
while (iterator.hasNext()) {
T[] requests = iterator.next();
......@@ -155,17 +147,17 @@ public class GitlabHTTPRequestor {
method("GET"); // Ensure we only use iterators for GET requests
// Ensure that we don't submit any data and alert the user
if (!_data.isEmpty()) {
if (!data.isEmpty()) {
throw new IllegalStateException();
}
return new Iterator<T>() {
T _next;
URL _url;
T next;
URL url;
{
try {
_url = _root.getAPIUrl(tailApiUrl);
url = root.getAPIUrl(tailApiUrl);
} catch (IOException e) {
throw new Error(e);
}
......@@ -173,23 +165,23 @@ public class GitlabHTTPRequestor {
public boolean hasNext() {
fetch();
if (_next.getClass().isArray()) {
Object[] arr = (Object[]) _next;
if (next != null && next.getClass().isArray()) {
Object[] arr = (Object[]) next;
return arr.length != 0;
} else {
return _next != null;
return next != null;
}
}
public T next() {
fetch();
T record = _next;
T record = next;
if (record == null) {
throw new NoSuchElementException();
}
_next = null;
next = null;
return record;
}
......@@ -198,20 +190,20 @@ public class GitlabHTTPRequestor {
}
private void fetch() {
if (_next != null) {
if (next != null) {
return;
}
if (_url == null) {
if (url == null) {
return;
}
try {
HttpURLConnection connection = setupConnection(_url);
HttpURLConnection connection = setupConnection(url);
try {
_next = parse(connection, type, null);
assert _next != null;
findNextUrl(connection);
next = parse(connection, type, null);
assert next != null;
findNextUrl();
} catch (IOException e) {
handleAPIError(e, connection);
}
......@@ -220,31 +212,30 @@ public class GitlabHTTPRequestor {
}
}
private void findNextUrl(HttpURLConnection connection) throws MalformedURLException {
String url = _url.toString();
private void findNextUrl() throws MalformedURLException {
String url = this.url.toString();
_url = null;
this.url = null;
/* Increment the page number for the url if a "page" property exists,
* otherwise, add the page property and increment it.
* The Gitlab API is not a compliant hypermedia REST api, so we use
* a naive implementation.
*/
Pattern pattern = Pattern.compile("([&|?])page=(\\d+)");
Matcher matcher = pattern.matcher(url);
Matcher matcher = PAGE_PATTERN.matcher(url);
if (matcher.find()) {
Integer page = Integer.parseInt(matcher.group(2)) + 1;
_url = new URL(matcher.replaceAll(matcher.group(1) + "page=" + page));
this.url = new URL(matcher.replaceAll(matcher.group(1) + "page=" + page));
} else {
if (GitlabCommit[].class == type) {
// there is a bug in the Gitlab CE API
// (https://gitlab.com/gitlab-org/gitlab-ce/issues/759)
// that starts pagination with page=0 for commits
_url = new URL(url + "&page=1");
// that starts pagination with page=0 for commits
this.url = new URL(url + "&page=1");
} else {
// Since the page query was not present, its safe to assume that we just
// currently used the first page, so we can default to page 2
_url = new URL(url + "&page=2");
this.url = new URL(url + "&page=2");
}
}
}
......@@ -254,28 +245,28 @@ public class GitlabHTTPRequestor {
private void submitData(HttpURLConnection connection) throws IOException {
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json");
GitlabAPI.MAPPER.writeValue(connection.getOutputStream(), _data);
GitlabAPI.MAPPER.writeValue(connection.getOutputStream(), data);
}
private boolean hasOutput() {
return _method.equals("POST") || _method.equals("PUT") && !_data.isEmpty();
return method.equals("POST") || method.equals("PUT") && !data.isEmpty();
}
private HttpURLConnection setupConnection(URL url) throws IOException {
if (_root.isIgnoreCertificateErrors()) {
if (root.isIgnoreCertificateErrors()) {
ignoreCertificateErrors();
}
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try {
connection.setRequestMethod(_method);
connection.setRequestMethod(method);
} catch (ProtocolException e) {
// Hack in case the API uses a non-standard HTTP verb
try {
Field methodField = connection.getClass().getDeclaredField("method");
methodField.setAccessible(true);
methodField.set(connection, _method);
methodField.set(connection, method);
} catch (Exception x) {
throw (IOException) new IOException("Failed to set the custom verb").initCause(x);
}
......@@ -336,17 +327,19 @@ public class GitlabHTTPRequestor {
private void ignoreCertificateErrors() {
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
}
}
}
};
try {
......
......@@ -16,6 +16,7 @@ public class Query {
private class Tuple<T1, T2> {
T1 _1;
T2 _2;
public Tuple(T1 _1, T2 _2) {
this._1 = _1;
this._2 = _2;
......@@ -24,20 +25,19 @@ public class Query {
/**
* The type of params is:
* Tuple<name, Tuple<value, URLEncoder.encode(value, "UTF-8")>>
* Tuple<name, Tuple<value, URLEncoder.encode(value, "UTF-8")>>
*/
private final List<Tuple<String, Tuple<String, String>>> params = new ArrayList<Tuple<String, Tuple<String, String>>>();
/**
* Appends a parameter to the query
*
* @param name Parameter name
* @param name Parameter name
* @param value Parameter value
*
* @throws java.io.UnsupportedEncodingException If the provided value cannot be URL Encoded
*/
public Query append(final String name, final String value) throws UnsupportedEncodingException {
params.add(new Tuple(name, new Tuple(value, URLEncoder.encode(value, "UTF-8"))));
params.add(new Tuple<String, Tuple<String, String>>(name, new Tuple<String, String>(value, URLEncoder.encode(value, "UTF-8"))));
return this;
}
......@@ -45,13 +45,12 @@ public class Query {
* Conditionally append a parameter to the query
* if the value of the parameter is not null
*
* @param name Parameter name
* @param name Parameter name
* @param value Parameter value
*
* @throws java.io.UnsupportedEncodingException If the provided value cannot be URL Encoded
*/
public Query appendIf(final String name, final String value) throws UnsupportedEncodingException {
if(value != null) {
if (value != null) {
append(name, value);
}
return this;
......@@ -61,13 +60,12 @@ public class Query {
* Conditionally append a parameter to the query
* if the value of the parameter is not null
*
* @param name Parameter name
* @param name Parameter name
* @param value Parameter value
*
* @throws java.io.UnsupportedEncodingException If the provided value cannot be URL Encoded
*/
public Query appendIf(final String name, final Integer value) throws UnsupportedEncodingException {
if(value != null) {
if (value != null) {
append(name, value.toString());
}
return this;
......@@ -77,13 +75,12 @@ public class Query {
* Conditionally append a parameter to the query
* if the value of the parameter is not null
*
* @param name Parameter name
* @param name Parameter name
* @param value Parameter value
*
* @throws java.io.UnsupportedEncodingException If the provided value cannot be URL Encoded
*/
public Query appendIf(final String name, final Boolean value) throws UnsupportedEncodingException {
if(value != null) {
if (value != null) {
append(name, value.toString());
}
return this;
......@@ -93,13 +90,12 @@ public class Query {
* Conditionally append a parameter to the query
* if the value of the parameter is not null
*
* @param name Parameter name
* @param name Parameter name
* @param value Parameter value
*
* @throws java.io.UnsupportedEncodingException If the provided value cannot be URL Encoded
*/
public Query appendIf(final String name, final GitlabAccessLevel value) throws UnsupportedEncodingException {
if(value != null) {
if (value != null) {
append(name, Integer.toString(value.accessValue));
}
return this;
......@@ -113,8 +109,8 @@ public class Query {
public String toString() {
final StringBuilder builder = new StringBuilder();
for(final Tuple<String, Tuple<String, String>> param : params) {
if(builder.length() == 0) {
for (final Tuple<String, Tuple<String, String>> param : params) {
if (builder.length() == 0) {
builder.append('?');
} else {
builder.append('&');
......
......@@ -4,17 +4,17 @@ import org.codehaus.jackson.annotate.JsonProperty;
public abstract class GitlabAbstractMember extends GitlabUser {
public static final String URL = "/members";
public static final String URL = "/members";
@JsonProperty("access_level")
private int _accessLevel;
private int accessLevel;
public GitlabAccessLevel getAccessLevel() {
return GitlabAccessLevel.fromAccessValue(_accessLevel);
}
public GitlabAccessLevel getAccessLevel() {
return GitlabAccessLevel.fromAccessValue(accessLevel);
}
public void setAccessLevel(GitlabAccessLevel accessLevel) {
_accessLevel = accessLevel.accessValue;
}
public void setAccessLevel(GitlabAccessLevel accessLevel) {
this.accessLevel = accessLevel.accessValue;
}
}
......@@ -9,16 +9,17 @@ public enum GitlabAccessLevel {
Owner(50);
public final int accessValue;
GitlabAccessLevel(int accessValue) {
this.accessValue = accessValue;
}
public static GitlabAccessLevel fromAccessValue(final int accessValue) throws IllegalArgumentException {
for(final GitlabAccessLevel gitlabAccessLevel : GitlabAccessLevel.values()) {
if(gitlabAccessLevel.accessValue == accessValue) {
for (final GitlabAccessLevel gitlabAccessLevel : GitlabAccessLevel.values()) {
if (gitlabAccessLevel.accessValue == accessValue) {
return gitlabAccessLevel;
}
}
throw new IllegalArgumentException("No GitLab Access Level enum constant with access value: " + accessValue);
}
}
\ No newline at end of file
}
......@@ -3,38 +3,38 @@ package org.gitlab.api.models;
import org.codehaus.jackson.annotate.JsonProperty;
public class GitlabBranch {
public final static String URL = "/repository/branches/";
@JsonProperty("name")
private String _name;
@JsonProperty("commit")
private GitlabBranchCommit _commit;
@JsonProperty("protected")
private boolean _protected;
public String getName() {
return _name;
}
public void setName(String name) {
this._name = name;
}
public GitlabBranchCommit getCommit() {
return _commit;
}
public void setCommit(GitlabBranchCommit commit) {
this._commit = commit;
}
public boolean isProtected() {
return _protected;
}
public void setProtected(boolean isProtected) {
this._protected = isProtected;
}
}
\ No newline at end of file
public final static String URL = "/repository/branches/";
@JsonProperty("name")
private String name;
@JsonProperty("commit")
private GitlabBranchCommit commit;
@JsonProperty("protected")
private boolean branchProtected;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public GitlabBranchCommit getCommit() {
return commit;
}
public void setCommit(GitlabBranchCommit commit) {
this.commit = commit;
}
public boolean isProtected() {
return branchProtected;
}
public void setProtected(boolean isProtected) {
this.branchProtected = isProtected;
}
}
package org.gitlab.api.models;
import org.gitlab.api.models.GitlabUser;
import org.codehaus.jackson.annotate.JsonProperty;
import java.lang.String;
import java.util.Date;
import org.codehaus.jackson.annotate.JsonProperty;
public class GitlabBranchCommit {
public static String URL = "/users";
private String _id;
private String _tree;
private String _message;
private GitlabUser _author;
private GitlabUser _committer;
private String id;
private String tree;
private String message;
private GitlabUser author;
private GitlabUser committer;
@JsonProperty("authored_date")
private Date _authoredDate;
private Date authoredDate;
@JsonProperty("committed_date")
private Date _committedDate;
private Date committedDate;
public String getId() {
return _id;
return id;
}
public void setId(String id) {
_id = id;
this.id = id;
}
public String getTree() {
return _tree;
return tree;
}
public void setTree(String tree) {
_tree = tree;
this.tree = tree;
}
public String getMessage() {
return _message;
return message;
}
public void setMessage(String message) {
_message = message;
this.message = message;
}
public GitlabUser getAuthor() {
return _author;
return author;
}
public void setAuthor(GitlabUser author) {
_author = author;
this.author = author;
}
public GitlabUser getCommitter() {
return _committer;
return committer;
}
public void setCommitter(GitlabUser committer) {
_committer = committer;
this.committer = committer;
}
public Date getAuthoredDate() {
return _authoredDate;
return authoredDate;
}
public void setAuthoredDate(Date authoredDate) {
_authoredDate = authoredDate;
this.authoredDate = authoredDate;
}
public Date getCommittedDate() {
return _committedDate;
return committedDate;
}
public void setCommittedDate(Date committedDate) {
_committedDate = committedDate;
this.committedDate = committedDate;
}
}
package org.gitlab.api.models;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.Date;
import java.util.List;
import org.codehaus.jackson.annotate.JsonProperty;
public class GitlabCommit {
public final static String URL = "/commits";
private String _id;
private String _title;
private String _description;
private String id;
private String title;
private String description;
@JsonProperty("short_id")
private String _shortId;
private String shortId;
@JsonProperty("author_name")
private String _authorName;
private String authorName;
@JsonProperty("author_email")
private String _authorEmail;
private String authorEmail;
@JsonProperty("created_at")
private Date _createdAt;
private Date createdAt;
@JsonProperty("committed_date")
private Date _committedDate;
private Date committedDate;
@JsonProperty("authored_date")
private Date _authoredDate;
private Date authoredDate;
@JsonProperty("parent_ids")
private List<String> _parentIds;
private List<String> parentIds;
public String getId() {
return _id;
return id;
}
public void setId(String id) {
_id = id;
this.id = id;
}
public String getShortId() {
return _shortId;
return shortId;
}
public void setShortId(String shortId) {
_shortId = shortId;
this.shortId = shortId;
}
public String getTitle() {
return _title;
return title;
}
public void setTitle(String title) {
_title = title;
this.title = title;
}
public String getDescription() {
return _description;
return description;
}
public void setDescription(String description) {
_description = description;
this.description = description;
}
public String getAuthorName() {
return _authorName;
return authorName;
}
public void setAuthorName(String authorName) {
_authorName = authorName;
this.authorName = authorName;
}
public String getAuthorEmail() {
return _authorEmail;
return authorEmail;
}
public void setAuthorEmail(String authorEmail) {
_authorEmail = authorEmail;
this.authorEmail = authorEmail;
}
public Date getCreatedAt() {
return _createdAt;
return createdAt;
}
public void setCreatedAt(Date createdAt) {
_createdAt = createdAt;
this.createdAt = createdAt;
}
public List<String> getParentIds() {
return _parentIds;
return parentIds;
}
public void setParentIds(List<String> parentIds) {
_parentIds = parentIds;
}
@Override
public boolean equals(Object obj) {
// we say that two commit objects are equal iff they have the same ID
// this prevents us from having to do clever workarounds for
// https://gitlab.com/gitlab-org/gitlab-ce/issues/759
try {
GitlabCommit commitObj = (GitlabCommit) obj;
return (this.getId().compareTo(commitObj.getId()) == 0);
} catch (ClassCastException e) {
return false;
}
}
this.parentIds = parentIds;
}
@Override
public boolean equals(Object obj) {
// we say that two commit objects are equal iff they have the same ID
// this prevents us from having to do clever workarounds for
// https://gitlab.com/gitlab-org/gitlab-ce/issues/759
try {
GitlabCommit commitObj = (GitlabCommit) obj;
return (this.getId().compareTo(commitObj.getId()) == 0);
} catch (ClassCastException e) {
return false;
}
}
}
......@@ -7,90 +7,90 @@ public class GitlabCommitDiff {
public final static String URL = "/diff";
@JsonProperty("diff")
private String _diff;
private String diff;
@JsonProperty("new_path")
private String _newPath;
private String newPath;
@JsonProperty("old_path")
private String _oldPath;
private String oldPath;
@JsonProperty("a_mode")
private String _aMode;
private String aMode;
@JsonProperty("b_mode")
private String _bMode;
private String bMode;
@JsonProperty("new_file")
private boolean _newFile;
private boolean newFile;
@JsonProperty("renamed_file")
private boolean _renamedFile;
private boolean renamedFile;
@JsonProperty("deleted_file")
private boolean _deletedFile;
private boolean deletedFile;
public String getDiff() {
return _diff;
return diff;
}
public void setDiff(String diff) {
_diff = diff;
this.diff = diff;
}
public String getNewPath() {
return _newPath;
return newPath;
}
public void setNewPath(String newPath) {
_newPath = newPath;
this.newPath = newPath;
}
public String getOldPath() {
return _oldPath;
return oldPath;
}
public void setOldPath(String oldPath) {
_oldPath = oldPath;
this.oldPath = oldPath;
}
public String getAMode() {
return _aMode;
return aMode;
}
public void setAMode(String aMode) {
_aMode = aMode;
this.aMode = aMode;
}
public String getBMode() {
return _bMode;
return bMode;
}
public void setBMode(String bMode) {
_bMode = bMode;
this.bMode = bMode;
}
public boolean getNewFile() {
return _newFile;
return newFile;
}
public void setNewFile(boolean newFile) {
_newFile = newFile;
this.newFile = newFile;
}
public boolean getRenamedFile() {
return _renamedFile;
return renamedFile;
}
public void setRenamedFile(boolean renamedFile) {
_renamedFile = renamedFile;
this.renamedFile = renamedFile;
}
public boolean getDeletedFile() {
return _deletedFile;
return deletedFile;
}
public void setDeletedFile(boolean deletedFile) {
_deletedFile = deletedFile;
this.deletedFile = deletedFile;
}
}
......@@ -6,53 +6,53 @@ public class GitlabGroup {
public static final String URL = "/groups";
private Integer _id;
private String _name;
private String _path;
private Integer id;
private String name;
private String path;
@JsonProperty("ldap_cn")
private String _ldapCn;
private String ldapCn;
@JsonProperty("ldap_access")
private Integer _ldapAccess;
private Integer ldapAccess;
public Integer getId() {
return _id;
return id;
}
public void setId(Integer id) {
_id = id;
this.id = id;
}
public String getName() {
return _name;
return name;
}
public void setName(String name) {
_name = name;
this.name = name;
}
public String getPath() {
return _path;
return path;
}
public void setPath(String path) {
_path = path;
this.path = path;
}
public String getLdapCn() {
return _ldapCn;
return ldapCn;
}
public void setLdapCn(String ldapCn) {
this._ldapCn = ldapCn;
this.ldapCn = ldapCn;
}
public GitlabAccessLevel getLdapAccess() {
return GitlabAccessLevel.fromAccessValue(_ldapAccess);
return GitlabAccessLevel.fromAccessValue(ldapAccess);
}
public void setLdapAccess(GitlabAccessLevel ldapGitlabAccessLevel) {
this._ldapAccess = ldapGitlabAccessLevel.accessValue;
this.ldapAccess = ldapGitlabAccessLevel.accessValue;
}
}
package org.gitlab.api.models;
import java.util.Date;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.Date;
public class GitlabIssue {
public enum Action {
LEAVE, CLOSE, REOPEN
}
public static final String StateClosed = "closed";
public static final String StateOpened = "opened";
public static final String URL = "/issues";
private int _id;
private int _iid;
@JsonProperty("project_id")
private int _projectId;
private String _title;
private String _description;
private String[] _labels;
private GitlabMilestone _milestone;
private GitlabUser _assignee;
private GitlabUser _author;
private String _state;
@JsonProperty("updated_at")
private Date _updatedAt;
@JsonProperty("created_at")
private Date _createdAt;
public int getId() {
return _id;
}
public void setId(int id) {
_id = id;
}
public int getIid() {
return _iid;
}
public void setIid(int iid) {
_iid = iid;
}
public int getProjectId() {
return _projectId;
}
public void setProjectId(int projectId) {
_projectId = projectId;
}
public String getTitle() {
return _title;
}
public void setTitle(String title) {
_title = title;
}
public String getDescription() {
return _description;
}
public void setDescription(String description) {
_description = description;
}
public String[] getLabels() {
return _labels;
}
public void setLabels(String[] labels) {
_labels = labels;
}
public GitlabMilestone getMilestone() {
return _milestone;
}
public void setMilestone(GitlabMilestone milestone) {
_milestone = milestone;
}
public GitlabUser getAssignee() {
return _assignee;
}
public void setAssignee(GitlabUser assignee) {
_assignee = assignee;
}
public GitlabUser getAuthor() {
return _author;
}
public void setAuthor(GitlabUser author) {
_author = author;
}
public String getState() {
return _state;
}
public void setState(String state) {
_state = state;
}
public Date getUpdatedAt() {
return _updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
_updatedAt = updatedAt;
}
public Date getCreatedAt() {
return _createdAt;
}
public void setCreatedAt(Date createdAt) {
_createdAt = createdAt;
}
public enum Action {
LEAVE, CLOSE, REOPEN
}
public static final String STATE_CLOSED = "closed";
public static final String STATE_OPENED = "opened";
public static final String URL = "/issues";
private int id;
private int iid;
@JsonProperty("project_id")
private int projectId;
private String title;
private String description;
private String[] labels;
private GitlabMilestone milestone;
private GitlabUser assignee;
private GitlabUser author;
private String state;
@JsonProperty("updated_at")
private Date updatedAt;
@JsonProperty("created_at")
private Date createdAt;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getIid() {
return iid;
}
public void setIid(int iid) {
this.iid = iid;
}
public int getProjectId() {
return projectId;
}
public void setProjectId(int projectId) {
this.projectId = projectId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String[] getLabels() {
return labels;
}
public void setLabels(String[] labels) {
this.labels = labels;
}
public GitlabMilestone getMilestone() {
return milestone;
}
public void setMilestone(GitlabMilestone milestone) {
this.milestone = milestone;
}
public GitlabUser getAssignee() {
return assignee;
}
public void setAssignee(GitlabUser assignee) {
this.assignee = assignee;
}
public GitlabUser getAuthor() {
return author;
}
public void setAuthor(GitlabUser author) {
this.author = author;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
}
......@@ -5,136 +5,145 @@ import org.codehaus.jackson.annotate.JsonProperty;
public class GitlabMergeRequest {
public static final String URL = "/merge_requests";
private Integer _id;
private Integer _iid;
private String _title;
private String _state;
private String _description;
private boolean _closed;
private boolean _merged;
private GitlabUser _author;
private GitlabUser _assignee;
private Integer id;
private Integer iid;
private String title;
private String state;
private String description;
private boolean closed;
private boolean merged;
private GitlabUser author;
private GitlabUser assignee;
@JsonProperty("target_branch")
private String _targetBranch;
private String targetBranch;
@JsonProperty("source_branch")
private String _sourceBranch;
private String sourceBranch;
@JsonProperty("project_id")
private Integer _projectId;
private Integer projectId;
@JsonProperty("source_project_id")
private Integer _sourceProjectId;
private Integer sourceProjectId;
@JsonProperty("milestone_id")
private Integer _milestone_id;
private Integer milestoneId;
public Integer getId() {
return _id;
return id;
}
public void setId(Integer id) {
_id = id;
this.id = id;
}
public Integer getMilestoneId(){ return _milestone_id; }
public void setMilestoneId(Integer id) { _milestone_id = id; }
public Integer getMilestoneId() {
return milestoneId;
}
public void setMilestoneId(Integer id) {
milestoneId = id;
}
public Integer getIid() {
return _iid;
return iid;
}
public void setIid(Integer iid) {
_iid = iid;
this.iid = iid;
}
public String getTargetBranch() {
return _targetBranch;
return targetBranch;
}
public void setTargetBranch(String targetBranch) {
_targetBranch = targetBranch;
this.targetBranch = targetBranch;
}
public String getSourceBranch() {
return _sourceBranch;
return sourceBranch;
}
public void setSourceBranch(String sourceBranch) {
_sourceBranch = sourceBranch;
this.sourceBranch = sourceBranch;
}
public Integer getProjectId() {
return _projectId;
return projectId;
}
public void setProjectId(Integer projectId) {
_projectId = projectId;
this.projectId = projectId;
}
public Integer getSourceProjectId() {
return _sourceProjectId;
return sourceProjectId;
}
public void setSourceProjectId(Integer sourceProjectId) {
_sourceProjectId = sourceProjectId;
this.sourceProjectId = sourceProjectId;
}
public String getTitle() {
return _title;
return title;
}
public void setTitle(String title) {
_title = title;
this.title = title;
}
public String getDescription() { return _description; }
public String getDescription() {
return description;
}
public void setDescription(String d) { _description = d; }
public void setDescription(String d) {
description = d;
}
public boolean isClosed() {
return _closed;
return closed;
}
public void setClosed(boolean closed) {
_closed = closed;
this.closed = closed;
}
public boolean isMerged() {
return _merged;
return merged;
}
public void setMerged(boolean merged) {
_merged = merged;
this.merged = merged;
}
public GitlabUser getAuthor() {
return _author;
return author;
}
public void setAuthor(GitlabUser author) {
_author = author;
this.author = author;
}
public GitlabUser getAssignee() {
return _assignee;
return assignee;
}
public void setAssignee(GitlabUser assignee) {
_assignee = assignee;
this.assignee = assignee;
}
public String getState() {
return _state;
return state;
}
public void setState(String state) {
_state = state;
if(state != null) {
_closed = state.equals("closed");
_merged = state.equals("merged");
this.state = state;
if (state != null) {
closed = state.equals("closed");
merged = state.equals("merged");
}
}
}
package org.gitlab.api.models;
import java.util.Date;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.Date;
public class GitlabMilestone {
public static final String URL = "/milestones";
private int _id;
private int _iid;
private int _projectId;
private String _title;
private String _description;
@JsonProperty("due_date")
private Date _dueDate;
private String _state;
@JsonProperty("updated_date")
private Date _updatedDate;
@JsonProperty("created_date")
private Date _createdDate;
public int getId() {
return _id;
}
public void setId(int id) {
_id = id;
}
public int getIid() {
return _iid;
}
public void setIid(int iid) {
_iid = iid;
}
public int getProjectId() {
return _projectId;
}
public void setProjectId(int projectId) {
_projectId = projectId;
}
public String getTitle() {
return _title;
}
public void setTitle(String title) {
_title = title;
}
public String getDescription() {
return _description;
}
public void setDescription(String description) {
_description = description;
}
public Date getDueDate() {
return _dueDate;
}
public void setDueDate(Date dueDate) {
_dueDate = dueDate;
}
public String getState() {
return _state;
}
public void setState(String state) {
_state = state;
}
public Date getUpdatedDate() {
return _updatedDate;
}
public void setUpdatedDate(Date updatedDate) {
_updatedDate = updatedDate;
}
public Date getCreatedDate() {
return _createdDate;
}
public void setCreatedDate(Date createdDate) {
_createdDate = createdDate;
}
public static final String URL = "/milestones";
private int id;
private int iid;
private int projectId;
private String title;
private String description;
@JsonProperty("due_date")
private Date dueDate;
private String state;
@JsonProperty("updated_date")
private Date updatedDate;
@JsonProperty("created_date")
private Date createdDate;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getIid() {
return iid;
}
public void setIid(int iid) {
this.iid = iid;
}
public int getProjectId() {
return projectId;
}
public void setProjectId(int projectId) {
this.projectId = projectId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getDueDate() {
return dueDate;
}
public void setDueDate(Date dueDate) {
this.dueDate = dueDate;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public Date getUpdatedDate() {
return updatedDate;
}
public void setUpdatedDate(Date updatedDate) {
this.updatedDate = updatedDate;
}
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
}
package org.gitlab.api.models;
import java.util.Date;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.Date;
public class GitlabNamespace {
public static final String URL = "/groups";
private Integer _id;
private String _name;
private String _path;
private String _description;
public static final String URL = "/groups";
private Integer id;
private String name;
private String path;
private String description;
@JsonProperty("created_at")
private Date _createdAt;
private Date createdAt;
@JsonProperty("updated_at")
private Date _updatedAt;
private Date updatedAt;
@JsonProperty("owner_id")
private Integer _ownerId;
private Integer ownerId;
public Integer getId() {
return _id;
return id;
}
public void setId(Integer id) {
_id = id;
this.id = id;
}
public Date getCreatedAt() {
return _createdAt;
return createdAt;
}
public void setCreatedAt(Date createdAt) {
_createdAt = createdAt;
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return _updatedAt;
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
_updatedAt = updatedAt;
this.updatedAt = updatedAt;
}
public Integer getOwnerId() {
return _ownerId;
return ownerId;
}
public void setOwnerId(Integer ownerId) {
_ownerId = ownerId;
this.ownerId = ownerId;
}
public String getName() {
return _name;
return name;
}
public void setName(String name) {
_name = name;
this.name = name;
}
public String getPath() {
return _path;
return path;
}
public void setPath(String path) {
_path = path;
this.path = path;
}
public String getDescription() {
return _description;
return description;
}
public void setDescription(String description) {
_description = description;
this.description = description;
}
}
package org.gitlab.api.models;
import java.util.Date;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.Date;
public class GitlabNote {
public static final String URL = "/notes";
private Integer _id;
private String _body;
private String _attachment;
private GitlabUser _author;
private Integer id;
private String body;
private String attachment;
private GitlabUser author;
@JsonProperty("created_at")
private Date _createdAt;
private Date createdAt;
public Integer getId() {
return _id;
return id;
}
public void setId(Integer id) {
_id = id;
this.id = id;
}
public String getBody() {
return _body;
return body;
}
public void setBody(String body) {
_body = body;
this.body = body;
}
public GitlabUser getAuthor() {
return _author;
return author;
}
public void setAuthor(GitlabUser author) {
_author = author;
this.author = author;
}
public Date getCreatedAt() {
return _createdAt;
return createdAt;
}
public void setCreatedAt(Date createdAt) {
_createdAt = createdAt;
this.createdAt = createdAt;
}
public String getAttachment() {
return _attachment;
return attachment;
}
public void setAttachment(String attachment) {
_attachment = attachment;
this.attachment = attachment;
}
}
package org.gitlab.api.models;
import org.codehaus.jackson.annotate.JsonProperty;
public class GitlabPermission {
@JsonProperty("project_access")
private GitlabProjectAccessLevel projectAccess;
@JsonProperty("group_access")
private GitlabProjectAccessLevel groupAccess;
public GitlabProjectAccessLevel getProjectAccess() {
return projectAccess;
}
public GitlabProjectAccessLevel getProjectGroupAccess() {
return groupAccess;
}
}
package org.gitlab.api.models;
import org.codehaus.jackson.annotate.JsonProperty;
public class GitlabPersmission {
@JsonProperty("project_access")
private GitlabProjectAccessLevel _projectAccess;
@JsonProperty("group_access")
private GitlabProjectAccessLevel _groupAccess;
public GitlabProjectAccessLevel getProjectAccess() {
return _projectAccess;
}
public GitlabProjectAccessLevel getProjectGroupAccess() {
return _groupAccess;
}
}
package org.gitlab.api.models;
import java.util.Date;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.Date;
public class GitlabProject {
public static final String URL = "/projects";
private Integer _id;
private String _name;
private Integer id;
private String name;
@JsonProperty("name_with_namespace")
private String _nameWithNamespace;
private String nameWithNamespace;
private String _description;
private String description;
@JsonProperty("default_branch")
private String _defaultBranch;
private String defaultBranch;
private GitlabUser _owner;
private boolean _public;
private String _path;
private GitlabUser owner;
private boolean publicProject;
private String path;
@JsonProperty("visibility_level")
private Integer _visibilityLevel;
private Integer visibilityLevel;
@JsonProperty("path_with_namespace")
private String _pathWithNamespace;
private String pathWithNamespace;
@JsonProperty("issues_enabled")
private boolean _issuesEnabled;
private boolean issuesEnabled;
@JsonProperty("merge_requests_enabled")
private boolean _mergeRequestsEnabled;
private boolean mergeRequestsEnabled;
@JsonProperty("snippets_enabled")
private boolean _snippetsEnabled;
private boolean snippetsEnabled;
@JsonProperty("wall_enabled")
private boolean _wallEnabled;
private boolean wallEnabled;
@JsonProperty("wiki_enabled")
private boolean _wikiEnabled;
private boolean wikiEnabled;
@JsonProperty("created_at")
private Date _createdAt;
private Date createdAt;
@JsonProperty("ssh_url_to_repo")
private String _sshUrl;
private String sshUrl;
@JsonProperty("web_url")
private String _webUrl;
private String webUrl;
@JsonProperty("http_url_to_repo")
private String _httpUrl;
private String httpUrl;
@JsonProperty("last_activity_at")
private Date _lastActivityAt;
private Date lastActivityAt;
@JsonProperty("archived")
private boolean _archived;
private boolean archived;
private GitlabNamespace namespace;
private GitlabNamespace _namespace;
@JsonProperty("permissions")
private GitlabPersmission _permissions;
private GitlabPermission permissions;
public Integer getId() {
return _id;
return id;
}
public void setId(Integer id) {
_id = id;
this.id = id;
}
public String getName() {
return _name;
return name;
}
public void setName(String name) {
_name = name;
this.name = name;
}
public String getNameWithNamespace() {
return _nameWithNamespace;
return nameWithNamespace;
}
public void setNameWithNamespace(String nameWithNamespace) {
this._nameWithNamespace = nameWithNamespace;
this.nameWithNamespace = nameWithNamespace;
}
public String getDescription() {
return _description;
return description;
}
public void setDescription(String description) {
_description = description;
this.description = description;
}
public String getDefaultBranch() {
return _defaultBranch;
return defaultBranch;
}
public void setDefaultBranch(String defaultBranch) {
_defaultBranch = defaultBranch;
this.defaultBranch = defaultBranch;
}
public Integer getVisibilityLevel() {
return _visibilityLevel;
return visibilityLevel;
}
public void setVisibilityLevel(Integer visibilityLevel) {
this._visibilityLevel = visibilityLevel;
this.visibilityLevel = visibilityLevel;
}
public GitlabUser getOwner() {
return _owner;
return owner;
}
public void setOwner(GitlabUser owner) {
_owner = owner;
this.owner = owner;
}
public String getPath() {
return _path;
return path;
}
public void setPath(String path) {
_path = path;
this.path = path;
}
public String getPathWithNamespace() {
return _pathWithNamespace;
return pathWithNamespace;
}
public void setPathWithNamespace(String pathWithNamespace) {
_pathWithNamespace = pathWithNamespace;
this.pathWithNamespace = pathWithNamespace;
}
public boolean isIssuesEnabled() {
return _issuesEnabled;
return issuesEnabled;
}
public void setIssuesEnabled(boolean issuesEnabled) {
_issuesEnabled = issuesEnabled;
this.issuesEnabled = issuesEnabled;
}
public boolean isMergeRequestsEnabled() {
return _mergeRequestsEnabled;
return mergeRequestsEnabled;
}
public void setMergeRequestsEnabled(boolean mergeRequestsEnabled) {
_mergeRequestsEnabled = mergeRequestsEnabled;
this.mergeRequestsEnabled = mergeRequestsEnabled;
}
public boolean isSnippetsEnabled() {
return _snippetsEnabled;
return snippetsEnabled;
}
public void setSnippetsEnabled(boolean snippetsEnabled) {
this._snippetsEnabled = snippetsEnabled;
this.snippetsEnabled = snippetsEnabled;
}
public boolean isWallEnabled() {
return _wallEnabled;
return wallEnabled;
}
public void setWallEnabled(boolean wallEnabled) {
_wallEnabled = wallEnabled;
this.wallEnabled = wallEnabled;
}
public boolean isWikiEnabled() {
return _wikiEnabled;
return wikiEnabled;
}
public void setWikiEnabled(boolean wikiEnabled) {
_wikiEnabled = wikiEnabled;
this.wikiEnabled = wikiEnabled;
}
public Date getCreatedAt() {
return _createdAt;
return createdAt;
}
public void setCreatedAt(Date createdAt) {
_createdAt = createdAt;
this.createdAt = createdAt;
}
public String getSshUrl() {
return _sshUrl;
return sshUrl;
}
public void setSshUrl(String sshUrl) {
_sshUrl = sshUrl;
this.sshUrl = sshUrl;
}
public String getWebUrl() {
return _webUrl;
return webUrl;
}
public void setWebUrl(String webUrl) {
_webUrl = webUrl;
this.webUrl = webUrl;
}
public String getHttpUrl() {
return _httpUrl;
return httpUrl;
}
public void setHttpUrl(String httpUrl) {
_httpUrl = httpUrl;
this.httpUrl = httpUrl;
}
public GitlabNamespace getNamespace() {
return _namespace;
return namespace;
}
public void setNamespace(GitlabNamespace namespace) {
_namespace = namespace;
this.namespace = namespace;
}
public boolean isPublic() {
return _public;
return publicProject;
}
public void setPublic(boolean aPublic) {
_public = aPublic;
publicProject = aPublic;
}
public boolean isArchived() {
return _archived;
return archived;
}
public void setArchived(boolean archived) {
_archived = archived;
this.archived = archived;
}
public Date getLastActivityAt() {
return _lastActivityAt;
return lastActivityAt;
}
public void setLastActivityAt(Date lastActivityAt) {
_lastActivityAt = lastActivityAt;
this.lastActivityAt = lastActivityAt;
}
public GitlabPersmission getPermissions() {
return _permissions;
}
public GitlabPermission getPermissions() {
return permissions;
}
public void setPermissions(GitlabPersmission permissions) {
this._permissions = permissions;
}
public void setPermissions(GitlabPermission permissions) {
this.permissions = permissions;
}
}
......@@ -4,29 +4,29 @@ import org.codehaus.jackson.annotate.JsonProperty;
public class GitlabProjectAccessLevel {
@JsonProperty("access_level")
private int _accessLevel;
@JsonProperty("notification_level")
private int _notificationLevel;
public GitlabAccessLevel getAccessLevel() {
return GitlabAccessLevel.fromAccessValue(_accessLevel);
}
public void setAccessLevel(GitlabAccessLevel accessLevel) {
_accessLevel = accessLevel.accessValue;
}
public int getNoficationLevel() {
return _notificationLevel;
}
public void setNoficationLevel(int notificationLevel) {
this._accessLevel=notificationLevel;
}
@JsonProperty("access_level")
private int accessLevel;
@JsonProperty("notification_level")
private int notificationLevel;
public GitlabAccessLevel getAccessLevel() {
return GitlabAccessLevel.fromAccessValue(accessLevel);
}
public void setAccessLevel(GitlabAccessLevel accessLevel) {
this.accessLevel = accessLevel.accessValue;
}
public int getNoficationLevel() {
return notificationLevel;
}
public void setNoficationLevel(int notificationLevel) {
this.accessLevel = notificationLevel;
}
}
package org.gitlab.api.models;
import java.util.Date;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.Date;
public class GitlabProjectHook {
public final static String URL = "/hooks";
private String _id;
private String _url;
private Integer _projectId;
public final static String URL = "/hooks";
private String id;
private String url;
private Integer projectId;
@JsonProperty("push_events")
private boolean _pushEvents;
@JsonProperty("push_events")
private boolean pushEvents;
@JsonProperty("issues_events")
private boolean _issueEvents;
@JsonProperty("issues_events")
private boolean issueEvents;
@JsonProperty("merge_requests_events")
private boolean _mergeRequestsEvents;
@JsonProperty("merge_requests_events")
private boolean mergeRequestsEvents;
@JsonProperty("created_at")
private Date _createdAt;
public String getId() {
return _id;
@JsonProperty("created_at")
private Date createdAt;
public String getId() {
return id;
}
public void setId(String id) {
_id = id;
this.id = id;
}
public String getUrl() {
return _url;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this._url = url;
}
public Integer getProjectId() {
return _projectId;
}
public void setUrl(String url) {
this.url = url;
}
public void setProjectId(Integer projectId) {
_projectId = projectId;
}
public Integer getProjectId() {
return projectId;
}
public boolean getPushEvents() {
return _pushEvents;
}
public void setProjectId(Integer projectId) {
this.projectId = projectId;
}
public boolean getPushEvents() {
return pushEvents;
}
public void setPushEvents(boolean pushEvents) {
_pushEvents = pushEvents;
}
public void setPushEvents(boolean pushEvents) {
this.pushEvents = pushEvents;
}
public boolean getIssueEvents() {
return _issueEvents;
}
public boolean getIssueEvents() {
return issueEvents;
}
public void setIssueEvents(boolean issueEvents) {
_issueEvents = issueEvents;
}
public void setIssueEvents(boolean issueEvents) {
this.issueEvents = issueEvents;
}
public boolean isMergeRequestsEvents() {
return _mergeRequestsEvents;
}
public boolean isMergeRequestsEvents() {
return mergeRequestsEvents;
}
public void setMergeRequestsEvents(boolean mergeRequestsEvents) {
_mergeRequestsEvents = mergeRequestsEvents;
}
public void setMergeRequestsEvents(boolean mergeRequestsEvents) {
this.mergeRequestsEvents = mergeRequestsEvents;
}
public Date getCreatedAt() {
return _createdAt;
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
_createdAt = createdAt;
this.createdAt = createdAt;
}
}
\ No newline at end of file
}
......@@ -3,17 +3,18 @@ package org.gitlab.api.models;
import org.codehaus.jackson.annotate.JsonProperty;
public class GitlabSession extends GitlabUser {
public static final String URL = "/session";
@JsonProperty("private_token")
private String _privateToken;
public String getPrivateToken() {
return _privateToken;
}
public static final String URL = "/session";
@JsonProperty("private_token")
private String privateToken;
public String getPrivateToken() {
return privateToken;
}
public void setPrivateToken(String privateToken) {
this.privateToken = privateToken;
}
public void setPrivateToken(String privateToken) {
_privateToken = privateToken;
}
}
package org.gitlab.api.models;
import java.util.Date;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.Date;
public class GitlabUser {
public static String URL = "/users";
public static String USERS_URL = "/users";
......@@ -18,16 +19,16 @@ public class GitlabUser {
private String _provider;
private String _state;
private boolean _blocked;
@JsonProperty("private_token")
private String _privateToken;
@JsonProperty("color_scheme_id")
private Integer _colorSchemeId;
@JsonProperty("provider")
private String _externProviderName;
@JsonProperty("website_url")
private String _websiteUrl;
......@@ -57,7 +58,7 @@ public class GitlabUser {
@JsonProperty("can_create_team")
private boolean _canCreateTeam;
@JsonProperty("avatar_url")
private String _avatarUrl;
......@@ -180,21 +181,21 @@ public class GitlabUser {
public void setState(String state) {
_state = state;
}
public String getExternProviderName() {
return _externProviderName;
}
public void setExternProviderName(String externProviderName) {
_externProviderName = externProviderName;
_externProviderName = externProviderName;
}
public String getWebsiteUrl() {
return _websiteUrl;
}
public void setWebsiteUrl(String websiteUrl) {
_websiteUrl = websiteUrl;
_websiteUrl = websiteUrl;
}
public boolean isAdmin() {
......@@ -229,27 +230,27 @@ public class GitlabUser {
_canCreateTeam = canCreateTeam;
}
public String getAvatarUrl() {
return _avatarUrl;
}
public String getAvatarUrl() {
return _avatarUrl;
}
public void setAvatarUrl(String avatarUrl) {
this._avatarUrl = avatarUrl;
}
public void setAvatarUrl(String avatarUrl) {
this._avatarUrl = avatarUrl;
}
public Integer getColorSchemeId() {
return _colorSchemeId;
}
public Integer getColorSchemeId() {
return _colorSchemeId;
}
public void setColorSchemeId(Integer colorSchemeId) {
this._colorSchemeId = colorSchemeId;
}
public void setColorSchemeId(Integer colorSchemeId) {
this._colorSchemeId = colorSchemeId;
}
public String getPrivateToken() {
return _privateToken;
}
public String getPrivateToken() {
return _privateToken;
}
public void setPrivateToken(String privateToken) {
this._privateToken = privateToken;
}
public void setPrivateToken(String privateToken) {
this._privateToken = privateToken;
}
}
package org.gitlab.api;
import org.gitlab.api.models.GitlabUser;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.ConnectException;
import java.net.URL;
import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeNoException;
import java.net.ConnectException;
public class GitlabAPIT {
GitlabAPI _api;
GitlabAPI api;
private static final String TEST_URL = System.getProperty("TEST_URL", "http://localhost");
private static final String TEST_TOKEN = System.getProperty("TEST_TOKEN", "y0E5b9761b7y4qk");
String rand = UUID.randomUUID().toString().replace("-", "").substring(0, 8);
String rand = UUID.randomUUID().toString().replace("-", "").substring(0, 8);
@Before
public void setup() throws IOException {
_api = GitlabAPI.connect(TEST_URL, TEST_TOKEN);
api = GitlabAPI.connect(TEST_URL, TEST_TOKEN);
try {
_api.dispatch().with("login", "INVALID").with("password", rand).to("session", GitlabUser.class);
api.dispatch().with("login", "INVALID").with("password", rand).to("session", GitlabUser.class);
} catch (ConnectException e) {
assumeNoException("GITLAB not running on '" + TEST_URL + "', skipping...", e);
} catch (IOException e) {
......@@ -43,78 +40,77 @@ public class GitlabAPIT {
@Test
public void testConnect() throws IOException {
assertEquals(GitlabAPI.class, _api.getClass());
assertEquals(GitlabAPI.class, api.getClass());
}
@Test
public void testGetAPIUrl() throws IOException {
URL expected = new URL(TEST_URL+"/api/v3/?private_token="+TEST_TOKEN);
assertEquals(expected, _api.getAPIUrl(""));
URL expected = new URL(TEST_URL + "/api/v3/?private_token=" + TEST_TOKEN);
assertEquals(expected, api.getAPIUrl(""));
}
@Test
public void testGetUrl() throws IOException {
URL expected = new URL(TEST_URL);
assertEquals(expected +"/", _api.getUrl("").toString());
assertEquals(expected + "/", api.getUrl("").toString());
}
@Test
@Test
public void testCreateUpdateDeleteUser() throws IOException {
String password = randVal("$%password");
GitlabUser gitUser = _api.createUser(randVal("testEmail@gitlabapitest.com"),
password,
randVal("userName"),
randVal("fullName"),
randVal("skypeId"),
randVal("linledin"),
randVal("twitter"),
"http://"+randVal("url.com"),
10,
randVal("externuid"),
randVal("externprovidername"),
randVal("bio"),
false,
false,
false);
Assert.assertNotNull(gitUser);
GitlabUser refetched = _api.getUserViaSudo(gitUser.getUsername());
Assert.assertNotNull(refetched);
Assert.assertEquals(refetched.getUsername(),gitUser.getUsername());
_api.updateUser(gitUser.getId(), gitUser.getEmail(), password , gitUser.getUsername(),
gitUser.getName(), "newSkypeId", gitUser.getLinkedin(), gitUser.getTwitter(), gitUser.getWebsiteUrl(),
10 /* project limit does not come back on GET */, gitUser.getExternUid(), gitUser.getExternProviderName(),
gitUser.getBio(), gitUser.isAdmin(), gitUser.isCanCreateGroup(), false);
GitlabUser postUpdate = _api.getUserViaSudo(gitUser.getUsername());
Assert.assertNotNull(postUpdate);
Assert.assertEquals(postUpdate.getSkype(),"newSkypeId");
_api.deleteUser(postUpdate.getId());
// expect a 404, but we have no access to it
try {
GitlabUser shouldNotExist = _api.getUser(postUpdate.getId());
Assert.assertNull(shouldNotExist); // should never even get here
} catch(FileNotFoundException thisIsSoOddForAnRESTApiClient) {
Assert.assertTrue(true); // expected
}
String password = randVal("$%password");
GitlabUser gitUser = api.createUser(randVal("testEmail@gitlabapitest.com"),
password,
randVal("userName"),
randVal("fullName"),
randVal("skypeId"),
randVal("linledin"),
randVal("twitter"),
"http://" + randVal("url.com"),
10,
randVal("externuid"),
randVal("externprovidername"),
randVal("bio"),
false,
false,
false);
assertNotNull(gitUser);
GitlabUser refetched = api.getUserViaSudo(gitUser.getUsername());
assertNotNull(refetched);
assertEquals(refetched.getUsername(), gitUser.getUsername());
api.updateUser(gitUser.getId(), gitUser.getEmail(), password, gitUser.getUsername(),
gitUser.getName(), "newSkypeId", gitUser.getLinkedin(), gitUser.getTwitter(), gitUser.getWebsiteUrl(),
10 /* project limit does not come back on GET */, gitUser.getExternUid(), gitUser.getExternProviderName(),
gitUser.getBio(), gitUser.isAdmin(), gitUser.isCanCreateGroup(), false);
GitlabUser postUpdate = api.getUserViaSudo(gitUser.getUsername());
assertNotNull(postUpdate);
assertEquals(postUpdate.getSkype(), "newSkypeId");
api.deleteUser(postUpdate.getId());
// expect a 404, but we have no access to it
try {
GitlabUser shouldNotExist = api.getUser(postUpdate.getId());
assertNull(shouldNotExist);
} catch (FileNotFoundException thisIsSoOddForAnRESTApiClient) {
assertTrue(true); // expected
}
}
private String randVal(String postfix) {
return rand + "-" + postfix;
return rand + "-" + postfix;
}
}
package org.gitlab.api.http;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.UnsupportedEncodingException;
import static org.junit.Assert.assertEquals;
public class QueryTest {
@Test
......@@ -20,8 +21,8 @@ public class QueryTest {
@Test
public void fluentStyle_append() throws UnsupportedEncodingException {
Query query = new Query()
.append("p1", "v1")
.append("p2", "v2");
.append("p1", "v1")
.append("p2", "v2");
assertEquals("?p1=v1&p2=v2", query.toString());
}
......@@ -42,8 +43,8 @@ public class QueryTest {
@Test
public void conditionalAppend_notNull() throws UnsupportedEncodingException {
Query query = new Query()
.appendIf("p1", "v1")
.appendIf("p2", "v2");
.appendIf("p1", "v1")
.appendIf("p2", "v2");
assertEquals("?p1=v1&p2=v2", query.toString());
}
......@@ -51,7 +52,7 @@ public class QueryTest {
@Test
public void conditionalAppend_null() throws UnsupportedEncodingException {
Query query = new Query()
.appendIf("p1", (String) null);
.appendIf("p1", (String) null);
assertEquals("", query.toString());
}
......@@ -59,7 +60,7 @@ public class QueryTest {
@Test
public void conditionalAppend_null_notNull() throws UnsupportedEncodingException {
Query query = new Query()
.appendIf("p1", (String)null)
.appendIf("p1", (String) null)
.appendIf("p2", "v2");
assertEquals("?p2=v2", query.toString());
......@@ -68,8 +69,8 @@ public class QueryTest {
@Test
public void append_encodes_values() throws UnsupportedEncodingException {
Query query = new Query()
.append("p1", "v 1")
.append("p2", "v 2");
.append("p1", "v 1")
.append("p2", "v 2");
assertEquals("?p1=v+1&p2=v+2", query.toString());
}
......
Markdown is supported
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