Commit 054754d5 authored by Greg Messner's avatar Greg Messner
Browse files

Mods related to create project fixes.

parent 0c6e6baa
...@@ -229,7 +229,7 @@ public abstract class AbstractApi { ...@@ -229,7 +229,7 @@ public abstract class AbstractApi {
* the returned secret token, if either is not correct will throw a GitLabApiException. * the returned secret token, if either is not correct will throw a GitLabApiException.
* *
* @param response response * @param response response
* @param expected expected respone status * @param expected expected response status
* @return original response if the response status is expected * @return original response if the response status is expected
* @throws GitLabApiException if HTTP status is not as expected, or the secret token doesn't match * @throws GitLabApiException if HTTP status is not as expected, or the secret token doesn't match
*/ */
......
...@@ -12,6 +12,7 @@ public class GitLabApi { ...@@ -12,6 +12,7 @@ public class GitLabApi {
private CommitsApi commitsApi; private CommitsApi commitsApi;
private GroupApi groupApi; private GroupApi groupApi;
private MergeRequestApi mergeRequestApi; private MergeRequestApi mergeRequestApi;
private NamespaceApi namespaceApi;
private ProjectApi projectApi; private ProjectApi projectApi;
private RepositoryApi repositoryApi; private RepositoryApi repositoryApi;
private RepositoryFileApi repositoryFileApi; private RepositoryFileApi repositoryFileApi;
...@@ -61,6 +62,7 @@ public class GitLabApi { ...@@ -61,6 +62,7 @@ public class GitLabApi {
commitsApi = new CommitsApi(this); commitsApi = new CommitsApi(this);
groupApi = new GroupApi(this); groupApi = new GroupApi(this);
mergeRequestApi = new MergeRequestApi(this); mergeRequestApi = new MergeRequestApi(this);
setNamespaceApi(new NamespaceApi(this));
projectApi = new ProjectApi(this); projectApi = new ProjectApi(this);
repositoryApi = new RepositoryApi(this); repositoryApi = new RepositoryApi(this);
servicesApi = new ServicesApi(this); servicesApi = new ServicesApi(this);
...@@ -99,6 +101,20 @@ public class GitLabApi { ...@@ -99,6 +101,20 @@ public class GitLabApi {
return (mergeRequestApi); return (mergeRequestApi);
} }
/**
* Gets the NamespaceApi instance owned by this GitLabApi instance. The NamespaceApi is used
* to perform all namespace related API calls.
*
* @return the NamespaceApi instance owned by this GitLabApi instance
*/
public NamespaceApi getNamespaceApi() {
return namespaceApi;
}
public void setNamespaceApi(NamespaceApi namespaceApi) {
this.namespaceApi = namespaceApi;
}
/** /**
* Gets the GroupApi instance owned by this GitLabApi instance. The GroupApi is used * Gets the GroupApi instance owned by this GitLabApi instance. The GroupApi is used
* to perform all group related API calls. * to perform all group related API calls.
......
...@@ -280,7 +280,10 @@ public class GitLabApiClient { ...@@ -280,7 +280,10 @@ public class GitLabApiClient {
* @return a ClientResponse instance with the data returned from the endpoint * @return a ClientResponse instance with the data returned from the endpoint
*/ */
protected Response post(Form formData, URL url) { protected Response post(Form formData, URL url) {
return (invocation(url, null).post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED_TYPE))); if (formData instanceof GitLabApiForm)
return (invocation(url, null).post(Entity.entity(formData.asMap(), MediaType.APPLICATION_FORM_URLENCODED_TYPE)));
else
return (invocation(url, null).post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED_TYPE)));
} }
/** /**
......
package org.gitlab4j.api; package org.gitlab4j.api;
import javax.ws.rs.core.Form; import javax.ws.rs.core.Form;
import javax.ws.rs.core.MultivaluedHashMap;
/** /**
* This class extends the standard JAX-RS Form class to make it fluent. * This class extends the standard JAX-RS Form class to make it fluent.
*/ */
public class GitLabApiForm extends Form { public class GitLabApiForm extends Form {
public GitLabApiForm() {
super();
}
public GitLabApiForm(MultivaluedHashMap<String, String> map) {
super(map);
}
/** /**
* Fluent method for adding query and form parameters to a get() or post() call. * Fluent method for adding query and form parameters to a get() or post() call.
* *
...@@ -47,4 +56,4 @@ public class GitLabApiForm extends Form { ...@@ -47,4 +56,4 @@ public class GitLabApiForm extends Form {
this.param(name, stringValue); this.param(name, stringValue);
return (this); return (this);
} }
} }
\ No newline at end of file
...@@ -100,14 +100,14 @@ public class ProjectApi extends AbstractApi { ...@@ -100,14 +100,14 @@ public class ProjectApi extends AbstractApi {
throw new RuntimeException("project cannot be null"); throw new RuntimeException("project cannot be null");
} }
String pid = null; String projectPath = null;
try { try {
pid = URLEncoder.encode(namespace + "/" + project, "UTF-8"); projectPath = URLEncoder.encode(namespace + "/" + project, "UTF-8");
} catch (UnsupportedEncodingException uee) { } catch (UnsupportedEncodingException uee) {
throw (new GitLabApiException(uee)); throw (new GitLabApiException(uee));
} }
Response response = get(Response.Status.OK, null, "projects", pid); Response response = get(Response.Status.OK, null, "projects", projectPath);
return (response.readEntity(Project.class)); return (response.readEntity(Project.class));
} }
...@@ -129,6 +129,22 @@ public class ProjectApi extends AbstractApi { ...@@ -129,6 +129,22 @@ public class ProjectApi extends AbstractApi {
return (response.readEntity(Project.class)); return (response.readEntity(Project.class));
} }
/**
* Create a new project with the current user's namespace.
*
* @param projectName the name of the project top create
* @return the created project
* @throws GitLabApiException if any exception occurs
*/
public Project createProject(String projectName) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("name", projectName, true);
Response response = post(Response.Status.CREATED, formData, "projects");
return (response.readEntity(Project.class));
}
/** /**
* Creates new project owned by the current user. * Creates new project owned by the current user.
* *
...@@ -144,15 +160,26 @@ public class ProjectApi extends AbstractApi { ...@@ -144,15 +160,26 @@ public class ProjectApi extends AbstractApi {
* Creates new project owned by the current user. The following properties on the Project instance * Creates new project owned by the current user. The following properties on the Project instance
* are utilized in the creation of the project: * are utilized in the creation of the project:
* *
* name (required) - new project name * name (name or path are required) - new project name
* path (name or path are required) - new project path
* defaultBranch (optional) - master by default
* description (optional) - short project description * description (optional) - short project description
* issuesEnabled (optional) * public (optional) - if true same as setting visibility_level = 20
* wallEnabled (optional)
* mergeRequestsEnabled (optional)
* wikiEnabled (optional)
* snippetsEnabled (optional)
* isPublic (optional) - if true same as setting visibility_level = 20
* visibilityLevel (optional) * visibilityLevel (optional)
* issuesEnabled (optional) - Enable issues for this project
* mergeRequestsEnabled (optional) - Enable merge requests for this project
* wikiEnabled (optional) - Enable wiki for this project
* snippetsEnabled (optional) - Enable snippets for this project
* jobsEnabled (optional) - Enable jobs for this project
* containerRegistryEnabled (optional) - Enable container registry for this project
* sharedRunnersEnabled (optional) - Enable shared runners for this project
* publicJobs (optional) - If true, jobs can be viewed by non-project-members
* onlyAllowMergeIfPipelineSucceeds (optional) - Set whether merge requests can only be merged with successful jobs
* onlyAllowMergeIfAllDiscussionsAreResolved (optional) - Set whether merge requests can only be merged when all the discussions are resolved
* lLfsEnabled (optional) - Enable LFS
* requestAccessEnabled (optional) - Allow users to request member access
* repositoryStorage (optional) - Which storage shard the repository is on. Available only to admins
* approvalsBeforeMerge (optional) - How many approvers should approve merge request by default
* *
* @param project the Project instance with the configuration for the new project * @param project the Project instance with the configuration for the new project
* @param importUrl the URL to import the repository from * @param importUrl the URL to import the repository from
...@@ -166,20 +193,33 @@ public class ProjectApi extends AbstractApi { ...@@ -166,20 +193,33 @@ public class ProjectApi extends AbstractApi {
} }
String name = project.getName(); String name = project.getName();
if (name == null || name.trim().length() == 0) { String path = project.getPath();
if ((name == null || name.trim().length() == 0) && (path == null || path.trim().length() == 0)) {
return (null); return (null);
} }
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = new GitLabApiForm()
.withParam("name", name, true) .withParam("name", name)
.withParam("path", path)
.withParam("default_branch", project.getDefaultBranch())
.withParam("description", project.getDescription()) .withParam("description", project.getDescription())
.withParam("issues_enabled", project.getIssuesEnabled()) .withParam("issues_enabled", project.getIssuesEnabled())
.withParam("wall_enabled", project.getWallEnabled())
.withParam("merge_requests_enabled", project.getMergeRequestsEnabled()) .withParam("merge_requests_enabled", project.getMergeRequestsEnabled())
.withParam("jobs_enabled", project.getJobsEnabled())
.withParam("wiki_enabled", project.getWikiEnabled()) .withParam("wiki_enabled", project.getWikiEnabled())
.withParam("container_registry_enabled", project.getContainerRegistryEnabled())
.withParam("snippets_enabled", project.getSnippetsEnabled()) .withParam("snippets_enabled", project.getSnippetsEnabled())
.withParam("shared_runners_enabled", project.getSharedRunnersEnabled())
.withParam("public_jobs", project.getPublicJobs())
.withParam("public", project.getPublic()) .withParam("public", project.getPublic())
.withParam("visibility_level", project.getVisibilityLevel()) .withParam("visibility_level", project.getVisibilityLevel())
.withParam("only_allow_merge_if_pipeline_succeeds", project.getOnlyAllowMergeIfPipelineSucceeds())
.withParam("only_allow_merge_if_all_discussions_are_resolved", project.getOnlyAllowMergeIfAllDiscussionsAreResolved())
.withParam("lfs_enabled", project.getLfsEnabled())
.withParam("request_access_enabled", project.getRequestAccessEnabled())
.withParam("repository_storage", project.getRepositoryStorage())
.withParam("approvals_before_merge", project.getApprovalsBeforeMerge())
.withParam("import_url", importUrl); .withParam("import_url", importUrl);
if (project.getNamespace() != null) { if (project.getNamespace() != null) {
...@@ -197,18 +237,16 @@ public class ProjectApi extends AbstractApi { ...@@ -197,18 +237,16 @@ public class ProjectApi extends AbstractApi {
* @param namespaceId The Namespace for the new project, otherwise null indicates to use the GitLab default (user) * @param namespaceId The Namespace for the new project, otherwise null indicates to use the GitLab default (user)
* @param description A description for the project, null otherwise * @param description A description for the project, null otherwise
* @param issuesEnabled Whether Issues should be enabled, otherwise null indicates to use GitLab default * @param issuesEnabled Whether Issues should be enabled, otherwise null indicates to use GitLab default
* @param wallEnabled Whether The Wall should be enabled, otherwise null indicates to use GitLab default
* @param mergeRequestsEnabled Whether Merge Requests should be enabled, otherwise null indicates to use GitLab default * @param mergeRequestsEnabled Whether Merge Requests should be enabled, otherwise null indicates to use GitLab default
* @param wikiEnabled Whether a Wiki should be enabled, otherwise null indicates to use GitLab default * @param wikiEnabled Whether a Wiki should be enabled, otherwise null indicates to use GitLab default
* @param snippetsEnabled Whether Snippets should be enabled, otherwise null indicates to use GitLab default * @param snippetsEnabled Whether Snippets should be enabled, otherwise null indicates to use GitLab default
* @param isPublic Whether the project is public or private, if true same as setting visibilityLevel = 20, otherwise null indicates to use GitLab default * @param isPublic Whether the project is public or private
* @param visibilityLevel The visibility level of the project, otherwise null indicates to use GitLab default
* @param importUrl The Import URL for the project, otherwise null * @param importUrl The Import URL for the project, otherwise null
* @return the GitLab Project * @return the GitLab Project
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public Project createProject(String name, Integer namespaceId, String description, Boolean issuesEnabled, Boolean wallEnabled, Boolean mergeRequestsEnabled, public Project createProject(String name, Integer namespaceId, String description, Boolean issuesEnabled, Boolean mergeRequestsEnabled,
Boolean wikiEnabled, Boolean snippetsEnabled, Boolean isPublic, Integer visibilityLevel, String importUrl) throws GitLabApiException { Boolean wikiEnabled, Boolean snippetsEnabled, Boolean isPublic, String importUrl) throws GitLabApiException {
if (name == null || name.trim().length() == 0) { if (name == null || name.trim().length() == 0) {
return (null); return (null);
...@@ -216,16 +254,14 @@ public class ProjectApi extends AbstractApi { ...@@ -216,16 +254,14 @@ public class ProjectApi extends AbstractApi {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = new GitLabApiForm()
.withParam("name", name, true) .withParam("name", name, true)
.withParam("namespace_id", namespaceId) .withParam("namespace_id", namespaceId, false)
.withParam("description", description) .withParam("description", description, false)
.withParam("issues_enabled", issuesEnabled) .withParam("issues_enabled", issuesEnabled, false)
.withParam("wall_enabled", wallEnabled) .withParam("merge_requests_enabled", mergeRequestsEnabled, false)
.withParam("merge_requests_enabled", mergeRequestsEnabled) .withParam("wiki_enabled", wikiEnabled, false)
.withParam("wiki_enabled", wikiEnabled) .withParam("snippets_enabled", snippetsEnabled, false)
.withParam("snippets_enabled", snippetsEnabled) .withParam("visibility", (isPublic != null && isPublic ? "public" : "private"), false)
.withParam("public", isPublic) .withParam("import_url", importUrl, false);
.withParam("visibility_level", visibilityLevel)
.withParam("import_url", importUrl);
Response response = post(Response.Status.CREATED, formData, "projects"); Response response = post(Response.Status.CREATED, formData, "projects");
return (response.readEntity(Project.class)); return (response.readEntity(Project.class));
......
...@@ -12,9 +12,9 @@ import javax.xml.bind.annotation.XmlRootElement; ...@@ -12,9 +12,9 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class Project { public class Project {
private Integer approvalsBeforeMerge;
private Boolean archived; private Boolean archived;
private String avatarUrl; private String avatarUrl;
private Boolean buildsEnabled;
private Boolean containerRegistryEnabled; private Boolean containerRegistryEnabled;
private Date createdAt; private Date createdAt;
private Integer creatorId; private Integer creatorId;
...@@ -24,23 +24,25 @@ public class Project { ...@@ -24,23 +24,25 @@ public class Project {
private Project forkedFromProject; private Project forkedFromProject;
private String httpUrlToRepo; private String httpUrlToRepo;
private Integer id; private Integer id;
private Boolean isPublic;
private Boolean issuesEnabled; private Boolean issuesEnabled;
private Boolean jobsEnabled;
private Date lastActivityAt; private Date lastActivityAt;
private Boolean lfsEnabled;
private Boolean mergeRequestsEnabled; private Boolean mergeRequestsEnabled;
private String name; private String name;
private Namespace namespace; private Namespace namespace;
private String nameWithNamespace; private String nameWithNamespace;
private Boolean onlyAllowMergeIfBuildSucceeds; private Boolean onlyAllowMergeIfPipelineSucceeds;
private Boolean onlyAllowMergeIfAllDiscussionsAreResolved; private Boolean onlyAllowMergeIfAllDiscussionsAreResolved;
private Integer openIssuesCount; private Integer openIssuesCount;
private Owner owner; private Owner owner;
private String path; private String path;
private String pathWithNamespace; private String pathWithNamespace;
private Permissions permissions; private Permissions permissions;
private Boolean isPublic; private Boolean publicJobs;
private Boolean publicBuilds;
private String repositoryStorage; private String repositoryStorage;
private Boolean request_access_enabled; private Boolean requestAccessEnabled;
private String runnersToken; private String runnersToken;
private Boolean sharedRunnersEnabled; private Boolean sharedRunnersEnabled;
private List<ProjectSharedGroup> sharedWithGroups; private List<ProjectSharedGroup> sharedWithGroups;
...@@ -49,10 +51,24 @@ public class Project { ...@@ -49,10 +51,24 @@ public class Project {
private Integer starCount; private Integer starCount;
private List<String> tagList; private List<String> tagList;
private Integer visibilityLevel; private Integer visibilityLevel;
private Visibility visibility;
private Boolean wallEnabled; private Boolean wallEnabled;
private String webUrl; private String webUrl;
private Boolean wikiEnabled; private Boolean wikiEnabled;
public Integer getApprovalsBeforeMerge() {
return approvalsBeforeMerge;
}
public void setApprovalsBeforeMerge(Integer approvalsBeforeMerge) {
this.approvalsBeforeMerge = approvalsBeforeMerge;
}
public Project withApprovalsBeforeMerge(Integer approvalsBeforeMerge) {
this.approvalsBeforeMerge = approvalsBeforeMerge;
return (this);
}
public Boolean getArchived() { public Boolean getArchived() {
return archived; return archived;
} }
...@@ -69,14 +85,6 @@ public class Project { ...@@ -69,14 +85,6 @@ public class Project {
this.avatarUrl = avatarUrl; this.avatarUrl = avatarUrl;
} }
public Boolean getBuildsEnabled() {
return buildsEnabled;
}
public void setBuildsEnabled(Boolean buildsEnabled) {
this.buildsEnabled = buildsEnabled;
}
public Boolean getContainerRegistryEnabled() { public Boolean getContainerRegistryEnabled() {
return containerRegistryEnabled; return containerRegistryEnabled;
} }
...@@ -85,6 +93,11 @@ public class Project { ...@@ -85,6 +93,11 @@ public class Project {
this.containerRegistryEnabled = containerRegistryEnabled; this.containerRegistryEnabled = containerRegistryEnabled;
} }
public Project withContainerRegistryEnabled(boolean containerRegistryEnabled) {
this.containerRegistryEnabled = containerRegistryEnabled;
return (this);
}
public Date getCreatedAt() { public Date getCreatedAt() {
return createdAt; return createdAt;
} }
...@@ -109,6 +122,11 @@ public class Project { ...@@ -109,6 +122,11 @@ public class Project {
this.defaultBranch = defaultBranch; this.defaultBranch = defaultBranch;
} }
public Project withDefaultBranch(String defaultBranch) {
this.defaultBranch = defaultBranch;
return (this);
}
public String getDescription() { public String getDescription() {
return description; return description;
} }
...@@ -117,6 +135,11 @@ public class Project { ...@@ -117,6 +135,11 @@ public class Project {
this.description = description; this.description = description;
} }
public Project withDescription(String description) {
this.description = description;
return (this);
}
public Integer getForksCount() { public Integer getForksCount() {
return forksCount; return forksCount;
} }
...@@ -157,6 +180,24 @@ public class Project { ...@@ -157,6 +180,24 @@ public class Project {
this.issuesEnabled = issuesEnabled; this.issuesEnabled = issuesEnabled;
} }
public Project withIssuesEnabled(boolean issuesEnabled) {
this.issuesEnabled = issuesEnabled;
return (this);
}
public Boolean getJobsEnabled() {
return jobsEnabled;
}
public void setJobsEnabled(Boolean jobsEnabled) {
this.jobsEnabled = jobsEnabled;
}
public Project withJobsEnabled(boolean jobsEnabled) {
this.jobsEnabled = jobsEnabled;
return (this);
}
public Date getLastActivityAt() { public Date getLastActivityAt() {
return lastActivityAt; return lastActivityAt;
} }
...@@ -165,6 +206,19 @@ public class Project { ...@@ -165,6 +206,19 @@ public class Project {
this.lastActivityAt = lastActivityAt; this.lastActivityAt = lastActivityAt;
} }
public Boolean getLfsEnabled() {
return lfsEnabled;
}
public void setLfsEnabled(Boolean lfsEnabled) {
this.lfsEnabled = lfsEnabled;
}
public Project withLfsEnabled(Boolean lfsEnabled) {
this.lfsEnabled = lfsEnabled;
return (this);
}
public Boolean getMergeRequestsEnabled() { public Boolean getMergeRequestsEnabled() {
return mergeRequestsEnabled; return mergeRequestsEnabled;
} }
...@@ -173,6 +227,11 @@ public class Project { ...@@ -173,6 +227,11 @@ public class Project {
this.mergeRequestsEnabled = mergeRequestsEnabled; this.mergeRequestsEnabled = mergeRequestsEnabled;
} }
public Project withMergeRequestsEnabled(boolean mergeRequestsEnabled) {
this.mergeRequestsEnabled = mergeRequestsEnabled;
return (this);
}
public String getName() { public String getName() {
return name; return name;
} }
...@@ -181,6 +240,11 @@ public class Project { ...@@ -181,6 +240,11 @@ public class Project {
this.name = name; this.name = name;
} }
public Project withName(String name) {
this.name = name;
return (this);
}
public Namespace getNamespace() { public Namespace getNamespace() {
return namespace; return namespace;
} }
...@@ -189,6 +253,17 @@ public class Project { ...@@ -189,6 +253,17 @@ public class Project {
this.namespace = namespace; this.namespace = namespace;
} }
public Project withNamespace(Namespace namespace) {
this.namespace = namespace;
return (this);
}
public Project withNamespaceId(int namespaceId) {
this.namespace = new Namespace();
this.namespace.setId(namespaceId);
return (this);
}
public String getNameWithNamespace() { public String getNameWithNamespace() {
return nameWithNamespace; return nameWithNamespace;
} }
...@@ -197,12 +272,17 @@ public class Project { ...@@ -197,12 +272,17 @@ public class Project {
this.nameWithNamespace = nameWithNamespace; this.nameWithNamespace = nameWithNamespace;
} }
public Boolean getOnlyAllowMergeIfBuildSucceeds() { public Boolean getOnlyAllowMergeIfPipelineSucceeds() {
return onlyAllowMergeIfBuildSucceeds; return onlyAllowMergeIfPipelineSucceeds;
} }
public void setOnlyAllowMergeIfBuildSucceeds(Boolean onlyAllowMergeIfBuildSucceeds) { public void setOnlyAllowMergeIfPipelineSucceeds(Boolean onlyAllowMergeIfPipelineSucceeds) {
this.onlyAllowMergeIfBuildSucceeds = onlyAllowMergeIfBuildSucceeds; this.onlyAllowMergeIfPipelineSucceeds = onlyAllowMergeIfPipelineSucceeds;
}
public Project withOnlyAllowMergeIfPipelineSucceeds(Boolean onlyAllowMergeIfPipelineSucceeds) {
this.onlyAllowMergeIfPipelineSucceeds = onlyAllowMergeIfPipelineSucceeds;
return (this);
} }
public Boolean getOnlyAllowMergeIfAllDiscussionsAreResolved() { public Boolean getOnlyAllowMergeIfAllDiscussionsAreResolved() {
...@@ -213,6 +293,11 @@ public class Project { ...@@ -213,6 +293,11 @@ public class Project {
this.onlyAllowMergeIfAllDiscussionsAreResolved = onlyAllowMergeIfAllDiscussionsAreResolved; this.onlyAllowMergeIfAllDiscussionsAreResolved = onlyAllowMergeIfAllDiscussionsAreResolved;
} }
public Project withOnlyAllowMergeIfAllDiscussionsAreResolved(Boolean onlyAllowMergeIfAllDiscussionsAreResolved) {
this.onlyAllowMergeIfAllDiscussionsAreResolved = onlyAllowMergeIfAllDiscussionsAreResolved;
return (this);
}
public Integer getOpenIssuesCount() { public Integer getOpenIssuesCount() {
return openIssuesCount; return openIssuesCount;
} }
...@@ -237,6 +322,11 @@ public class Project { ...@@ -237,6 +322,11 @@ public class Project {
this.path = path; this.path = path;
} }
public Project withPath(String path) {
this.path = path;
return (this);
}
public String getPathWithNamespace() { public String getPathWithNamespace() {
return pathWithNamespace; return pathWithNamespace;
} }
...@@ -261,12 +351,22 @@ public class Project { ...@@ -261,12 +351,22 @@ public class Project {
this.isPublic = isPublic; this.isPublic = isPublic;
} }
public Boolean getPublicBuilds() { public Project withPublic(Boolean isPublic) {
return publicBuilds; this.isPublic = isPublic;
return (this);
}
public Boolean getPublicJobs() {
return publicJobs;
} }
public void setPublicBuilds(Boolean publicBuilds) { public void setPublicJobs(Boolean publicJobs) {
this.publicBuilds = publicBuilds; this.publicJobs = publicJobs;
}
public Project withPublicJobs(boolean publicJobs) {
this.publicJobs = publicJobs;
return (this);
} }
public String getRepositoryStorage() { public String getRepositoryStorage() {
...@@ -277,12 +377,22 @@ public class Project { ...@@ -277,12 +377,22 @@ public class Project {
this.repositoryStorage = repositoryStorage; this.repositoryStorage = repositoryStorage;
} }
public Boolean getRequest_access_enabled() { public Project withRepositoryStorage(String repositoryStorage) {
return request_access_enabled; this.repositoryStorage = repositoryStorage;
return (this);
}
public Boolean getRequestAccessEnabled() {
return requestAccessEnabled;
} }
public void setRequest_access_enabled(Boolean request_access_enabled) { public void setRequestAccessEnabled(Boolean request_access_enabled) {
this.request_access_enabled = request_access_enabled; this.requestAccessEnabled = request_access_enabled;
}
public Project withRequestAccessEnabled(boolean requestAccessEnabled) {
this.requestAccessEnabled = requestAccessEnabled;
return (this);
} }
public String getRunnersToken() { public String getRunnersToken() {
...@@ -309,6 +419,11 @@ public class Project { ...@@ -309,6 +419,11 @@ public class Project {
this.sharedWithGroups = sharedWithGroups; this.sharedWithGroups = sharedWithGroups;
} }
public Project withSharedRunnersEnabled(boolean sharedRunnersEnabled) {
this.sharedRunnersEnabled = sharedRunnersEnabled;
return (this);
}
public Boolean getSnippetsEnabled() { public Boolean getSnippetsEnabled() {
return snippetsEnabled; return snippetsEnabled;
} }
...@@ -317,6 +432,11 @@ public class Project { ...@@ -317,6 +432,11 @@ public class Project {
this.snippetsEnabled = snippetsEnabled; this.snippetsEnabled = snippetsEnabled;
} }
public Project withSnippetsEnabled(boolean snippetsEnabled) {
this.snippetsEnabled = snippetsEnabled;
return (this);
}
public String getSshUrlToRepo() { public String getSshUrlToRepo() {
return sshUrlToRepo; return sshUrlToRepo;
} }
...@@ -341,6 +461,19 @@ public class Project { ...@@ -341,6 +461,19 @@ public class Project {
this.tagList = tagList; this.tagList = tagList;
} }
public Visibility getVisibility() {
return visibility;
}
public void setVisibility(Visibility visibility) {
this.visibility = visibility;
}
public Project withVisibility(Visibility visibility) {
this.visibility = visibility;
return (this);
}
public Integer getVisibilityLevel() { public Integer getVisibilityLevel() {
return visibilityLevel; return visibilityLevel;
} }
...@@ -349,6 +482,11 @@ public class Project { ...@@ -349,6 +482,11 @@ public class Project {
this.visibilityLevel = visibilityLevel; this.visibilityLevel = visibilityLevel;
} }
public Project withVisibilityLevel(Integer visibilityLevel) {
this.visibilityLevel = visibilityLevel;
return (this);
}
public Boolean getWallEnabled() { public Boolean getWallEnabled() {
return wallEnabled; return wallEnabled;
} }
...@@ -373,6 +511,11 @@ public class Project { ...@@ -373,6 +511,11 @@ public class Project {
this.wikiEnabled = wikiEnabled; this.wikiEnabled = wikiEnabled;
} }
public Project withWikiEnabled(boolean wikiEnabled) {
this.wikiEnabled = wikiEnabled;
return (this);
}
public static final boolean isValid(Project project) { public static final boolean isValid(Project project) {
return (project != null && project.getId() != null); return (project != null && project.getId() != null);
} }
......
...@@ -13,8 +13,6 @@ import javax.ws.rs.core.MediaType; ...@@ -13,8 +13,6 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.ContextResolver; import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider; import javax.ws.rs.ext.Provider;
import org.gitlab4j.api.models.AccessLevel;
import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonGenerator;
...@@ -65,7 +63,6 @@ public class JacksonJson extends JacksonJaxbJsonProvider implements ContextResol ...@@ -65,7 +63,6 @@ public class JacksonJson extends JacksonJaxbJsonProvider implements ContextResol
SimpleModule module = new SimpleModule("GitLabApiJsonModule"); SimpleModule module = new SimpleModule("GitLabApiJsonModule");
module.addSerializer(Date.class, new JsonDateSerializer()); module.addSerializer(Date.class, new JsonDateSerializer());
module.addDeserializer(Date.class, new JsonDateDeserializer()); module.addDeserializer(Date.class, new JsonDateDeserializer());
module.addSerializer(AccessLevel.class, new JsonAccessLevelSerializer());
objectMapper.registerModule(module); objectMapper.registerModule(module);
} }
...@@ -171,15 +168,4 @@ public class JacksonJson extends JacksonJaxbJsonProvider implements ContextResol ...@@ -171,15 +168,4 @@ public class JacksonJson extends JacksonJaxbJsonProvider implements ContextResol
} }
} }
} }
/**
* JsonSerializer for serializing AccessLevel values.
*/
public static class JsonAccessLevelSerializer extends JsonSerializer<AccessLevel> {
@Override
public void serialize(AccessLevel accessLevel, JsonGenerator gen, SerializerProvider provider) throws IOException, JsonProcessingException {
gen.writeNumber(accessLevel.value);
}
}
} }
\ No newline at end of file
package org.gitlab4j.api; package org.gitlab4j.api;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
import java.io.File; import java.io.File;
...@@ -12,14 +12,14 @@ import java.nio.file.Path; ...@@ -12,14 +12,14 @@ import java.nio.file.Path;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.List; import java.util.List;
import org.gitlab4j.api.GitLabApi;
import org.gitlab4j.api.GitLabApiException;
import org.gitlab4j.api.models.Branch; import org.gitlab4j.api.models.Branch;
import org.gitlab4j.api.models.Project; import org.gitlab4j.api.models.Project;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test; import org.junit.Test;
import org.junit.runners.MethodSorters;
/** /**
* In order for these tests to run you must set the following systems properties: * In order for these tests to run you must set the following systems properties:
...@@ -35,7 +35,9 @@ import org.junit.Test; ...@@ -35,7 +35,9 @@ import org.junit.Test;
* mvn test -DTEST_PRIVATE_TOKEN=your_private_token -DTEST_HOST_URL=https://gitlab.com \ * mvn test -DTEST_PRIVATE_TOKEN=your_private_token -DTEST_HOST_URL=https://gitlab.com \
* -DTEST_NAMESPACE=your_namespace -DTEST_PROJECT_NAME=test-project * -DTEST_NAMESPACE=your_namespace -DTEST_PROJECT_NAME=test-project
* *
* NOTE: &amp;FixMethodOrder(MethodSorters.NAME_ASCENDING) is very important to insure that testCreate() is executed first.
*/ */
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestGitLabApi { public class TestGitLabApi {
// The following needs to be set to your test repository // The following needs to be set to your test repository
...@@ -87,6 +89,7 @@ public class TestGitLabApi { ...@@ -87,6 +89,7 @@ public class TestGitLabApi {
@AfterClass @AfterClass
public static void teardown() throws GitLabApiException { public static void teardown() throws GitLabApiException {
if (gitLabApi != null) { if (gitLabApi != null) {
try { try {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME); Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
gitLabApi.getRepositoryApi().deleteBranch(project.getId(), TEST_BRANCH_NAME); gitLabApi.getRepositoryApi().deleteBranch(project.getId(), TEST_BRANCH_NAME);
...@@ -121,6 +124,14 @@ public class TestGitLabApi { ...@@ -121,6 +124,14 @@ public class TestGitLabApi {
assertNotNull(branch); assertNotNull(branch);
} }
@Test
public void testDeleteBranch() throws GitLabApiException {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
assertNotNull(project);
gitLabApi.getRepositoryApi().deleteBranch(project.getId(), TEST_BRANCH_NAME);
}
@Test @Test
public void testRepositoryArchiveViaInputStream() throws GitLabApiException, IOException { public void testRepositoryArchiveViaInputStream() throws GitLabApiException, IOException {
...@@ -135,7 +146,7 @@ public class TestGitLabApi { ...@@ -135,7 +146,7 @@ public class TestGitLabApi {
assertTrue(target.toFile().length() > 0); assertTrue(target.toFile().length() > 0);
Files.delete(target); Files.delete(target);
} }
@Test @Test
public void testRepositoryArchiveViaFile() throws GitLabApiException, IOException { public void testRepositoryArchiveViaFile() throws GitLabApiException, IOException {
...@@ -145,7 +156,7 @@ public class TestGitLabApi { ...@@ -145,7 +156,7 @@ public class TestGitLabApi {
File file = gitLabApi.getRepositoryApi().getRepositoryArchive(project.getId(), "master", null); File file = gitLabApi.getRepositoryApi().getRepositoryArchive(project.getId(), "master", null);
assertTrue(file.length() > 0); assertTrue(file.length() > 0);
file.delete(); file.delete();
file = gitLabApi.getRepositoryApi().getRepositoryArchive(project.getId(), "master", new File(".")); file = gitLabApi.getRepositoryApi().getRepositoryArchive(project.getId(), "master", new File("."));
assertTrue(file.length() > 0); assertTrue(file.length() > 0);
file.delete(); file.delete();
......
...@@ -31,6 +31,7 @@ import org.junit.BeforeClass; ...@@ -31,6 +31,7 @@ import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
...@@ -292,7 +293,18 @@ public class TestGitLabApiBeans { ...@@ -292,7 +293,18 @@ public class TestGitLabApiBeans {
String objectJson = jacksonJson.marshal(apiObject); String objectJson = jacksonJson.marshal(apiObject);
JsonNode tree1 = jacksonJson.getObjectMapper().readTree(objectJson.getBytes()); JsonNode tree1 = jacksonJson.getObjectMapper().readTree(objectJson.getBytes());
JsonNode tree2 = jacksonJson.getObjectMapper().readTree(reader); JsonNode tree2 = jacksonJson.getObjectMapper().readTree(reader);
boolean sameJson = tree1.equals(tree2); boolean sameJson = tree1.equals(tree2);
if (!sameJson) {
System.out.println("JSON did not match:");
sortedDump(tree1);
sortedDump(tree2);
}
return (sameJson); return (sameJson);
} }
private void sortedDump(final JsonNode node) throws JsonProcessingException {
final Object obj = jacksonJson.getObjectMapper().treeToValue(node, Object.class);
System.out.println(jacksonJson.getObjectMapper().writeValueAsString(obj));
}
} }
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
"git_ssh_url": "git@192.168.64.1:gitlab-org/gitlab-test.git", "git_ssh_url": "git@192.168.64.1:gitlab-org/gitlab-test.git",
"description": "Atque in sunt eos similique dolores voluptatem.", "description": "Atque in sunt eos similique dolores voluptatem.",
"homepage": "http://192.168.64.1:3005/gitlab-org/gitlab-test", "homepage": "http://192.168.64.1:3005/gitlab-org/gitlab-test",
"git_ssh_url": "git@192.168.64.1:gitlab-org/gitlab-test.git",
"git_http_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test.git", "git_http_url": "http://192.168.64.1:3005/gitlab-org/gitlab-test.git",
"visibility_level": 20 "visibility_level": 20
} }
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
"issues_enabled": true, "issues_enabled": true,
"open_issues_count": 1, "open_issues_count": 1,
"merge_requests_enabled": true, "merge_requests_enabled": true,
"builds_enabled": true, "jobs_enabled": true,
"wiki_enabled": true, "wiki_enabled": true,
"snippets_enabled": false, "snippets_enabled": false,
"container_registry_enabled": false, "container_registry_enabled": false,
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
"forks_count": 0, "forks_count": 0,
"star_count": 0, "star_count": 0,
"runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b", "runners_token": "b8bc4a7a29eb76ea83cf79e4908c2b",
"public_builds": true, "public_jobs": true,
"shared_with_groups": [ "shared_with_groups": [
{ {
"group_id": 4, "group_id": 4,
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
} }
], ],
"repository_storage": "default", "repository_storage": "default",
"only_allow_merge_if_build_succeeds": false, "only_allow_merge_if_pipeline_succeeds": false,
"only_allow_merge_if_all_discussions_are_resolved": false, "only_allow_merge_if_all_discussions_are_resolved": false,
"request_access_enabled": false "request_access_enabled": false
} }
\ No newline at end of file
Supports Markdown
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