Commit e380c5ad authored by Paul Weingardt's avatar Paul Weingardt

added GitlabIssue (only get issues and notes for a project)

parent 5daa647d
......@@ -5,10 +5,12 @@ 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.GitlabNote;
import org.gitlab.api.models.GitlabProject;
import org.gitlab.api.models.GitlabProjectHook;
import org.gitlab.api.models.GitlabSession;
import java.io.IOException;
import java.net.URL;
......@@ -34,6 +36,13 @@ public class GitlabAPI {
_hostUrl = hostUrl.endsWith("/") ? hostUrl.replaceAll("/$", "") : hostUrl;
_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);
}
public static GitlabAPI connect(String hostUrl, String apiToken) {
return new GitlabAPI(hostUrl, apiToken);
......@@ -244,4 +253,15 @@ public class GitlabAPI {
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 Arrays.asList(retrieve().to(tailUrl, GitlabIssue[].class));
}
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));
}
}
......@@ -149,7 +149,6 @@ public class GitlabHTTPRequestor {
}
}
@Override
public boolean hasNext() {
fetch();
if (_next.getClass().isArray()) {
......@@ -160,7 +159,6 @@ public class GitlabHTTPRequestor {
}
}
@Override
public T next() {
fetch();
T record = _next;
......
package org.gitlab.api.models;
import java.util.Date;
import org.codehaus.jackson.annotate.JsonProperty;
public class GitlabIssue {
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 String _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 String getMilestone() {
return _milestone;
}
public void setMilestone(String 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;
}
}
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 void setPrivateToken(String privateToken) {
_privateToken = privateToken;
}
}
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