diff --git a/.travis.yml b/.travis.yml index 87800ef2..257d4981 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ sudo: required services: - docker jdk: -- oraclejdk8 +- openjdk8 install: - ./mvnw -B -q -Pdocker-gitlab dependency:go-offline verify -DskipTests -Ddocker.skip script: diff --git a/build.gradle b/build.gradle index c9fd7ac3..a245c85b 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ sourceCompatibility = 1.8 targetCompatibility = 1.8 group = "org.gitlab" -version = "4.0.1-SNAPSHOT" +version = "4.1.2-SNAPSHOT" repositories { mavenLocal() @@ -23,17 +23,18 @@ repositories { } dependencies { - compile(group: 'org.slf4j', name: 'slf4j-api', version: '1.8.0-beta2') - compile(group: "com.fasterxml.jackson.core", name: "jackson-databind", version: "2.5.+") - compile(group: "commons-io", name: "commons-io", version: "2.4") - testCompile(group: "org.hamcrest", name: "hamcrest-all", version: "1.3") - testCompile(group: 'org.mockito', name: 'mockito-core', version: '2.18.3') - testCompile(group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0') - testCompile(group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.0') - testCompile(group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.2.0') - testRuntime(group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.2.0') - testCompile(group: "junit", name: "junit", version: "4.12") - testRuntime(group: 'org.junit.vintage', name: 'junit-vintage-engine', version: '5.2.0') + compile(group: "org.slf4j", name: "slf4j-api", version: "1.8.0-beta2") + compile(group: "commons-io", name: "commons-io", version: "2.4") + compile(group: "com.fasterxml.jackson.core", name: "jackson-databind", version: "2.5.+") + compile(group: "com.fasterxml.jackson.datatype", name: "jackson-datatype-jsr310", version: "2.5.1") + testCompile(group: "org.apache.logging.log4j", name: "log4j-api", version: "2.11.0") + testCompile(group: "org.apache.logging.log4j", name: "log4j-slf4j-impl", version: "2.11.0") + testCompile(group: "org.hamcrest", name: "hamcrest-all", version: "1.3") + testCompile(group: "org.mockito", name: "mockito-core", version: "2.18.3") + testCompile(group: "org.junit.jupiter", name: "junit-jupiter-api", version: "5.2.0") + testCompile(group: "junit", name: "junit", version: "4.12") + testRuntime(group: "org.junit.jupiter", name: "junit-jupiter-engine", version: "5.2.0") + testRuntime(group: "org.junit.vintage", name: "junit-vintage-engine", version: "5.2.0") } jar { @@ -55,13 +56,9 @@ task sourcesJar(type: Jar, dependsOn:classes) { artifacts { archives sourcesJar } -task wrapper(type: Wrapper) { - gradleVersion = "4.6" -} - test { useJUnitPlatform { includeEngines 'junit-jupiter' includeEngines 'junit-vintage' } -} \ No newline at end of file +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 0d4a9516..f6b961fd 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bf3de218..430dfabc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/pom.xml b/pom.xml index f61b6cd0..902f0424 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.gitlab java-gitlab-api - 4.1.1-SNAPSHOT + 4.1.2-SNAPSHOT Gitlab Java API Wrapper A Java wrapper for the Gitlab Git Hosting Server API @@ -88,7 +88,7 @@ com.fasterxml.jackson.core jackson-databind - 2.5.3 + 2.9.10.5 commons-io @@ -151,6 +151,13 @@ ${log4j.version} test + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + 2.5.1 + + @@ -215,6 +222,26 @@ + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + --pinentry-mode + loopback + + + + + diff --git a/src/main/java/org/gitlab/api/GitlabAPI.java b/src/main/java/org/gitlab/api/GitlabAPI.java index c544351d..c0c88fa7 100644 --- a/src/main/java/org/gitlab/api/GitlabAPI.java +++ b/src/main/java/org/gitlab/api/GitlabAPI.java @@ -5,6 +5,9 @@ import org.gitlab.api.http.GitlabHTTPRequestor; import org.gitlab.api.http.Query; import org.gitlab.api.models.*; +import org.gitlab.api.query.PaginationQuery; +import org.gitlab.api.query.PipelinesQuery; +import org.gitlab.api.query.ProjectsQuery; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,8 +39,10 @@ public class GitlabAPI { public static final ObjectMapper MAPPER = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - private static final String API_NAMESPACE = "/api/v4"; + + private static final String DEFAULT_API_NAMESPACE = "/api/v4"; private static final String PARAM_SUDO = "sudo"; + private static final String PARAM_WITH_PROJECTS = "with_projects"; private static final String PARAM_MAX_ITEMS_PER_PAGE = new Pagination().withPerPage(Pagination.MAX_ITEMS_PER_PAGE).toString(); private final String hostUrl; @@ -45,6 +50,7 @@ public class GitlabAPI { private final String apiToken; private final TokenType tokenType; private AuthMethod authMethod; + private final String apiNamespace; private boolean ignoreCertificateErrors = false; private Proxy proxy; private int defaultTimeout = 0; @@ -52,16 +58,21 @@ public class GitlabAPI { private int connectionTimeout = defaultTimeout; private String userAgent = GitlabAPI.class.getCanonicalName() + "/" + System.getProperty("java.version"); - private GitlabAPI(String hostUrl, String apiToken, TokenType tokenType, AuthMethod method) { + private GitlabAPI(String hostUrl, String apiToken, TokenType tokenType, AuthMethod method, String apiNamespace) { this.hostUrl = hostUrl.endsWith("/") ? hostUrl.replaceAll("/$", "") : hostUrl; this.apiToken = apiToken; this.tokenType = tokenType; this.authMethod = method; + this.apiNamespace = apiNamespace; + } + + private GitlabAPI(String hostUrl, String apiToken, TokenType tokenType, AuthMethod method) { + this(hostUrl, apiToken, tokenType, method, DEFAULT_API_NAMESPACE); } public static GitlabSession connect(String hostUrl, String username, String password) throws IOException { String tailUrl = GitlabSession.URL; - GitlabAPI api = connect(hostUrl, null, null, null); + GitlabAPI api = connect(hostUrl, null, null, (AuthMethod) null); return api.dispatch().with("login", username).with("password", password) .to(tailUrl, GitlabSession.class); } @@ -78,6 +89,14 @@ public static GitlabAPI connect(String hostUrl, String apiToken, TokenType token return new GitlabAPI(hostUrl, apiToken, tokenType, method); } + public static GitlabAPI connect(String hostUrl, String apiToken, TokenType tokenType, String apiNamespace) { + return new GitlabAPI(hostUrl, apiToken, tokenType, AuthMethod.HEADER, apiNamespace); + } + + public static GitlabAPI connect(String hostUrl, String apiToken, TokenType tokenType, AuthMethod method, String apiNamespace) { + return new GitlabAPI(hostUrl, apiToken, tokenType, method, apiNamespace); + } + public GitlabAPI ignoreCertificateErrors(boolean ignoreCertificateErrors) { this.ignoreCertificateErrors = ignoreCertificateErrors; return this; @@ -159,7 +178,7 @@ public URL getAPIUrl(String tailAPIUrl) throws IOException { if (!tailAPIUrl.startsWith("/")) { tailAPIUrl = "/" + tailAPIUrl; } - return new URL(hostUrl + API_NAMESPACE + tailAPIUrl); + return new URL(hostUrl + apiNamespace + tailAPIUrl); } public URL getUrl(String tailAPIUrl) throws IOException { @@ -377,7 +396,7 @@ public GitlabSSHKey createSSHKey(Integer targetUserId, String title, String key) return dispatch().to(tailUrl, GitlabSSHKey.class); } - + /** * Create a new ssh key for the authenticated user. * @@ -449,8 +468,24 @@ public GitlabGroup getGroup(Integer groupId) throws IOException { return getGroup(groupId.toString()); } + public GitlabGroup getGroupWithoutProjects(Integer groupId) throws IOException { + return getGroupWithoutProjects(groupId.toString()); + } + /** - * Get a group by path + * Get a group by path. Don't include the projects. + * + * @param path Path of the group + * @return {@link GitlabGroup} object + * + * @throws IOException on gitlab api call error + */ + public GitlabGroup getGroupWithoutProjects(String path) throws IOException { + return getGroup(path, false); + } + + /** + * Get a group by path, including its projects. * * @param path Path of the group * @return {@link GitlabGroup} object @@ -458,8 +493,24 @@ public GitlabGroup getGroup(Integer groupId) throws IOException { * @throws IOException on gitlab api call error */ public GitlabGroup getGroup(String path) throws IOException { + return getGroup(path, true); + } + + /** + * Get a group by path + * + * @param path Path of the group + * @param withProjects If true, include the projects + * @return {@link GitlabGroup} object + * + * @throws IOException on gitlab api call error + */ + public GitlabGroup getGroup(String path, boolean withProjects) throws IOException { String tailUrl = GitlabGroup.URL + "/" + URLEncoder.encode(path, "UTF-8"); - return retrieve().to(tailUrl, GitlabGroup.class); + Query query = new Query() + .append(PARAM_WITH_PROJECTS, "" + withProjects); + + return retrieve().to(tailUrl + query.toString(), GitlabGroup.class); } public List getGroups() throws IOException { @@ -632,7 +683,7 @@ public GitlabGroup createGroup(String name, String path, String ldapCn, GitlabAc return dispatch().to(tailUrl, GitlabGroup.class); } - + /** * Creates a Group * @@ -828,6 +879,16 @@ public List getProjectsWithPagination(int page, int perPage) thro return getProjectsWithPagination(pagination); } + /** + * Get a list of projects accessible by the authenticated user. + * + * @return A list of gitlab projects + */ + public List getProjects(ProjectsQuery projectsQuery) { + String tailUrl = GitlabProject.URL + projectsQuery; + return retrieve().getAll(tailUrl, GitlabProject[].class); + } + /** * Get a list of projects by pagination accessible by the authenticated user. * @@ -961,6 +1022,70 @@ public GitlabUpload uploadFile(GitlabProject project, File file) throws IOExcept return dispatch().withAttachment("file", file).to(tailUrl, GitlabUpload.class); } + /** + * Get a project's pipeline + * + * @param project the project + * @param pipeline the pipeline + * @return The project pipeline + */ + public GitlabPipeline getProjectPipeline(GitlabProject project, GitlabPipeline pipeline) throws IOException { + return getProjectPipeline(project.getId(), pipeline.getId()); + } + + /** + * Get a project's pipeline + * + * @param projectId the project id + * @param pipelineId the pipeline id + * @return The project pipeline + */ + public GitlabPipeline getProjectPipeline(Integer projectId, Integer pipelineId) throws IOException { + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabPipeline.URL + "/" + sanitizeId(pipelineId, "pipelineId"); + return retrieve().to(tailUrl, GitlabPipeline.class); + } + + /** + * Get a list of a project's pipelines in Gitlab + * + * @param project the project + * @return A list of project pipelines + */ + public List getProjectPipelines(GitlabProject project) { + return getProjectPipelines(project.getId()); + } + + /** + * Get a list of a project's pipelines in Gitlab + * + * @param projectId the project id + * @return A list of project pipelines + */ + public List getProjectPipelines(Integer projectId) { + return getProjectPipelines(projectId, new PipelinesQuery().withPerPage(PaginationQuery.MAX_ITEMS_PER_PAGE)); + } + + /** + * Get a list of a project's pipelines in Gitlab + * + * @param project the project + * @return A list of project pipelines + */ + public List getProjectPipelines(GitlabProject project, PipelinesQuery pipelinesQuery) { + return getProjectPipelines(project.getId(), pipelinesQuery); + } + + /** + * Get a list of a project's pipelines in Gitlab + * + * @param projectId the project id + * @return A list of project pipelines + */ + public List getProjectPipelines(Integer projectId, PipelinesQuery pipelinesQuery) { + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabPipeline.URL + pipelinesQuery; + return retrieve().getAll(tailUrl, GitlabPipeline[].class); + } + /** * Gets a list of a project's jobs in Gitlab * @@ -983,6 +1108,33 @@ public List getProjectJobs(Integer projectId) { } + /** + * Run pipeline for selected project and branch + * @param project project + * @param ref branch + * @param variables pipeline variables + * @return Created pipeline + * @throws IOException + */ + public GitlabPipeline runPipeline(GitlabProject project, String ref, List variables) throws IOException { + return runPipeline(project.getId(), ref, variables); + } + + + /** + * Run pipeline for selected project and branch + * @param projectId project's id + * @param ref branch + * @param variables pipeline variables + * @return Created pipeline + * @throws IOException + */ + public GitlabPipeline runPipeline(Integer projectId, String ref, List variables) throws IOException { + Query query = new Query().appendIf("ref", ref); + String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabPipeline.CREATE_URL + query.toString(); + return dispatch().with("variables", variables).to(tailUrl, GitlabPipeline.class); + } + /** * Gets a list of project's jobs of the given pipeline in Gitlab * @@ -1152,7 +1304,8 @@ public GitlabProject createProject(GitlabProject project) throws IOException { .appendIf("request_access_enabled", project.isRequestAccessEnabled()) .appendIf("repository_storage", project.getRepositoryStorage()) .appendIf("approvals_before_merge", project.getApprovalsBeforeMerge()) - .appendIf("printing_merge_request_link_enabled", project.isPrintingMergeRequestLinkEnabled()); + .appendIf("printing_merge_request_link_enabled", project.isPrintingMergeRequestLinkEnabled()) + .appendIf("initialize_with_readme",project.isInitializeWithReadme()); GitlabNamespace namespace = project.getNamespace(); if (namespace != null) { @@ -1301,16 +1454,30 @@ public GitlabProject createUserProject(Integer userId, String name, String descr /** * @param namespace The namespace of the fork * @param projectId ProjectId of the project forked + * @param path The path that will be assigned to the resultant project after forking. (Optional) + * @param name The name that will be assigned to the resultant project after forking. (Optional) * @return The new Gitlab Project * @throws IOException on gitlab api call error */ - public GitlabProject createFork(String namespace, Integer projectId) throws IOException { + public GitlabProject createFork(String namespace, Integer projectId, String path, String name) throws IOException { Query query = new Query() - .appendIf("namespace", namespace); + .appendIf("namespace", namespace) + .appendIf("path", path) + .appendIf("name", name); String tailUrl = GitlabProject.URL + "/" + projectId + "/fork" + query.toString(); return dispatch().to(tailUrl, GitlabProject.class); } + /** + * @param namespace The namespace of the fork + * @param projectId ProjectId of the project forked + * @return The new Gitlab Project + * @throws IOException on gitlab api call error + */ + public GitlabProject createFork(String namespace, Integer projectId) throws IOException { + return createFork(namespace, projectId, null, null); + } + /** * @param namespace The namespace of the fork * @param gitlabProject The project forked @@ -1958,13 +2125,9 @@ public List getCommits(GitlabMergeRequest mergeRequest, Pagination projectId = mergeRequest.getProjectId(); } - Query query = new Query() - .append("ref_name", mergeRequest.getSourceBranch()); - - query.mergeWith(pagination.asQuery()); - String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + - "/repository" + GitlabCommit.URL + query.toString(); + GitlabMergeRequest.URL + "/" + mergeRequest.getIid() + + GitlabCommit.URL + pagination.toString(); GitlabCommit[] commits = retrieve().to(tailUrl, GitlabCommit[].class); return Arrays.asList(commits); @@ -1980,7 +2143,7 @@ public List getLastCommits(Serializable projectId, String branchOr public List getCommits(Serializable projectId, Pagination pagination, String branchOrTag) throws IOException { - return getCommits(projectId, null, branchOrTag, null); + return getCommits(projectId, pagination, branchOrTag, null); } public List getCommits(Serializable projectId, Pagination pagination, @@ -2360,14 +2523,12 @@ public void unprotectBranch(GitlabProject project, String branchName) throws IOE public List getProjectHooks(Serializable projectId) throws IOException { String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabProjectHook.URL; - GitlabProjectHook[] hooks = retrieve().to(tailUrl, GitlabProjectHook[].class); - return Arrays.asList(hooks); + return retrieve().getAll(tailUrl, GitlabProjectHook[].class); } public List getProjectHooks(GitlabProject project) throws IOException { String tailUrl = GitlabProject.URL + "/" + project.getId() + GitlabProjectHook.URL; - GitlabProjectHook[] hooks = retrieve().to(tailUrl, GitlabProjectHook[].class); - return Arrays.asList(hooks); + return retrieve().getAll(tailUrl, GitlabProjectHook[].class); } public GitlabProjectHook getProjectHook(GitlabProject project, String hookId) throws IOException { @@ -3275,7 +3436,7 @@ private String sanitizeId(Serializable id, String parameterName) { private String sanitizePath(String branch) { try { - return URLEncoder.encode(branch, "UTF-8"); + return URLEncoder.encode(branch, "UTF-8").replaceAll("\\+", "%20"); } catch (UnsupportedEncodingException e) { throw new RuntimeException((e)); } diff --git a/src/main/java/org/gitlab/api/Pagination.java b/src/main/java/org/gitlab/api/Pagination.java index b7084529..20be0d27 100644 --- a/src/main/java/org/gitlab/api/Pagination.java +++ b/src/main/java/org/gitlab/api/Pagination.java @@ -1,48 +1,44 @@ package org.gitlab.api; import org.gitlab.api.http.Query; +import org.gitlab.api.query.PaginationQuery; -import java.io.UnsupportedEncodingException; +/** + * @deprecated Use {@link PaginationQuery#PARAM_PAGE} instead. + */ +@Deprecated +public class Pagination extends PaginationQuery { -public class Pagination { - public static final String PARAM_PAGE = "page"; - public static final String PARAM_PER_PAGE = "per_page"; - public static final int MAX_ITEMS_PER_PAGE = 100; - private final Query paginationQuery = new Query(); + /** + * @deprecated Use {@link PaginationQuery#PARAM_PAGE} instead. + */ + @Deprecated + public static final String PARAM_PAGE = PaginationQuery.PARAM_PAGE; - public void setPage(int page) { - try { - paginationQuery.append(PARAM_PAGE, String.valueOf(page)); - } catch (UnsupportedEncodingException ignored) { - } - } + /** + @deprecated Use {@link PaginationQuery#PARAM_PER_PAGE} instead. + */ + @Deprecated + public static final String PARAM_PER_PAGE = PaginationQuery.PARAM_PER_PAGE; + + /** + @deprecated Use {@link PaginationQuery#MAX_ITEMS_PER_PAGE} instead. + */ + @Deprecated + public static final int MAX_ITEMS_PER_PAGE = PaginationQuery.MAX_ITEMS_PER_PAGE; - public void setPerPage(int perPage) { - if (perPage > MAX_ITEMS_PER_PAGE) { - throw new IllegalArgumentException("Max value for perPage is " + MAX_ITEMS_PER_PAGE); - } - try { - paginationQuery.append(PARAM_PER_PAGE, String.valueOf(perPage)); - } catch (UnsupportedEncodingException ignored) { - } - } - public Pagination withPage(int page) { setPage(page); return this; } - + public Pagination withPerPage(int perPage) { setPerPage(perPage); return this; } public Query asQuery() { - return paginationQuery; + return this; } - @Override - public String toString() { - return paginationQuery.toString(); - } } diff --git a/src/main/java/org/gitlab/api/http/GitlabHTTPRequestor.java b/src/main/java/org/gitlab/api/http/GitlabHTTPRequestor.java index 83754792..ebe80573 100644 --- a/src/main/java/org/gitlab/api/http/GitlabHTTPRequestor.java +++ b/src/main/java/org/gitlab/api/http/GitlabHTTPRequestor.java @@ -10,6 +10,7 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Reader; +import java.io.UncheckedIOException; import java.lang.reflect.Field; import java.net.*; import java.util.*; @@ -188,7 +189,7 @@ public Iterator asIterator(final String tailApiUrl, final Class type) try { url = root.getAPIUrl(tailApiUrl); } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } } @@ -240,7 +241,7 @@ private void fetch() { handleAPIError(e, connection); } } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } } diff --git a/src/main/java/org/gitlab/api/jackson/InstantDeserializer.java b/src/main/java/org/gitlab/api/jackson/InstantDeserializer.java new file mode 100644 index 00000000..5663826a --- /dev/null +++ b/src/main/java/org/gitlab/api/jackson/InstantDeserializer.java @@ -0,0 +1,80 @@ +package org.gitlab.api.jackson; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; + +import java.io.IOException; +import java.time.Instant; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.format.FormatStyle; +import java.util.Locale; +import java.util.Objects; +import java.util.stream.Stream; + +/** + * A spezialized {@link Instant} deserializer that can parse different formats. + */ +public class InstantDeserializer extends StdDeserializer { + + private static final DateTimeFormatter LOCAL_DATE_TIME_FORMATTER_WITH_SPACE_SEPARATOR = new DateTimeFormatterBuilder() + .parseCaseInsensitive() + .append(DateTimeFormatter.ISO_LOCAL_DATE) + .appendLiteral(' ') + .append(DateTimeFormatter.ISO_LOCAL_TIME) + .toFormatter(Locale.getDefault(Locale.Category.FORMAT)); + + public InstantDeserializer() { + super(Instant.class); + } + + @Override + public Instant deserialize(JsonParser parser, DeserializationContext context) throws IOException { + if (JsonToken.VALUE_NULL.equals(parser.getCurrentToken())) { + return null; + } + + final String text = parser.getText(); + + if (null == text || text.trim().isEmpty()) { + return null; + } + + return getFormatters() + .map(formatter -> { + try { + return formatter.parse(text, Instant::from); + } catch (DateTimeParseException e) { + return null; + } + }) + .filter(Objects::nonNull) + .findFirst() + .orElseThrow(() -> new JsonParseException("Unable to parse instant \"" + text + "\"", parser.getCurrentLocation())); + } + + private static Stream getFormatters() { + return Stream.of( + // English (Standard) Formats + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.LONG).withLocale(Locale.ENGLISH), + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.LONG).withLocale(Locale.ENGLISH), + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.LONG).withLocale(Locale.ENGLISH), + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.MEDIUM).withLocale(Locale.ENGLISH), + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.MEDIUM).withLocale(Locale.ENGLISH), + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.MEDIUM).withLocale(Locale.ENGLISH), + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT).withLocale(Locale.ENGLISH), + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT).withLocale(Locale.ENGLISH), + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.SHORT).withLocale(Locale.ENGLISH), + + // ISO Formats + LOCAL_DATE_TIME_FORMATTER_WITH_SPACE_SEPARATOR, + DateTimeFormatter.ISO_LOCAL_DATE_TIME, + DateTimeFormatter.ISO_DATE_TIME + ); + } + +} diff --git a/src/main/java/org/gitlab/api/models/GitlabBuildVariable.java b/src/main/java/org/gitlab/api/models/GitlabBuildVariable.java index e7e202f6..e26b9601 100644 --- a/src/main/java/org/gitlab/api/models/GitlabBuildVariable.java +++ b/src/main/java/org/gitlab/api/models/GitlabBuildVariable.java @@ -14,6 +14,13 @@ public GitlabBuildVariable() { public GitlabBuildVariable(String key, String value) { this.key = key; this.value = value; + this.variableType = VariableType.env_var; + } + + public GitlabBuildVariable(String key, String value, VariableType variableType) { + this.key = key; + this.value = value; + this.variableType = variableType; } @JsonProperty("key") @@ -22,6 +29,9 @@ public GitlabBuildVariable(String key, String value) { @JsonProperty("value") private String value; + @JsonProperty("variable_type") + private VariableType variableType; + public String getKey() { return key; } @@ -37,4 +47,18 @@ public String getValue() { public void setValue(String value) { this.value = value; } + + public VariableType getVariableType() { + return variableType; + } + + public void setVariableType(VariableType variableType) { + this.variableType = variableType; + } + + public enum VariableType { + env_var, + file + } + } diff --git a/src/main/java/org/gitlab/api/models/GitlabIssue.java b/src/main/java/org/gitlab/api/models/GitlabIssue.java index de62fb5a..046fe609 100644 --- a/src/main/java/org/gitlab/api/models/GitlabIssue.java +++ b/src/main/java/org/gitlab/api/models/GitlabIssue.java @@ -4,8 +4,12 @@ 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; +@JsonIgnoreProperties(ignoreUnknown = true) public class GitlabIssue { public enum Action { @@ -41,6 +45,7 @@ public enum Action { @JsonProperty("downvotes") private Integer downVotes; + @JsonDeserialize(using = LocalDateDeserializer.class) @JsonProperty("due_date") private LocalDate dueDate; diff --git a/src/main/java/org/gitlab/api/models/GitlabMergeRequest.java b/src/main/java/org/gitlab/api/models/GitlabMergeRequest.java index fbfc82e9..11d037e5 100644 --- a/src/main/java/org/gitlab/api/models/GitlabMergeRequest.java +++ b/src/main/java/org/gitlab/api/models/GitlabMergeRequest.java @@ -87,7 +87,7 @@ public class GitlabMergeRequest { private Boolean squash; @JsonProperty("changes_count") - private Integer changesCount; + private String changesCount; @JsonProperty("merged_by") private GitlabUser mergedBy; @@ -251,7 +251,7 @@ public void setLabels(String[] labels) { this.labels = labels; } - public int getUpvotes() { + public Integer getUpvotes() { return upvotes; } @@ -259,7 +259,7 @@ public void setUpvotes(int upvotes) { this.upvotes = upvotes; } - public int getDownvotes() { + public Integer getDownvotes() { return downvotes; } @@ -352,7 +352,7 @@ public Boolean isShouldRemoveSourceBranch() { return shouldRemoveSourceBranch; } - public boolean isForceRemoveSourceBranch() { + public Boolean isForceRemoveSourceBranch() { return forceRemoveSourceBranch; } @@ -360,7 +360,7 @@ public Boolean isSquash() { return squash; } - public Integer getChangesCount() { + public String getChangesCount() { return changesCount; } diff --git a/src/main/java/org/gitlab/api/models/GitlabPipeline.java b/src/main/java/org/gitlab/api/models/GitlabPipeline.java index 31927db5..c2f55b95 100644 --- a/src/main/java/org/gitlab/api/models/GitlabPipeline.java +++ b/src/main/java/org/gitlab/api/models/GitlabPipeline.java @@ -1,23 +1,73 @@ package org.gitlab.api.models; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.gitlab.api.jackson.InstantDeserializer; + +import java.time.Instant; public class GitlabPipeline { public static final String URL = "/pipelines"; + public static final String CREATE_URL = "/pipeline"; + @JsonProperty("id") private Integer id; - @JsonProperty("ref") - private String ref; - @JsonProperty("sha") private String sha; + @JsonProperty("ref") + private String ref; + @JsonProperty("status") private String status; + @JsonProperty("web_url") + private String webUrl; + + @JsonProperty("before_sha") + private String beforeSha; + + @JsonProperty("tag") + private boolean tag; + + @JsonProperty("yaml_errors") + private String yamlErrors; + + @JsonProperty("user") + private GitlabUser user; + + @JsonProperty("created_at") + @JsonDeserialize(using = InstantDeserializer.class) + private Instant createdAt; + + @JsonProperty("updated_at") + @JsonDeserialize(using = InstantDeserializer.class) + private Instant updatedAt; + + @JsonProperty("started_at") + @JsonDeserialize(using = InstantDeserializer.class) + private Instant startedAt; + + @JsonProperty("finished_at") + @JsonDeserialize(using = InstantDeserializer.class) + private Instant finishedAt; + + @JsonProperty("committed_at") + @JsonDeserialize(using = InstantDeserializer.class) + private Instant committedAt; + + @JsonProperty("duration") + private int duration; + + @JsonProperty("coverage") + private String coverage; + + @JsonProperty("detailed_status") + private DetailedStatus detailedStatus; + public Integer getId() { return id; } @@ -26,14 +76,6 @@ public void setId(Integer id) { this.id = id; } - public String getRef() { - return ref; - } - - public void setRef(String ref) { - this.ref = ref; - } - public String getSha() { return sha; } @@ -42,6 +84,14 @@ public void setSha(String sha) { this.sha = sha; } + public String getRef() { + return ref; + } + + public void setRef(String ref) { + this.ref = ref; + } + public String getStatus() { return status; } @@ -49,4 +99,205 @@ public String getStatus() { public void setStatus(String status) { this.status = status; } + + public String getWebUrl() { + return webUrl; + } + + public void setWebUrl(String webUrl) { + this.webUrl = webUrl; + } + + public String getBeforeSha() { + return beforeSha; + } + + public void setBeforeSha(String beforeSha) { + this.beforeSha = beforeSha; + } + + public boolean isTag() { + return tag; + } + + public void setTag(boolean tag) { + this.tag = tag; + } + + public String getYamlErrors() { + return yamlErrors; + } + + public void setYamlErrors(String yamlErrors) { + this.yamlErrors = yamlErrors; + } + + public GitlabUser getUser() { + return user; + } + + public void setUser(GitlabUser user) { + this.user = user; + } + + public Instant getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Instant createdAt) { + this.createdAt = createdAt; + } + + public Instant getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Instant updatedAt) { + this.updatedAt = updatedAt; + } + + public Instant getStartedAt() { + return startedAt; + } + + public void setStartedAt(Instant startedAt) { + this.startedAt = startedAt; + } + + public Instant getFinishedAt() { + return finishedAt; + } + + public void setFinishedAt(Instant finishedAt) { + this.finishedAt = finishedAt; + } + + public Instant getCommittedAt() { + return committedAt; + } + + public void setCommittedAt(Instant committedAt) { + this.committedAt = committedAt; + } + + public int getDuration() { + return duration; + } + + public void setDuration(int duration) { + this.duration = duration; + } + + public String getCoverage() { + return coverage; + } + + public void setCoverage(String coverage) { + this.coverage = coverage; + } + + public DetailedStatus getDetailedStatus() { + return detailedStatus; + } + + public void setDetailedStatus(DetailedStatus detailedStatus) { + this.detailedStatus = detailedStatus; + } + + public static class DetailedStatus { + + private String icon; + + private String text; + + private String label; + + private String group; + + private String tooltip; + + @JsonProperty("has_details") + private String hasDetails; + + @JsonProperty("details_path") + private String detailsPath; + + private String illustration; + + private String favicon; + + public String getIcon() { + return icon; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getGroup() { + return group; + } + + public void setGroup(String group) { + this.group = group; + } + + public String getTooltip() { + return tooltip; + } + + public void setTooltip(String tooltip) { + this.tooltip = tooltip; + } + + public String getHasDetails() { + return hasDetails; + } + + public void setHasDetails(String hasDetails) { + this.hasDetails = hasDetails; + } + + public String getDetailsPath() { + return detailsPath; + } + + public void setDetailsPath(String detailsPath) { + this.detailsPath = detailsPath; + } + + public String getIllustration() { + return illustration; + } + + public void setIllustration(String illustration) { + this.illustration = illustration; + } + + public String getFavicon() { + return favicon; + } + + public void setFavicon(String favicon) { + this.favicon = favicon; + } + + } + } diff --git a/src/main/java/org/gitlab/api/models/GitlabProject.java b/src/main/java/org/gitlab/api/models/GitlabProject.java index f1c6e803..a245d23b 100644 --- a/src/main/java/org/gitlab/api/models/GitlabProject.java +++ b/src/main/java/org/gitlab/api/models/GitlabProject.java @@ -131,6 +131,9 @@ public class GitlabProject { @JsonProperty("import_status") private String importStatus; + @JsonProperty("initialize_with_readme") + private Boolean initializeWithReadme; + public Integer getId() { return id; } @@ -475,6 +478,14 @@ public void setPrintingMergeRequestLinkEnabled(Boolean printingMergeRequestLinkE this.printingMergeRequestLinkEnabled = printingMergeRequestLinkEnabled; } + public Boolean isInitializeWithReadme() { + return initializeWithReadme; + } + + public void setInitializeWithReadme(Boolean initializeWithReadme) { + this.initializeWithReadme = initializeWithReadme; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/org/gitlab/api/models/GitlabTag.java b/src/main/java/org/gitlab/api/models/GitlabTag.java index 4ed51596..c0ec8cbb 100644 --- a/src/main/java/org/gitlab/api/models/GitlabTag.java +++ b/src/main/java/org/gitlab/api/models/GitlabTag.java @@ -7,7 +7,7 @@ public class GitlabTag { public final static String URL = "/repository/tags"; @JsonProperty("commit") - private GitlabBranchCommit commit; + private GitlabCommit commit; @JsonProperty("release") private GitlabRelease release; @@ -18,11 +18,11 @@ public class GitlabTag { @JsonProperty("message") private String message; - public GitlabBranchCommit getCommit() { + public GitlabCommit getCommit() { return commit; } - public void setCommit(GitlabBranchCommit commit) { + public void setCommit(GitlabCommit commit) { this.commit = commit; } diff --git a/src/main/java/org/gitlab/api/models/GitlabUser.java b/src/main/java/org/gitlab/api/models/GitlabUser.java index 840c6f86..9f6cff5f 100644 --- a/src/main/java/org/gitlab/api/models/GitlabUser.java +++ b/src/main/java/org/gitlab/api/models/GitlabUser.java @@ -1,10 +1,12 @@ package org.gitlab.api.models; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + import java.util.Date; import java.util.List; -import com.fasterxml.jackson.annotation.JsonProperty; - +@JsonIgnoreProperties(ignoreUnknown = true) public class GitlabUser { public static String URL = "/users"; diff --git a/src/main/java/org/gitlab/api/query/PaginationQuery.java b/src/main/java/org/gitlab/api/query/PaginationQuery.java new file mode 100644 index 00000000..7996ec3f --- /dev/null +++ b/src/main/java/org/gitlab/api/query/PaginationQuery.java @@ -0,0 +1,40 @@ +package org.gitlab.api.query; + +import org.gitlab.api.http.Query; + +import java.io.UnsupportedEncodingException; + +public class PaginationQuery extends Query { + + public static final String PARAM_PAGE = "page"; + public static final String PARAM_PER_PAGE = "per_page"; + public static final int MAX_ITEMS_PER_PAGE = 100; + + public void setPage(int page) { + try { + append(PARAM_PAGE, String.valueOf(page)); + } catch (UnsupportedEncodingException ignored) { + } + } + + public void setPerPage(int perPage) { + if (perPage > MAX_ITEMS_PER_PAGE) { + throw new IllegalArgumentException("Max value for perPage is " + MAX_ITEMS_PER_PAGE); + } + try { + append(PARAM_PER_PAGE, String.valueOf(perPage)); + } catch (UnsupportedEncodingException ignored) { + } + } + + public PaginationQuery withPage(int page) { + setPage(page); + return this; + } + + public PaginationQuery withPerPage(int perPage) { + setPerPage(perPage); + return this; + } + +} diff --git a/src/main/java/org/gitlab/api/query/PipelinesQuery.java b/src/main/java/org/gitlab/api/query/PipelinesQuery.java new file mode 100644 index 00000000..5c919e2c --- /dev/null +++ b/src/main/java/org/gitlab/api/query/PipelinesQuery.java @@ -0,0 +1,100 @@ +package org.gitlab.api.query; + +import java.io.UnsupportedEncodingException; + +public class PipelinesQuery extends PaginationQuery { + + public void setScope(String scope) throws UnsupportedEncodingException { + appendIf("scope", scope); + } + + public PipelinesQuery withScope(String scope) throws UnsupportedEncodingException { + this.setScope(scope); + return this; + } + + public void setStatus(String status) throws UnsupportedEncodingException { + appendIf("status", status); + } + + public PipelinesQuery withStatus(String status) throws UnsupportedEncodingException { + this.setStatus(status); + return this; + } + + public void setRef(String ref) throws UnsupportedEncodingException { + appendIf("ref", ref); + } + + public PipelinesQuery withRef(String ref) throws UnsupportedEncodingException { + this.setRef(ref); + return this; + } + + public void setSha(String sha) throws UnsupportedEncodingException { + appendIf("sha", sha); + } + + public PipelinesQuery withSha(String sha) throws UnsupportedEncodingException { + this.setSha(sha); + return this; + } + + public void setYamlErrors(Boolean yamlErrors) throws UnsupportedEncodingException { + appendIf("yaml_errors", yamlErrors); + } + + public PipelinesQuery withYamlErrors(Boolean yamlErrors) throws UnsupportedEncodingException { + this.setYamlErrors(yamlErrors); + return this; + } + + public void setName(String name) throws UnsupportedEncodingException { + appendIf("name", name); + } + + public PipelinesQuery withName(String name) throws UnsupportedEncodingException { + this.setName(name); + return this; + } + + public void setUsername(String username) throws UnsupportedEncodingException { + appendIf("username", username); + } + + public PipelinesQuery withUsername(String username) throws UnsupportedEncodingException { + this.setUsername(username); + return this; + } + + public void setOrderBy(String orderBy) throws UnsupportedEncodingException { + appendIf("order_by", orderBy); + } + + public PipelinesQuery withOrderBy(String orderBy) throws UnsupportedEncodingException { + this.setOrderBy(orderBy); + return this; + } + + public void setSort(String sort) throws UnsupportedEncodingException { + appendIf("sort", sort); + } + + public PipelinesQuery withSort(String sort) throws UnsupportedEncodingException { + this.setSort(sort); + return this; + } + + @Override + public PipelinesQuery withPage(int page) { + super.withPage(page); + return this; + } + + @Override + public PipelinesQuery withPerPage(int perPage) { + super.withPerPage(perPage); + return this; + } + +} diff --git a/src/main/java/org/gitlab/api/query/ProjectsQuery.java b/src/main/java/org/gitlab/api/query/ProjectsQuery.java new file mode 100644 index 00000000..02fd4142 --- /dev/null +++ b/src/main/java/org/gitlab/api/query/ProjectsQuery.java @@ -0,0 +1,192 @@ +package org.gitlab.api.query; + +import org.gitlab.api.models.GitlabAccessLevel; + +import java.io.UnsupportedEncodingException; + +public class ProjectsQuery extends PaginationQuery { + + public static final String PARAM_ARCHIVED = "archived"; + public static final String PARAM_VISIBILITY = "visibility"; + public static final String PARAM_ORDER_BY = "order_by"; + public static final String PARAM_SORT = "sort"; + public static final String PARAM_SEARCH = "search"; + public static final String PARAM_SIMPLE = "simple"; + public static final String PARAM_OWNED = "owned"; + public static final String PARAM_MEMBERSHIP = "membership"; + public static final String PARAM_STARRED = "starred"; + public static final String PARAM_STATISTICS = "statistics"; + public static final String PARAM_WITH_CUSTOM_ATTRIBUTES = "with_custom_attributes"; + public static final String PARAM_WITH_ISSUES_ENABLED = "with_issues_enabled"; + public static final String PARAM_WITH_MERGE_REQUESTS_ENABLED = "with_merge_requests_enabled"; + public static final String PARAM_WITH_PROGRAMMING_LANGUAGE = "with_programming_language"; + public static final String PARAM_WIKI_CHECKSUM_FAILED = "wiki_checksum_failed"; + public static final String PARAM_REPOSITORY_CHECKSUM_FAILED = "repository_checksum_failed"; + public static final String PARAM_MIN_ACCESS_LEVEL = "min_access_level"; + + public void setArchived(Boolean archived) throws UnsupportedEncodingException { + appendIf(PARAM_ARCHIVED, archived); + } + + public ProjectsQuery withArchived(Boolean archived) throws UnsupportedEncodingException { + setArchived(archived); + return this; + } + + public void setVisibility(String visibility) throws UnsupportedEncodingException { + appendIf(PARAM_VISIBILITY, visibility); + } + + public ProjectsQuery withVisibility(String visibility) throws UnsupportedEncodingException { + setVisibility(visibility); + return this; + } + + public void setOrderBy(String orderBy) throws UnsupportedEncodingException { + appendIf(PARAM_ORDER_BY, orderBy); + } + + public ProjectsQuery withOrderBy(String orderBy) throws UnsupportedEncodingException { + setOrderBy(orderBy); + return this; + } + + public void setSort(String sort) throws UnsupportedEncodingException { + appendIf(PARAM_SORT, sort); + } + + public ProjectsQuery withSort(String sort) throws UnsupportedEncodingException { + setSort(sort); + return this; + } + + public void setSearch(String search) throws UnsupportedEncodingException { + appendIf(PARAM_SEARCH, search); + } + + public ProjectsQuery withSearch(String search) throws UnsupportedEncodingException { + setSearch(search); + return this; + } + + public void setSimple(Boolean simple) throws UnsupportedEncodingException { + appendIf(PARAM_SIMPLE, simple); + } + + public ProjectsQuery withSimple(Boolean simple) throws UnsupportedEncodingException { + setSimple(simple); + return this; + } + + public void setOwned(Boolean owned) throws UnsupportedEncodingException { + appendIf(PARAM_OWNED, owned); + } + + public ProjectsQuery withOwned(Boolean owned) throws UnsupportedEncodingException { + setOwned(owned); + return this; + } + + public void setMembership(Boolean membership) throws UnsupportedEncodingException { + appendIf(PARAM_MEMBERSHIP, membership); + } + + public ProjectsQuery withMembership(Boolean membership) throws UnsupportedEncodingException { + setMembership(membership); + return this; + } + + public void setStarred(Boolean starred) throws UnsupportedEncodingException { + appendIf(PARAM_STARRED, starred); + } + + public ProjectsQuery withStarred(Boolean starred) throws UnsupportedEncodingException { + setStarred(starred); + return this; + } + + public void setStatistics(Boolean statistics) throws UnsupportedEncodingException { + appendIf(PARAM_STATISTICS, statistics); + } + + public ProjectsQuery withStatistics(Boolean statistics) throws UnsupportedEncodingException { + setStatistics(statistics); + return this; + } + + public void setWithCustomAttributes(Boolean withCustomAttributes) throws UnsupportedEncodingException { + appendIf(PARAM_WITH_CUSTOM_ATTRIBUTES, withCustomAttributes); + } + + public ProjectsQuery withWithCustomAttributes(Boolean withCustomAttributes) throws UnsupportedEncodingException { + setWithCustomAttributes(withCustomAttributes); + return this; + } + + public void setWithIssuesEnabled(Boolean withIssuesEnabled) throws UnsupportedEncodingException { + appendIf(PARAM_WITH_ISSUES_ENABLED, withIssuesEnabled); + } + + public ProjectsQuery withWithIssuesEnabled(Boolean withIssuesEnabled) throws UnsupportedEncodingException { + setWithIssuesEnabled(withIssuesEnabled); + return this; + } + + public void setWithMergeRequestsEnabled(Boolean withMergeRequestsEnabled) throws UnsupportedEncodingException { + appendIf(PARAM_WITH_MERGE_REQUESTS_ENABLED, withMergeRequestsEnabled); + } + + public ProjectsQuery withWithMergeRequestsEnabled(Boolean withMergeRequestsEnabled) throws UnsupportedEncodingException { + setWithMergeRequestsEnabled(withMergeRequestsEnabled); + return this; + } + + public void setWithProgrammingLanguage(String withProgrammingLanguage) throws UnsupportedEncodingException { + appendIf(PARAM_WITH_PROGRAMMING_LANGUAGE, withProgrammingLanguage); + } + + public ProjectsQuery withWithProgrammingLanguage(String withProgrammingLanguage) throws UnsupportedEncodingException { + setWithProgrammingLanguage(withProgrammingLanguage); + return this; + } + + public void setWikiChecksumFailed(Boolean wikiChecksumFailed) throws UnsupportedEncodingException { + appendIf(PARAM_WIKI_CHECKSUM_FAILED, wikiChecksumFailed); + } + + public ProjectsQuery withWikiChecksumFailed(Boolean wikiChecksumFailed) throws UnsupportedEncodingException { + setWikiChecksumFailed(wikiChecksumFailed); + return this; + } + + public void setRepositoryChecksumFailed(Boolean repositoryChecksumFailed) throws UnsupportedEncodingException { + appendIf(PARAM_REPOSITORY_CHECKSUM_FAILED, repositoryChecksumFailed); + } + + public ProjectsQuery withRepositoryChecksumFailed(Boolean repositoryChecksumFailed) throws UnsupportedEncodingException { + setRepositoryChecksumFailed(repositoryChecksumFailed); + return this; + } + + public void setMinAccessLevel(GitlabAccessLevel minAccessLevel) throws UnsupportedEncodingException { + appendIf(PARAM_MIN_ACCESS_LEVEL, minAccessLevel); + } + + public ProjectsQuery withMinAccessLevel(GitlabAccessLevel minAccessLevel) throws UnsupportedEncodingException { + setMinAccessLevel(minAccessLevel); + return this; + } + + @Override + public ProjectsQuery withPage(int page) { + super.withPage(page); + return this; + } + + @Override + public ProjectsQuery withPerPage(int perPage) { + super.withPerPage(perPage); + return this; + } + +} diff --git a/src/test/java/org/gitlab/api/GitlabAPIUT.java b/src/test/java/org/gitlab/api/GitlabAPIUT.java index b2cce34a..dd5cec6e 100644 --- a/src/test/java/org/gitlab/api/GitlabAPIUT.java +++ b/src/test/java/org/gitlab/api/GitlabAPIUT.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test; import java.io.IOException; +import java.net.NoRouteToHostException; import java.net.ServerSocket; import java.net.SocketTimeoutException; @@ -18,13 +19,13 @@ @SuppressWarnings("WeakerAccess") public class GitlabAPIUT { - @Test + //@Test @DisplayName(value = "Check non-routable connection with connection timeout error") public void unitTest_20180503175711() { GitlabAPI api = GitlabAPI.connect("http://172.16.0.0:80", "test"); api.setConnectionTimeout(100); - Throwable exception = assertThrows(SocketTimeoutException.class, api::getVersion); - assertThat(exception.getMessage(), is("connect timed out")); + Throwable exception = assertThrows(NoRouteToHostException.class, api::getVersion); + assertThat(exception.getMessage(), is("No route to host")); } @Test diff --git a/src/test/java/org/gitlab/api/InstantDeserializerTest.java b/src/test/java/org/gitlab/api/InstantDeserializerTest.java new file mode 100644 index 00000000..727554db --- /dev/null +++ b/src/test/java/org/gitlab/api/InstantDeserializerTest.java @@ -0,0 +1,34 @@ +package org.gitlab.api; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.gitlab.api.jackson.InstantDeserializer; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.time.*; +import java.util.concurrent.TimeUnit; + +import static org.junit.jupiter.api.Assertions.*; + +class InstantDeserializerTest { + + @Test + void deserialize() throws IOException { + final ObjectMapper objectMapper = new ObjectMapper(); + + final InstantDeserializer deserializer = new InstantDeserializer(); + final JsonParser parser = objectMapper.treeAsTokens(objectMapper.readTree("\"2016-08-11T11:28:34.085Z\"")); + parser.nextToken(); + final Instant instant = deserializer.deserialize(parser, objectMapper.getDeserializationContext()); + + assertEquals(Instant.from( + ZonedDateTime.of( + LocalDate.of(2016, 8, 11), + LocalTime.of(11, 28, 34, (int) TimeUnit.MILLISECONDS.toNanos(85)), + ZoneOffset.UTC + ) + ), instant); + } + +} \ No newline at end of file diff --git a/src/test/java/org/gitlab/api/TestUtils.java b/src/test/java/org/gitlab/api/TestUtils.java new file mode 100644 index 00000000..71bbe027 --- /dev/null +++ b/src/test/java/org/gitlab/api/TestUtils.java @@ -0,0 +1,18 @@ +package org.gitlab.api; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.stream.Collectors; + +public class TestUtils { + public static String readDataFromResource(String path) throws IOException { + InputStream inputStream = TestUtils.class.getClassLoader().getResourceAsStream(path); + assert inputStream != null; + try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { + return reader.lines().collect(Collectors.joining("\n")); + } + } + +} diff --git a/src/test/java/org/gitlab/api/models/GitlabIssueDeserializationTest.java b/src/test/java/org/gitlab/api/models/GitlabIssueDeserializationTest.java new file mode 100644 index 00000000..52802671 --- /dev/null +++ b/src/test/java/org/gitlab/api/models/GitlabIssueDeserializationTest.java @@ -0,0 +1,17 @@ +package org.gitlab.api.models; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.gitlab.api.TestUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +class GitlabIssueDeserializationTest { + @Test + void deserializationTest() { + ObjectMapper objectMapper = new ObjectMapper(); + Assertions.assertDoesNotThrow(() -> objectMapper.readValue( + TestUtils.readDataFromResource("IssueExample.json"), GitlabIssue.class)); + } +} diff --git a/src/test/resources/IssueExample.json b/src/test/resources/IssueExample.json new file mode 100644 index 00000000..66936686 --- /dev/null +++ b/src/test/resources/IssueExample.json @@ -0,0 +1,44 @@ +{ + "id":231, + "iid":2456, + "project_id":871, + "title":"Data Feed Dghrythfh00", + "description":"# Bountyrdhfy.", + "state":"opened", + "created_at":"2019-06-06T21:54:50.241Z", + "updated_at":"2019-06-08T17:22:59.613Z", + "closed_at":null, + "closed_by":null, + "labels":[ + "bounty::available", + "status::untouched" + ], + "milestone":null, + "assignees":[ + + ], + "author":{ + "id":1325, + "name":"jlsfldgs", + "username":"jlsfldgsd", + "state":"active", + "avatar_url":"https://assets.gitlab-static.net/uploads/-/system/user/avatar/139453452225/avatar.png", + "web_url":"https://gitlab.com/jlsfldgsd" + }, + "assignee":null, + "user_notes_count":4, + "merge_requests_count":0, + "upvotes":0, + "downvotes":0, + "due_date":"2019-06-29", + "confidential":false, + "discussion_locked":null, + "web_url":"https://gitlab.com/3456457", + "time_stats":{ + "time_estimate":0, + "total_time_spent":0, + "human_time_estimate":null, + "human_total_time_spent":null + }, + "weight":null +} \ No newline at end of file