Commit 37444213 authored by Grogdunn's avatar Grogdunn

enh: formatted code

parent 42bf4d2b
This diff is collapsed.
package org.gitlab.api;
public enum TokenType {
PRIVATE_TOKEN("private_token")
, ACCESS_TOKEN("access_token"),
;
PRIVATE_TOKEN("private_token"), ACCESS_TOKEN("access_token"),;
private final String tokenParamName;
......
......@@ -20,8 +20,8 @@ import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
/**
* Gitlab HTTP Requestor
* Responsible for handling HTTP requests to the Gitlab API
* Gitlab HTTP Requestor Responsible for handling HTTP requests to the Gitlab
* API
*
* @author @timols (Tim O)
*/
......@@ -57,8 +57,8 @@ public class GitlabHTTPRequestor {
}
/**
* Sets the HTTP Request method for the request.
* Has a fluent api for method chaining.
* Sets the HTTP Request method for the request. Has a fluent api for method
* chaining.
*
* @param method The HTTP method
* @return this
......@@ -74,8 +74,8 @@ public class GitlabHTTPRequestor {
}
/**
* Sets the HTTP Form Post parameters for the request
* Has a fluent api for method chaining
* 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
......@@ -101,7 +101,8 @@ public class GitlabHTTPRequestor {
* Will throw an error
*
* @param <T> The return type of the method
* @param tailAPIUrl The url to open a connection to (after the host and namespace)
* @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
......@@ -231,8 +232,7 @@ public class GitlabHTTPRequestor {
if (matcher.find()) {
Integer page = Integer.parseInt(matcher.group(2)) + 1;
this.url = new URL(matcher.replaceAll(matcher.group(1) + "page=" + page));
} else {
if (GitlabCommit[].class == type) {
} 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
......@@ -243,7 +243,6 @@ public class GitlabHTTPRequestor {
this.url = new URL(url + "&page=2");
}
}
}
};
}
......
......@@ -8,12 +8,12 @@ import java.util.ArrayList;
import java.util.List;
/**
* Models the Query
* aspect of a URL
* Models the Query aspect of a URL
*/
public class Query {
private class Tuple<T1, T2> {
T1 _1;
T2 _2;
......@@ -24,8 +24,8 @@ public class Query {
}
/**
* The type of params is:
* Tuple<name, Tuple<value, URLEncoder.encode(value, "UTF-8")>>
* The type of params is: 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>>>();
......@@ -35,7 +35,8 @@ public class Query {
* @param name Parameter name
* @param value Parameter value
* @return this
* @throws java.io.UnsupportedEncodingException If the provided value cannot be URL Encoded
* @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<String, Tuple<String, String>>(name, new Tuple<String, String>(value, URLEncoder.encode(value, "UTF-8"))));
......@@ -43,13 +44,14 @@ public class Query {
}
/**
* Conditionally append a parameter to the query
* if the value of the parameter is not null
* Conditionally append a parameter to the query if the value of the
* parameter is not null
*
* @param name Parameter name
* @param value Parameter value
* @return this
* @throws java.io.UnsupportedEncodingException If the provided value cannot be URL Encoded
* @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) {
......@@ -59,13 +61,14 @@ public class Query {
}
/**
* Conditionally append a parameter to the query
* if the value of the parameter is not null
* Conditionally append a parameter to the query if the value of the
* parameter is not null
*
* @param name Parameter name
* @param value Parameter value
* @return this
* @throws java.io.UnsupportedEncodingException If the provided value cannot be URL Encoded
* @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) {
......@@ -75,13 +78,14 @@ public class Query {
}
/**
* Conditionally append a parameter to the query
* if the value of the parameter is not null
* Conditionally append a parameter to the query if the value of the
* parameter is not null
*
* @param name Parameter name
* @param value Parameter value
* @return this
* @throws java.io.UnsupportedEncodingException If the provided value cannot be URL Encoded
* @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) {
......@@ -91,13 +95,14 @@ public class Query {
}
/**
* Conditionally append a parameter to the query
* if the value of the parameter is not null
* Conditionally append a parameter to the query if the value of the
* parameter is not null
*
* @param name Parameter name
* @param value Parameter value
* @return this
* @throws java.io.UnsupportedEncodingException If the provided value cannot be URL Encoded
* @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) {
......@@ -107,8 +112,7 @@ public class Query {
}
/**
* Returns a Query suitable for appending
* to a URI
* Returns a Query suitable for appending to a URI
*/
@Override
public String toString() {
......
......@@ -3,6 +3,7 @@ package org.gitlab.api.models;
import com.fasterxml.jackson.annotation.JsonProperty;
public class GitlabBranch {
public final static String URL = "/repository/branches/";
@JsonProperty("name")
......
......@@ -5,6 +5,7 @@ import java.util.Date;
import com.fasterxml.jackson.annotation.JsonProperty;
public class GitlabBranchCommit {
public static String URL = "/users";
private String id;
......
......@@ -5,6 +5,7 @@ import java.util.Date;
import com.fasterxml.jackson.annotation.JsonProperty;
public class GitlabMergeRequest {
public static final String URL = "/merge_requests";
private Integer id;
......
......@@ -5,6 +5,7 @@ import java.util.Date;
import com.fasterxml.jackson.annotation.JsonProperty;
public class GitlabNamespace {
public static final String URL = "/groups";
private Integer id;
......
......@@ -10,7 +10,6 @@ public class GitlabProjectAccessLevel {
@JsonProperty("notification_level")
private int notificationLevel;
public GitlabAccessLevel getAccessLevel() {
return GitlabAccessLevel.fromAccessValue(accessLevel);
}
......@@ -19,7 +18,6 @@ public class GitlabProjectAccessLevel {
this.accessLevel = accessLevel.accessValue;
}
public int getNoficationLevel() {
return notificationLevel;
}
......@@ -28,5 +26,4 @@ public class GitlabProjectAccessLevel {
this.accessLevel = notificationLevel;
}
}
package org.gitlab.api.models;
public class GitlabRepositoryTree {
public static String URL = "/tree";
private String name;
......
package org.gitlab.api.models;
public class GitlabSSHKey {
public static String KEYS_URL = "/keys";
private Integer _id;
......
......@@ -5,6 +5,7 @@ import java.util.Date;
import com.fasterxml.jackson.annotation.JsonProperty;
public class GitlabUser {
public static String URL = "/users";
public static String USERS_URL = "/users";
public static String USER_URL = "/user"; // for sudo based ops
......
......@@ -24,7 +24,6 @@ public class GitlabAPIT {
String rand = UUID.randomUUID().toString().replace("-", "").substring(0, 8);
@Before
public void setup() throws IOException {
api = GitlabAPI.connect(TEST_URL, TEST_TOKEN);
......@@ -62,7 +61,6 @@ public class GitlabAPIT {
String password = randVal("$%password");
GitlabUser gitUser = api.createUser(randVal("testEmail@gitlabapitest.com"),
password,
randVal("userName"),
......@@ -91,14 +89,11 @@ public class GitlabAPIT {
10 /* project limit does not come back on GET */, gitUser.getExternUid(), gitUser.getExternProviderName(),
gitUser.getBio(), gitUser.isAdmin(), gitUser.isCanCreateGroup());
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
......@@ -109,7 +104,6 @@ public class GitlabAPIT {
assertTrue(true); // expected
}
}
private String randVal(String postfix) {
......
......@@ -32,7 +32,6 @@ public class QueryTest {
Query query = new Query()
.append("p1", "v1");
query.append("p2", "v2");
query = query.append("p3", "v3");
......
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