Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
67b1e3b0
Commit
67b1e3b0
authored
May 15, 2015
by
Greg Messner
Browse files
Minor format changes from previous merge.
parent
6b73b770
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/messners/gitlab/api/GitLabApi.java
View file @
67b1e3b0
...
@@ -117,8 +117,19 @@ public class GitLabApi {
...
@@ -117,8 +117,19 @@ public class GitLabApi {
public
RepositoryApi
getRepositoryApi
()
{
public
RepositoryApi
getRepositoryApi
()
{
return
(
repositoryApi
);
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
* Gets the SessionApi instance owned by this GitLabApi instance. The SessionApi is used
* to perform a login to the GitLab API.
* to perform a login to the GitLab API.
...
@@ -139,26 +150,4 @@ public class GitLabApi {
...
@@ -139,26 +150,4 @@ public class GitLabApi {
public
UserApi
getUserApi
()
{
public
UserApi
getUserApi
()
{
return
(
userApi
);
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
;
}
}
}
src/main/java/com/messners/gitlab/api/ProjectApi.java
View file @
67b1e3b0
...
@@ -131,6 +131,7 @@ public class ProjectApi extends AbstractApi {
...
@@ -131,6 +131,7 @@ public class ProjectApi extends AbstractApi {
return
(
createProject
(
project
,
null
));
return
(
createProject
(
project
,
null
));
}
}
/**
/**
* 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:
...
@@ -181,6 +182,7 @@ public class ProjectApi extends AbstractApi {
...
@@ -181,6 +182,7 @@ public class ProjectApi extends AbstractApi {
return
(
response
.
readEntity
(
Project
.
class
));
return
(
response
.
readEntity
(
Project
.
class
));
}
}
/**
/**
* Creates a Project
* Creates a Project
*
*
...
@@ -199,16 +201,16 @@ public class ProjectApi extends AbstractApi {
...
@@ -199,16 +201,16 @@ public class ProjectApi extends AbstractApi {
* @throws GitLabApiException
* @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
{
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
)
{
if
(
name
==
null
||
name
.
trim
().
length
()
==
0
)
{
return
(
null
);
return
(
null
);
}
}
Form
formData
=
new
Form
();
Form
formData
=
new
Form
();
addFormParam
(
formData
,
"name"
,
name
,
true
);
addFormParam
(
formData
,
"name"
,
name
,
true
);
addFormParam
(
formData
,
"namespace_id"
,
namespaceId
);
addFormParam
(
formData
,
"namespace_id"
,
namespaceId
);
addFormParam
(
formData
,
"description"
,
description
);
addFormParam
(
formData
,
"description"
,
description
);
addFormParam
(
formData
,
"issues_enabled"
,
issuesEnabled
);
addFormParam
(
formData
,
"issues_enabled"
,
issuesEnabled
);
addFormParam
(
formData
,
"wall_enabled"
,
wallEnabled
);
addFormParam
(
formData
,
"wall_enabled"
,
wallEnabled
);
addFormParam
(
formData
,
"merge_requests_enabled"
,
mergeRequestsEnabled
);
addFormParam
(
formData
,
"merge_requests_enabled"
,
mergeRequestsEnabled
);
addFormParam
(
formData
,
"wiki_enabled"
,
wikiEnabled
);
addFormParam
(
formData
,
"wiki_enabled"
,
wikiEnabled
);
...
@@ -216,11 +218,12 @@ public class ProjectApi extends AbstractApi {
...
@@ -216,11 +218,12 @@ public class ProjectApi extends AbstractApi {
addFormParam
(
formData
,
"public"
,
publik
);
addFormParam
(
formData
,
"public"
,
publik
);
addFormParam
(
formData
,
"visibility_level"
,
visibilityLevel
);
addFormParam
(
formData
,
"visibility_level"
,
visibilityLevel
);
addFormParam
(
formData
,
"import_url"
,
importUrl
);
addFormParam
(
formData
,
"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
));
}
}
/**
/**
* Removes project with all resources(issues, merge requests etc).
* Removes project with all resources(issues, merge requests etc).
*
*
...
...
src/main/java/com/messners/gitlab/api/RepositoryApi.java
View file @
67b1e3b0
...
@@ -135,26 +135,26 @@ public class RepositoryApi extends AbstractApi {
...
@@ -135,26 +135,26 @@ public class RepositoryApi extends AbstractApi {
Response
response
=
put
(
Response
.
Status
.
OK
,
null
,
"projects"
,
projectId
,
"repository"
,
"tree"
);
Response
response
=
put
(
Response
.
Status
.
OK
,
null
,
"projects"
,
projectId
,
"repository"
,
"tree"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
TreeItem
>>()
{}));
return
(
response
.
readEntity
(
new
GenericType
<
List
<
TreeItem
>>()
{}));
}
}
/**
/**
* Get the raw file contents for a file by commit sha and path.
* Get the raw file contents for a file by commit sha and path.
*
*
* GET /projects/:id/repository/blobs/:sha
* GET /projects/:id/repository/blobs/:sha
*
*
* @param projectId
* @param projectId
* @param commitOrBranchName
* @param commitOrBranchName
* @return a string with the file content for the specified file
* @return a string with the file content for the specified file
* @throws GitLabApiException
* @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
();
Form
formData
=
new
Form
();
addFormParam
(
formData
,
"filepath"
,
filepath
,
true
);
addFormParam
(
formData
,
"filepath"
,
filepath
,
true
);
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"projects"
,
projectId
,
"repository"
,
"blobs"
,
commitOrBranchName
);
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"projects"
,
projectId
,
"repository"
,
"blobs"
,
commitOrBranchName
);
return
(
response
.
readEntity
(
String
.
class
));
return
(
response
.
readEntity
(
String
.
class
));
}
}
/**
/**
* Get the raw file contents for a blob by blob SHA.
* Get the raw file contents for a blob by blob SHA.
*
*
...
@@ -169,5 +169,4 @@ public class RepositoryApi extends AbstractApi {
...
@@ -169,5 +169,4 @@ public class RepositoryApi extends AbstractApi {
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
projectId
,
"repository"
,
"raw_blobs"
,
sha
);
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
projectId
,
"repository"
,
"raw_blobs"
,
sha
);
return
(
response
.
readEntity
(
String
.
class
));
return
(
response
.
readEntity
(
String
.
class
));
}
}
}
}
src/main/java/com/messners/gitlab/api/RepositoryFileApi.java
View file @
67b1e3b0
...
@@ -8,7 +8,7 @@ import com.messners.gitlab.api.models.RepositoryFile;
...
@@ -8,7 +8,7 @@ import com.messners.gitlab.api.models.RepositoryFile;
/**
/**
* This class provides an entry point to all the GitLab API repository files calls.
* This class provides an entry point to all the GitLab API repository files calls.
*
*
* @author lonfee88 <lonfee88@gmail.com>
* @author lonfee88 <lonfee88@gmail.com>
*/
*/
public
class
RepositoryFileApi
extends
AbstractApi
{
public
class
RepositoryFileApi
extends
AbstractApi
{
...
@@ -16,14 +16,14 @@ public class RepositoryFileApi extends AbstractApi {
...
@@ -16,14 +16,14 @@ public class RepositoryFileApi extends AbstractApi {
public
RepositoryFileApi
(
GitLabApi
gitLabApi
)
{
public
RepositoryFileApi
(
GitLabApi
gitLabApi
)
{
super
(
gitLabApi
);
super
(
gitLabApi
);
}
}
/**
/**
* Get file from repository
* Get file from repository
* Allows you to receive information about file in repository like name, size, content.
* 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
* GET /projects/:id/repository/files
*
*
* @param file_path (required) - Full path to new file. Ex. lib/class.rb
* @param file_path (required) - Full path to new file. Ex. lib/class.rb
* @param projectId
* @param projectId
* @param ref (required) - The name of branch, tag or commit
* @param ref (required) - The name of branch, tag or commit
...
@@ -37,18 +37,18 @@ public class RepositoryFileApi extends AbstractApi {
...
@@ -37,18 +37,18 @@ public class RepositoryFileApi extends AbstractApi {
Response
response
=
get
(
Response
.
Status
.
OK
,
form
.
asMap
(),
"projects"
,
projectId
,
"repository"
,
"files"
);
Response
response
=
get
(
Response
.
Status
.
OK
,
form
.
asMap
(),
"projects"
,
projectId
,
"repository"
,
"files"
);
return
(
response
.
readEntity
(
RepositoryFile
.
class
));
return
(
response
.
readEntity
(
RepositoryFile
.
class
));
}
}
/**
/**
* Create new file in repository
* Create new file in repository
*
*
* POST /projects/:id/repository/files
* POST /projects/:id/repository/files
*
*
* file_path (required) - Full path to new file. Ex. lib/class.rb
* file_path (required) - Full path to new file. Ex. lib/class.rb
* branch_name (required) - The name of branch
* branch_name (required) - The name of branch
* encoding (optional) - 'text' or 'base64'. Text is default.
* encoding (optional) - 'text' or 'base64'. Text is default.
* content (required) - File content
* content (required) - File content
* commit_message (required) - Commit message
* commit_message (required) - Commit message
*
*
* @param file
* @param file
* @param projectId
* @param projectId
* @param branchName
* @param branchName
...
@@ -61,18 +61,18 @@ public class RepositoryFileApi extends AbstractApi {
...
@@ -61,18 +61,18 @@ public class RepositoryFileApi extends AbstractApi {
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
,
"projects"
,
projectId
,
"repository"
,
"files"
);
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
,
"projects"
,
projectId
,
"repository"
,
"files"
);
return
(
response
.
readEntity
(
RepositoryFile
.
class
));
return
(
response
.
readEntity
(
RepositoryFile
.
class
));
}
}
/**
/**
* Update existing file in repository
* Update existing file in repository
*
*
* PUT /projects/:id/repository/files
* PUT /projects/:id/repository/files
*
*
* file_path (required) - Full path to new file. Ex. lib/class.rb
* file_path (required) - Full path to new file. Ex. lib/class.rb
* branch_name (required) - The name of branch
* branch_name (required) - The name of branch
* encoding (optional) - 'text' or 'base64'. Text is default.
* encoding (optional) - 'text' or 'base64'. Text is default.
* content (required) - File content
* content (required) - File content
* commit_message (required) - Commit message
* commit_message (required) - Commit message
*
*
* @param file
* @param file
* @param projectId
* @param projectId
* @param branchName
* @param branchName
...
@@ -85,16 +85,16 @@ public class RepositoryFileApi extends AbstractApi {
...
@@ -85,16 +85,16 @@ public class RepositoryFileApi extends AbstractApi {
Response
response
=
put
(
Response
.
Status
.
OK
,
form
.
asMap
(),
"projects"
,
projectId
,
"repository"
,
"files"
);
Response
response
=
put
(
Response
.
Status
.
OK
,
form
.
asMap
(),
"projects"
,
projectId
,
"repository"
,
"files"
);
return
(
response
.
readEntity
(
RepositoryFile
.
class
));
return
(
response
.
readEntity
(
RepositoryFile
.
class
));
}
}
/**
/**
* Delete existing file in repository
* Delete existing file in repository
*
*
* DELETE /projects/:id/repository/files
* DELETE /projects/:id/repository/files
*
*
* file_path (required) - Full path to file. Ex. lib/class.rb
* file_path (required) - Full path to file. Ex. lib/class.rb
* branch_name (required) - The name of branch
* branch_name (required) - The name of branch
* commit_message (required) - Commit message
* commit_message (required) - Commit message
*
*
* @param filePath
* @param filePath
* @param projectId
* @param projectId
* @param branchName
* @param branchName
...
@@ -102,18 +102,18 @@ public class RepositoryFileApi extends AbstractApi {
...
@@ -102,18 +102,18 @@ public class RepositoryFileApi extends AbstractApi {
* @throws GitLabApiException
* @throws GitLabApiException
*/
*/
public
void
deleteFile
(
String
filePath
,
Integer
projectId
,
String
branchName
,
String
commitMessage
)
throws
GitLabApiException
{
public
void
deleteFile
(
String
filePath
,
Integer
projectId
,
String
branchName
,
String
commitMessage
)
throws
GitLabApiException
{
if
(
filePath
==
null
)
{
if
(
filePath
==
null
)
{
throw
new
RuntimeException
(
"filePath cannot be null"
);
throw
new
RuntimeException
(
"filePath cannot be null"
);
}
}
Form
form
=
new
Form
();
Form
form
=
new
Form
();
addFormParam
(
form
,
"file_path"
,
filePath
,
true
);
addFormParam
(
form
,
"file_path"
,
filePath
,
true
);
addFormParam
(
form
,
"branch_name"
,
branchName
,
true
);
addFormParam
(
form
,
"branch_name"
,
branchName
,
true
);
addFormParam
(
form
,
"commit_message"
,
commitMessage
,
true
);
addFormParam
(
form
,
"commit_message"
,
commitMessage
,
true
);
delete
(
Response
.
Status
.
OK
,
form
.
asMap
(),
"projects"
,
projectId
,
"repository"
,
"files"
);
delete
(
Response
.
Status
.
OK
,
form
.
asMap
(),
"projects"
,
projectId
,
"repository"
,
"files"
);
}
}
private
Form
file2form
(
RepositoryFile
file
,
String
branchName
,
String
commitMessage
){
private
Form
file2form
(
RepositoryFile
file
,
String
branchName
,
String
commitMessage
){
Form
form
=
new
Form
();
Form
form
=
new
Form
();
addFormParam
(
form
,
"file_path"
,
file
.
getFilePath
(),
true
);
addFormParam
(
form
,
"file_path"
,
file
.
getFilePath
(),
true
);
...
@@ -123,5 +123,4 @@ public class RepositoryFileApi extends AbstractApi {
...
@@ -123,5 +123,4 @@ public class RepositoryFileApi extends AbstractApi {
addFormParam
(
form
,
"commit_message"
,
commitMessage
,
true
);
addFormParam
(
form
,
"commit_message"
,
commitMessage
,
true
);
return
form
;
return
form
;
}
}
}
}
src/main/java/com/messners/gitlab/api/UserApi.java
View file @
67b1e3b0
...
@@ -62,13 +62,11 @@ public class UserApi extends AbstractApi {
...
@@ -62,13 +62,11 @@ public class UserApi extends AbstractApi {
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"users"
,
userId
);
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"users"
,
userId
);
return
(
response
.
readEntity
(
User
.
class
));
return
(
response
.
readEntity
(
User
.
class
));
}
}
// Search users by Email or username
// GET /users?search=:email_or_username
/**
/**
* Search users by Email or username
* Search users by Email or username
*
*
* GET /users?search=:email_or_username
* GET /users?search=:email_or_username
*
*
* @param emailOrUsername
* @param emailOrUsername
...
@@ -81,12 +79,13 @@ public class UserApi extends AbstractApi {
...
@@ -81,12 +79,13 @@ public class UserApi extends AbstractApi {
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"users"
);
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"users"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
User
>>()
{}));
return
(
response
.
readEntity
(
new
GenericType
<
List
<
User
>>()
{}));
}
}
/**
/**
* Creates a new user. Note only administrators can create new users.
* Creates a new user. Note only administrators can create new users.
*
*
* POST /users
* POST /users
*
*
* email (required) - Email
* email (required) - Email
* password (required) - Password
* password (required) - Password
* username (required) - Username
* username (required) - Username
...
...
src/main/java/com/messners/gitlab/api/models/RepositoryFile.java
View file @
67b1e3b0
...
@@ -9,7 +9,7 @@ import javax.xml.bind.annotation.XmlRootElement;
...
@@ -9,7 +9,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
RepositoryFile
{
public
class
RepositoryFile
{
private
String
fileName
;
//file name only, Ex. lib/class.rb
private
String
fileName
;
//file name only, Ex. lib/class.rb
private
String
filePath
;
//full path to file. Ex. lib/class.rb
private
String
filePath
;
//full path to file. Ex. lib/class.rb
private
Integer
size
;
private
Integer
size
;
...
@@ -18,68 +18,68 @@ public class RepositoryFile {
...
@@ -18,68 +18,68 @@ public class RepositoryFile {
private
String
ref
;
private
String
ref
;
private
String
blobId
;
private
String
blobId
;
private
String
commitId
;
private
String
commitId
;
public
String
getFileName
()
{
public
String
getFileName
()
{
return
fileName
;
return
fileName
;
}
}
public
void
setFileName
(
String
fileName
)
{
public
void
setFileName
(
String
fileName
)
{
this
.
fileName
=
fileName
;
this
.
fileName
=
fileName
;
}
}
public
String
getFilePath
()
{
public
String
getFilePath
()
{
return
filePath
;
return
filePath
;
}
}
public
void
setFilePath
(
String
filePath
)
{
public
void
setFilePath
(
String
filePath
)
{
this
.
filePath
=
filePath
;
this
.
filePath
=
filePath
;
}
}
public
Integer
getSize
()
{
public
Integer
getSize
()
{
return
size
;
return
size
;
}
}
public
void
setSize
(
Integer
size
)
{
public
void
setSize
(
Integer
size
)
{
this
.
size
=
size
;
this
.
size
=
size
;
}
}
public
String
getEncoding
()
{
public
String
getEncoding
()
{
return
encoding
;
return
encoding
;
}
}
public
void
setEncoding
(
String
encoding
)
{
public
void
setEncoding
(
String
encoding
)
{
this
.
encoding
=
encoding
;
this
.
encoding
=
encoding
;
}
}
public
String
getContent
()
{
public
String
getContent
()
{
return
content
;
return
content
;
}
}
public
void
setContent
(
String
content
)
{
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
this
.
content
=
content
;
}
}
public
String
getRef
()
{
public
String
getRef
()
{
return
ref
;
return
ref
;
}
}
public
void
setRef
(
String
ref
)
{
public
void
setRef
(
String
ref
)
{
this
.
ref
=
ref
;
this
.
ref
=
ref
;
}
}
public
String
getBlobId
()
{
public
String
getBlobId
()
{
return
blobId
;
return
blobId
;
}
}
public
void
setBlobId
(
String
blobId
)
{
public
void
setBlobId
(
String
blobId
)
{
this
.
blobId
=
blobId
;
this
.
blobId
=
blobId
;
}
}
public
String
getCommitId
()
{
public
String
getCommitId
()
{
return
commitId
;
return
commitId
;
}
}
public
void
setCommitId
(
String
commitId
)
{
public
void
setCommitId
(
String
commitId
)
{
this
.
commitId
=
commitId
;
this
.
commitId
=
commitId
;
}
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment