Skip to content

Commit

Permalink
Minor format changes from previous merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmessner committed May 15, 2015
1 parent 6b73b77 commit 67b1e3b
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 130 deletions.
37 changes: 13 additions & 24 deletions src/main/java/com/messners/gitlab/api/GitLabApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,19 @@ public ProjectApi getProjectApi () {
public RepositoryApi getRepositoryApi () {
return (repositoryApi);
}




/**
* Gets the RepositoryFileApi instance owned by this GitLabApi instance. The RepositoryFileApi is used
* to perform all repository files related API calls.
*
* @return the RepositoryFileApi instance owned by this GitLabApi instance
*/
public RepositoryFileApi getRepositoryFileApi() {
return repositoryFileApi;
}


/**
* Gets the SessionApi instance owned by this GitLabApi instance. The SessionApi is used
* to perform a login to the GitLab API.
Expand All @@ -139,26 +150,4 @@ public SessionApi getSessionApi () {
public UserApi getUserApi () {
return (userApi);
}


/**
* Gets the RepositoryFileApi instance owned by this GitLabApi instance. The RepositoryFileApi is used
* to perform all repository files related API calls.
*
* @return the RepositoryFileApi instance owned by this GitLabApi instance
*/
public RepositoryFileApi getRepositoryFileApi() {
return repositoryFileApi;
}

/**
* Gets the RepositoryFileApi instance owned by this GitLabApi instance. The RepositoryFileApi is used
* to perform all repository files related API calls.
*
* @return the RepositoryFileApi instance owned by this GitLabApi instance
*/
public void setRepositoryFileApi(RepositoryFileApi repositoryFileApi) {
this.repositoryFileApi = repositoryFileApi;
}

}
13 changes: 8 additions & 5 deletions src/main/java/com/messners/gitlab/api/ProjectApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public Project createProject (Project project) throws GitLabApiException {
return (createProject(project, null));
}


/**
* Creates new project owned by the current user. The following properties on the Project instance
* are utilized in the creation of the project:
Expand Down Expand Up @@ -181,6 +182,7 @@ public Project createProject (Project project, String importUrl) throws GitLabAp
return (response.readEntity(Project.class));
}


/**
* Creates a Project
*
Expand All @@ -199,28 +201,29 @@ public Project createProject (Project project, String importUrl) throws GitLabAp
* @throws GitLabApiException
*/
public Project createProject(String name, Integer namespaceId, String description, Boolean issuesEnabled, Boolean wallEnabled, Boolean mergeRequestsEnabled, Boolean wikiEnabled, Boolean snippetsEnabled, Boolean publik, Integer visibilityLevel, String importUrl) throws GitLabApiException{

if (name == null || name.trim().length() == 0) {
return (null);
}

Form formData = new Form();
addFormParam(formData, "name", name, true);
addFormParam(formData, "namespace_id", namespaceId);
addFormParam(formData, "description", description);
addFormParam(formData, "issues_enabled", issuesEnabled);
addFormParam(formData, "issues_enabled", issuesEnabled);
addFormParam(formData, "wall_enabled", wallEnabled);
addFormParam(formData, "merge_requests_enabled", mergeRequestsEnabled);
addFormParam(formData, "wiki_enabled", wikiEnabled);
addFormParam(formData, "snippets_enabled", snippetsEnabled);
addFormParam(formData, "public", publik);
addFormParam(formData, "visibility_level", visibilityLevel);
addFormParam(formData, "import_url", importUrl);

Response response = post(Response.Status.CREATED, formData, "projects");
return (response.readEntity(Project.class));
}



/**
* Removes project with all resources(issues, merge requests etc).
*
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/com/messners/gitlab/api/RepositoryApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,26 +135,26 @@ public List<TreeItem> getTree (Integer projectId) throws GitLabApiException {
Response response = put(Response.Status.OK, null, "projects", projectId, "repository", "tree");
return (response.readEntity(new GenericType<List<TreeItem>>() {}));
}


/**
* Get the raw file contents for a file by commit sha and path.
*
*
* GET /projects/:id/repository/blobs/:sha
*
*
* @param projectId
* @param commitOrBranchName
* @return a string with the file content for the specified file
* @throws GitLabApiException
*/
public String getRawFileContent (Integer projectId, String commitOrBranchName, String filepath) throws GitLabApiException {

public String getRawFileContent (Integer projectId, String commitOrBranchName, String filepath) throws GitLabApiException {
Form formData = new Form();
addFormParam(formData, "filepath", filepath, true);
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "repository", "blobs", commitOrBranchName);
return (response.readEntity(String.class));
}



