diff --git a/pom.xml b/pom.xml index 902f0424..1b0685d3 100644 --- a/pom.xml +++ b/pom.xml @@ -83,12 +83,17 @@ com.fasterxml.jackson.core jackson-core - 2.5.3 + 2.13.3 com.fasterxml.jackson.core jackson-databind - 2.9.10.5 + 2.13.3 + + + com.fasterxml.jackson.core + jackson-annotations + 2.13.3 commons-io @@ -226,6 +231,9 @@ org.apache.maven.plugins maven-gpg-plugin 1.6 + + + sign-artifacts diff --git a/src/main/java/org/gitlab/api/GitlabAPI.java b/src/main/java/org/gitlab/api/GitlabAPI.java index c0c88fa7..27959b31 100644 --- a/src/main/java/org/gitlab/api/GitlabAPI.java +++ b/src/main/java/org/gitlab/api/GitlabAPI.java @@ -19,11 +19,7 @@ import java.net.URL; import java.net.URLEncoder; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Collection; +import java.util.*; import static org.gitlab.api.http.Method.*; @@ -1812,8 +1808,9 @@ public GitlabMergeRequest acceptMergeRequest(Serializable projectId, Integer mer GitlabHTTPRequestor requestor = retrieve().method(PUT); requestor.with("id", projectId); requestor.with("merge_request_iid", mergeRequestIid); - if (mergeCommitMessage != null) + if (mergeCommitMessage != null) { requestor.with("merge_commit_message", mergeCommitMessage); + } return requestor.to(tailUrl, GitlabMergeRequest.class); } @@ -2612,7 +2609,10 @@ public void deleteProjectHook(GitlabProject project, String hookId) throws IOExc String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabProjectHook.URL + "/" + hookId; retrieve().method(DELETE).to(tailUrl, Void.class); } - + public List getIssues(String assigneeId){ + String tailUrl = GitlabIssue.URL+"?assigneeId="+assigneeId+"&scope=all"; + return this.retrieve().getAll(tailUrl, GitlabIssue[].class); + } public List getIssues(GitlabProject project) { return getIssues(project.getId()); } diff --git a/src/main/java/org/gitlab/api/TokenType.java b/src/main/java/org/gitlab/api/TokenType.java index 572ca1d7..0a3f073f 100644 --- a/src/main/java/org/gitlab/api/TokenType.java +++ b/src/main/java/org/gitlab/api/TokenType.java @@ -1,7 +1,17 @@ package org.gitlab.api; +/** + * User Token Type + * @author Chi Vinh Le + */ public enum TokenType { + /** + * User private token + */ PRIVATE_TOKEN("private_token", "PRIVATE-TOKEN", "%s"), + /** + * User access token + */ ACCESS_TOKEN("access_token", "Authorization", "Bearer %s"); private final String tokenParamName; diff --git a/src/main/java/org/gitlab/api/http/GitlabHTTPRequestor.java b/src/main/java/org/gitlab/api/http/GitlabHTTPRequestor.java index ebe80573..0fd70615 100644 --- a/src/main/java/org/gitlab/api/http/GitlabHTTPRequestor.java +++ b/src/main/java/org/gitlab/api/http/GitlabHTTPRequestor.java @@ -1,34 +1,22 @@ package org.gitlab.api.http; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.io.Reader; -import java.io.UncheckedIOException; +import org.apache.commons.io.IOUtils; +import org.gitlab.api.AuthMethod; +import org.gitlab.api.GitlabAPI; +import org.gitlab.api.GitlabAPIException; +import org.gitlab.api.TokenType; + +import javax.net.ssl.*; +import java.io.*; import java.lang.reflect.Field; import java.net.*; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; -import javax.net.ssl.*; - -import org.apache.commons.io.IOUtils; -import org.gitlab.api.AuthMethod; -import org.gitlab.api.GitlabAPI; -import org.gitlab.api.GitlabAPIException; -import org.gitlab.api.TokenType; - -import static org.gitlab.api.http.Method.GET; -import static org.gitlab.api.http.Method.POST; -import static org.gitlab.api.http.Method.PUT; +import static org.gitlab.api.http.Method.*; /** * Gitlab HTTP Requestor @@ -86,8 +74,8 @@ public GitlabHTTPRequestor method(Method method) { * Sets the HTTP Form Post parameters for the request * Has a fluent api for method chaining * - * @param key Form parameter Key - * @param value Form parameter Value + * @param key Form parameter Key + * @param value Form parameter Value * @return this */ public GitlabHTTPRequestor with(String key, Object value) { @@ -96,13 +84,13 @@ public GitlabHTTPRequestor with(String key, Object value) { } return this; } - + /** * Sets the HTTP Form Post parameters for the request * Has a fluent api for method chaining * - * @param key Form parameter Key - * @param file File data + * @param key Form parameter Key + * @param file File data * @return this */ public GitlabHTTPRequestor withAttachment(String key, File file) { @@ -138,7 +126,7 @@ public T to(String tailAPIUrl, Class type, T instance) throws IOException if (hasAttachments()) { submitAttachments(connection); } else if (hasOutput()) { - submitData(connection); + 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); @@ -301,7 +289,7 @@ private void submitAttachments(HttpURLConnection connection) throws IOException writer.append("--").append(boundary).append("--").append(CRLF).flush(); } } - + private void submitData(HttpURLConnection connection) throws IOException { connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "application/json"); @@ -311,7 +299,7 @@ private void submitData(HttpURLConnection connection) throws IOException { private boolean hasAttachments() { return !attachments.isEmpty(); } - + private boolean hasOutput() { return method.equals(POST) || method.equals(PUT) && !data.isEmpty(); } @@ -361,13 +349,17 @@ private T parse(HttpURLConnection connection, Class type, T instance) thr if (byte[].class == type) { return type.cast(IOUtils.toByteArray(wrapStream(connection, connection.getInputStream()))); } - reader = new InputStreamReader(wrapStream(connection, connection.getInputStream()), "UTF-8"); + reader = new InputStreamReader(wrapStream(connection, connection.getInputStream()), StandardCharsets.UTF_8); String json = IOUtils.toString(reader); if (type != null && type == String.class) { return type.cast(json); } if (type != null && type != Void.class) { - return GitlabAPI.MAPPER.readValue(json, type); + try { + return GitlabAPI.MAPPER.readValue(json, type); + } catch (Exception e) { + throw new IOException("Json Parse Failed,JSON String:" + json); + } } else if (instance != null) { return GitlabAPI.MAPPER.readerForUpdating(instance).readValue(json); } else { @@ -440,6 +432,7 @@ public void checkServerTrusted( HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); // Added per https://github.com/timols/java-gitlab-api/issues/44 HttpsURLConnection.setDefaultHostnameVerifier(nullVerifier); - } catch (Exception ignore) {} + } catch (Exception ignore) { + } } } diff --git a/src/main/java/org/gitlab/api/http/Method.java b/src/main/java/org/gitlab/api/http/Method.java index 02655e7e..58cc49e0 100644 --- a/src/main/java/org/gitlab/api/http/Method.java +++ b/src/main/java/org/gitlab/api/http/Method.java @@ -1,11 +1,41 @@ package org.gitlab.api.http; /** + * @author Shaburov Oleg * Created by Oleg Shaburov on 03.05.2018 * shaburov.o.a@gmail.com */ public enum Method { - - GET, PUT, POST, PATCH, DELETE, HEAD, OPTIONS, TRACE; - + /** + * HTTP GET method + */ + GET, + /** + * HTTP PUT method + */ + PUT, + /** + * HTTP POST method + */ + POST, + /** + * HTTP PATCH method + */ + PATCH, + /** + * HTTP DELETE method + */ + DELETE, + /** + * HTTP HEAD method + */ + HEAD, + /** + * HTTP OPTIONS + */ + OPTIONS, + /** + * HTTP TRACE + */ + TRACE; } diff --git a/src/main/java/org/gitlab/api/models/GitlabIssue.java b/src/main/java/org/gitlab/api/models/GitlabIssue.java index 046fe609..63cec8ac 100644 --- a/src/main/java/org/gitlab/api/models/GitlabIssue.java +++ b/src/main/java/org/gitlab/api/models/GitlabIssue.java @@ -1,14 +1,14 @@ package org.gitlab.api.models; -import java.time.LocalDate; -import java.util.Date; -import java.util.List; - import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; +import java.time.LocalDate; +import java.util.Date; +import java.util.List; + @JsonIgnoreProperties(ignoreUnknown = true) public class GitlabIssue { @@ -71,6 +71,9 @@ public enum Action { @JsonProperty("web_url") private String webUrl; + @JsonProperty("moved_to_id") + private String movedToId; + public int getId() { return id; } @@ -134,6 +137,7 @@ public List getAssignees() { public void setAssignees(List assignees) { this.assignees = assignees; } + public GitlabUser getAssignee() { return assignee; } @@ -230,4 +234,27 @@ public void setCreatedAt(Date createdAt) { this.createdAt = createdAt; } + public Date getClosedAt() { + return closedAt; + } + + public void setClosedAt(Date closedAt) { + this.closedAt = closedAt; + } + + public String getWebUrl() { + return webUrl; + } + + public void setWebUrl(String webUrl) { + this.webUrl = webUrl; + } + + public String getMovedToId() { + return movedToId; + } + + public void setMovedToId(String movedToId) { + this.movedToId = movedToId; + } }