Commit 80e7d982 authored by Tim Olshansky's avatar Tim Olshansky

Merge pull request #20 from caguilar187/master

Diffs, Project Slugs and a couple other things
parents d350223d 6bc36c98
......@@ -4,7 +4,7 @@
<groupId>org.gitlab</groupId>
<artifactId>java-gitlab-api</artifactId>
<version>1.1.5-SNAPSHOT</version>
<version>1.1.6-SNAPSHOT</version>
<name>Gitlab Java API Wrapper</name>
<description>A Java wrapper for the Gitlab Git Hosting Server API</description>
......@@ -28,6 +28,16 @@
<email>adam.retter@googlemail.com</email>
<organization>Evolved Binary Ltd</organization>
</contributor>
<contributor>
<name>Cesar Aguilar</name>
<email>cesar@fuzzproductions.com</email>
<organization>Fuzz Productions</organization>
</contributor>
<contributor>
<name>Chris Luu</name>
<email>luu@fuzzproductions.com</email>
<organization>Fuzz Productions</organization>
</contributor>
</contributors>
<licenses>
......
......@@ -97,6 +97,14 @@ public class GitlabAPI {
return retrieve().getAll( tailUrl, GitlabUser[].class );
}
// Search users by Email or username
// GET /users?search=:email_or_username
public List<GitlabUser> findUsers(String emailOrUsername) throws IOException {
String tailUrl = GitlabUser.URL + "?search=" + emailOrUsername;
GitlabUser[] users = retrieve().to(tailUrl, GitlabUser[].class);
return Arrays.asList(users);
}
public GitlabUser getUser(Integer userId) throws IOException {
String tailUrl = GitlabUser.URL + "/" + userId;
return retrieve().to(tailUrl, GitlabUser.class);
......@@ -299,8 +307,8 @@ public class GitlabAPI {
return dispatch().to(tailUrl, GitlabGroup.class);
}
public GitlabProject getProject(Integer projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + projectId;
public GitlabProject getProject(String projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId);
return retrieve().to(tailUrl, GitlabProject.class);
}
......@@ -422,8 +430,8 @@ public class GitlabAPI {
return openMergeRequests;
}
public List<GitlabMergeRequest> getMergeRequests(Integer projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + projectId + GitlabMergeRequest.URL;
public List<GitlabMergeRequest> getMergeRequests(String projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabMergeRequest.URL;
return fetchMergeRequests(tailUrl);
}
......@@ -460,6 +468,14 @@ public class GitlabAPI {
}
// 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 {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + "/repository/commits/" + commitHash;
GitlabCommit commit = retrieve().to(tailUrl, GitlabCommit.class);
return commit;
}
public List<GitlabCommit> getCommits(GitlabMergeRequest mergeRequest) throws IOException {
Integer projectId = mergeRequest.getSourceProjectId();
if (projectId == null) {
......@@ -476,12 +492,26 @@ public class GitlabAPI {
return Arrays.asList(commits);
}
// 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 {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + "/repository/commits/" + commitHash + GitlabCommitDiff.URL;
GitlabCommitDiff[] diffs = retrieve().to(tailUrl, GitlabCommitDiff[].class);
return Arrays.asList(diffs);
}
public GitlabNote createNote(GitlabMergeRequest mergeRequest, String body) throws IOException {
String tailUrl = GitlabProject.URL + "/" + mergeRequest.getProjectId() +
GitlabMergeRequest.URL + "/" + mergeRequest.getId() + GitlabNote.URL;
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;
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;
......@@ -504,6 +534,12 @@ public class GitlabAPI {
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(GitlabProject project) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabProjectHook.URL;
......@@ -524,6 +560,17 @@ public class GitlabAPI {
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 {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabProjectHook.URL;
return dispatch()
.with("url", url)
.with("push_events", pushEvents ? "true" : "false")
.with("issues_events", issuesEvents ? "true" : "false")
.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()
......@@ -532,6 +579,11 @@ public class GitlabAPI {
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);
}
public void deleteProjectHook(GitlabProject project, String hookId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabProjectHook.URL + "/" + hookId;
......@@ -548,8 +600,8 @@ public class GitlabAPI {
return retrieve().getAll(tailUrl, GitlabIssue[].class);
}
public GitlabIssue getIssue(Integer projectId, Integer issueId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + projectId + GitlabIssue.URL + "/" + issueId;
public GitlabIssue getIssue(String projectId, Integer issueId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabIssue.URL + "/" + issueId;
return retrieve().to(tailUrl, GitlabIssue.class);
}
......@@ -595,31 +647,31 @@ public class GitlabAPI {
return Arrays.asList(retrieve().to(tailUrl, GitlabNote[].class));
}
public GitlabNote createNote(Integer projectId, Integer issueId, String message) throws IOException {
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(GitlabIssue issue, String message) throws IOException {
return createNote(issue.getProjectId(), issue.getId(), message);
return createNote(String.valueOf(issue.getProjectId()), issue.getId(), message);
}
public List<GitlabMilestone> getMilestones(GitlabProject project) throws IOException {
return getMilestones(project.getId());
return getMilestones(String.valueOf(project.getId()));
}
public List<GitlabMilestone> getMilestones(Integer projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + projectId + GitlabMilestone.URL;
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<GitlabProjectMember> getProjectMembers(GitlabProject project) throws IOException {
return getProjectMembers(project.getId());
return getProjectMembers(String.valueOf(project.getId()));
}
public List<GitlabProjectMember> getProjectMembers(Integer projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + projectId + GitlabProjectMember.URL;
public List<GitlabProjectMember> getProjectMembers(String projectId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabProjectMember.URL;
return Arrays.asList(retrieve().to(tailUrl, GitlabProjectMember[].class));
}
......@@ -648,4 +700,8 @@ public class GitlabAPI {
String tailUrl = "/user";
return retrieve().to(tailUrl, GitlabSession.class);
}
private String sanitizeProjectId(String projectId) {
return projectId.replace("/","%2F");
}
}
......@@ -8,8 +8,8 @@ public class GitlabBranch {
@JsonProperty("name")
private String _name;
// @JsonProperty("commit")
// private GitlabCommit _commit;
@JsonProperty("commit")
private GitlabBranchCommit _commit;
@JsonProperty("protected")
private boolean _protected;
......@@ -22,6 +22,14 @@ public class GitlabBranch {
this._name = name;
}
public GitlabBranchCommit getCommit() {
return _commit;
}
public void setCommit(GitlabBranchCommit commit) {
this._commit = commit;
}
public boolean isProtected() {
return _protected;
}
......@@ -29,4 +37,4 @@ public class GitlabBranch {
public void setProtected(boolean isProtected) {
this._protected = isProtected;
}
}
}
\ No newline at end of file
package org.gitlab.api.models;
import org.gitlab.api.models.GitlabUser;
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;
@JsonProperty("authored_date")
private Date _authoredDate;
@JsonProperty("committed_date")
private Date _committedDate;
public String getId() {
return _id;
}
public void setId(String id) {
_id = id;
}
public String getTree() {
return _tree;
}
public void setTree(String tree) {
_tree = tree;
}
public String getMessage() {
return _message;
}
public void setMessage(String message) {
_message = message;
}
public GitlabUser getAuthor() {
return _author;
}
public void setAuthor(GitlabUser author) {
_author = author;
}
public GitlabUser getCommitter() {
return _committer;
}
public void setCommitter(GitlabUser committer) {
_committer = committer;
}
public Date getAuthoredDate() {
return _authoredDate;
}
public void setAuthoredDate(Date authoredDate) {
_authoredDate = authoredDate;
}
public Date getCommittedDate() {
return _committedDate;
}
public void setCommittedDate(Date committedDate) {
_committedDate = committedDate;
}
}
package org.gitlab.api.models;
import java.util.Date;
import java.util.List;
import org.codehaus.jackson.annotate.JsonProperty;
public class GitlabCommit {
......@@ -9,6 +10,7 @@ public class GitlabCommit {
private String _id;
private String _title;
private String _description;
@JsonProperty("short_id")
private String _shortId;
......@@ -22,6 +24,15 @@ public class GitlabCommit {
@JsonProperty("created_at")
private Date _createdAt;
@JsonProperty("committed_date")
private Date _committedDate;
@JsonProperty("authored_date")
private Date _authoredDate;
@JsonProperty("parent_ids")
private List<String> _parentIds;
public String getId() {
return _id;
}
......@@ -46,6 +57,14 @@ public class GitlabCommit {
_title = title;
}
public String getDescription() {
return _description;
}
public void setDescription(String description) {
_description = description;
}
public String getAuthorName() {
return _authorName;
}
......@@ -69,4 +88,12 @@ public class GitlabCommit {
public void setCreatedAt(Date createdAt) {
_createdAt = createdAt;
}
public List<String> getParentIds() {
return _parentIds;
}
public void setParentIds(List<String> parentIds) {
_parentIds = parentIds;
}
}
package org.gitlab.api.models;
import org.codehaus.jackson.annotate.JsonProperty;
public class GitlabCommitDiff {
public final static String URL = "/diff";
@JsonProperty("diff")
private String _diff;
@JsonProperty("new_path")
private String _newPath;
@JsonProperty("old_path")
private String _oldPath;
@JsonProperty("a_mode")
private String _aMode;
@JsonProperty("b_mode")
private String _bMode;
@JsonProperty("new_file")
private boolean _newFile;
@JsonProperty("renamed_file")
private boolean _renamedFile;
@JsonProperty("deleted_file")
private boolean _deletedFile;
public String getDiff() {
return _diff;
}
public void setDiff(String diff) {
_diff = diff;
}
public String getNewPath() {
return _newPath;
}
public void setNewPath(String newPath) {
_newPath = newPath;
}
public String getOldPath() {
return _oldPath;
}
public void setOldPath(String oldPath) {
_oldPath = oldPath;
}
public String getAMode() {
return _aMode;
}
public void setAMode(String aMode) {
_aMode = aMode;
}
public String getBMode() {
return _bMode;
}
public void setBMode(String bMode) {
_bMode = bMode;
}
public boolean getNewFile() {
return _newFile;
}
public void setNewFile(boolean newFile) {
_newFile = newFile;
}
public boolean getRenamedFile() {
return _renamedFile;
}
public void setRenamedFile(boolean renamedFile) {
_renamedFile = renamedFile;
}
public boolean getDeletedFile() {
return _deletedFile;
}
public void setDeletedFile(boolean deletedFile) {
_deletedFile = deletedFile;
}
}
......@@ -49,6 +49,9 @@ public class GitlabProject {
@JsonProperty("ssh_url_to_repo")
private String _sshUrl;
@JsonProperty("web_url")
private String _webUrl;
@JsonProperty("http_url_to_repo")
private String _httpUrl;
......@@ -182,6 +185,14 @@ public class GitlabProject {
_sshUrl = sshUrl;
}
public String getWebUrl() {
return _webUrl;
}
public void setWebUrl(String webUrl) {
_webUrl = webUrl;
}
public String getHttpUrl() {
return _httpUrl;
}
......
......@@ -11,6 +11,17 @@ public class GitlabProjectHook {
private String _id;
private String _url;
private Integer _projectId;
@JsonProperty("push_events")
private boolean _pushEvents;
@JsonProperty("issues_events")
private boolean _issueEvents;
@JsonProperty("merge_requests_events")
private boolean _mergeRequestsEvents;
@JsonProperty("created_at")
private Date _createdAt;
......@@ -31,6 +42,38 @@ public class GitlabProjectHook {
this._url = url;
}
public Integer getProjectId() {
return _projectId;
}
public void setProjectId(Integer projectId) {
_projectId = projectId;
}
public boolean getPushEvents() {
return _pushEvents;
}
public void setPushEvents(boolean pushEvents) {
_pushEvents = pushEvents;
}
public boolean getIssueEvents() {
return _issueEvents;
}
public void setIssueEvents(boolean issueEvents) {
_issueEvents = issueEvents;
}
public boolean isMergeRequestsEvents() {
return _mergeRequestsEvents;
}
public void setMergeRequestsEvents(boolean mergeRequestsEvents) {
_mergeRequestsEvents = mergeRequestsEvents;
}
public Date getCreatedAt() {
return _createdAt;
}
......@@ -38,4 +81,4 @@ public class GitlabProjectHook {
public void setCreatedAt(Date createdAt) {
_createdAt = createdAt;
}
}
}
\ No newline at end of file
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