/**
* Get the raw file contents for a blob by blob SHA.
*
Expand All @@ -169,5 +169,4 @@ public String getRawBlobCotent(Integer projectId, String sha) throws GitLabApiEx
Response response = get(Response.Status.OK, null, "projects", projectId, "repository", "raw_blobs", sha);
return (response.readEntity(String.class));
}

}
39 changes: 19 additions & 20 deletions src/main/java/com/messners/gitlab/api/RepositoryFileApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@

/**
* This class provides an entry point to all the GitLab API repository files calls.
*
*
* @author lonfee88 <[email protected]>
*/
public class RepositoryFileApi extends AbstractApi {

public RepositoryFileApi (GitLabApi gitLabApi) {
super(gitLabApi);
}

/**
* Get file from repository
* Allows you to receive information about file in repository like name, size, content.
* Note that file content is Base64 encoded.
*
* Note that file content is Base64 encoded.
*
* GET /projects/:id/repository/files
*
*
* @param file_path (required) - Full path to new file. Ex. lib/class.rb
* @param projectId
* @param ref (required) - The name of branch, tag or commit
Expand All @@ -37,18 +37,18 @@ public RepositoryFile getFile(String filePath, Integer projectId, String ref) th
Response response = get(Response.Status.OK, form.asMap(),"projects", projectId, "repository", "files");
return (response.readEntity(RepositoryFile.class));
}

/**
* Create new file in repository
*
*
* POST /projects/:id/repository/files
*
*
* file_path (required) - Full path to new file. Ex. lib/class.rb
* branch_name (required) - The name of branch
* encoding (optional) - 'text' or 'base64'. Text is default.
* content (required) - File content
* commit_message (required) - Commit message
*
*
* @param file
* @param projectId
* @param branchName
Expand All @@ -61,18 +61,18 @@ public RepositoryFile createFile (RepositoryFile file, Integer projectId, String
Response response = post(Response.Status.CREATED, formData, "projects", projectId, "repository", "files");
return (response.readEntity(RepositoryFile.class));
}

/**
* Update existing file in repository
*
*
* PUT /projects/:id/repository/files
*
*
* file_path (required) - Full path to new file. Ex. lib/class.rb
* branch_name (required) - The name of branch
* encoding (optional) - 'text' or 'base64'. Text is default.
* content (required) - File content
* commit_message (required) - Commit message
*
*
* @param file
* @param projectId
* @param branchName
Expand All @@ -85,35 +85,35 @@ public RepositoryFile updateFile (RepositoryFile file, Integer projectId, String
Response response = put(Response.Status.OK, form.asMap(), "projects", projectId, "repository", "files");
return (response.readEntity(RepositoryFile.class));
}

/**
* Delete existing file in repository
*
*
* DELETE /projects/:id/repository/files
*
* file_path (required) - Full path to file. Ex. lib/class.rb
* branch_name (required) - The name of branch
* commit_message (required) - Commit message
*
*
* @param filePath
* @param projectId
* @param branchName
* @param commitMessage
* @throws GitLabApiException
*/
public void deleteFile (String filePath, Integer projectId, String branchName, String commitMessage) throws GitLabApiException {

if (filePath == null) {
throw new RuntimeException("filePath cannot be null");
}

Form form = new Form();
addFormParam(form, "file_path", filePath, true);
addFormParam(form, "branch_name", branchName, true);
addFormParam(form, "commit_message", commitMessage, true);
delete(Response.Status.OK, form.asMap(), "projects", projectId, "repository", "files");
}

private Form file2form(RepositoryFile file, String branchName, String commitMessage){
Form form = new Form();
addFormParam(form, "file_path", file.getFilePath(), true);
Expand All @@ -123,5 +123,4 @@ private Form file2form(RepositoryFile file, String branchName, String commitMess
addFormParam(form, "commit_message", commitMessage, true);
return form;
}

}
15 changes: 7 additions & 8 deletions src/main/java/com/messners/gitlab/api/UserApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ public User getUser (int userId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "users", userId);
return (response.readEntity(User.class));
}

// Search users by Email or username
// GET /users?search=:email_or_username



/**
* Search users by Email or username
*
*
* GET /users?search=:email_or_username
*
* @param emailOrUsername
Expand All @@ -81,12 +79,13 @@ public List<User> findUsers(String emailOrUsername) throws GitLabApiException {
Response response = get(Response.Status.OK, formData.asMap(), "users");
return (response.readEntity(new GenericType<List<User>>() {}));
}



/**
* Creates a new user. Note only administrators can create new users.
*
*
* POST /users
*
*
* email (required) - Email
* password (required) - Password
* username (required) - Username
Expand Down
Loading

0 comments on commit 67b1e3b

Please sign in to comment.