Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
java-gitlab-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
沈俊林
java-gitlab-api
Commits
2f87d8c5
Commit
2f87d8c5
authored
May 19, 2013
by
Tim Olshansky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic API support with tests
parent
eb693a3b
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
1148 additions
and
0 deletions
+1148
-0
pom.xml
pom.xml
+75
-0
GitlabAPI.java
src/main/java/org/gitlab/api/GitlabAPI.java
+135
-0
GitlabHTTPRequestor.java
src/main/java/org/gitlab/api/http/GitlabHTTPRequestor.java
+231
-0
GitlabCommit.java
src/main/java/org/gitlab/api/models/GitlabCommit.java
+72
-0
GitlabMergeRequest.java
src/main/java/org/gitlab/api/models/GitlabMergeRequest.java
+104
-0
GitlabNamespace.java
src/main/java/org/gitlab/api/models/GitlabNamespace.java
+68
-0
GitlabNote.java
src/main/java/org/gitlab/api/models/GitlabNote.java
+57
-0
GitlabProject.java
src/main/java/org/gitlab/api/models/GitlabProject.java
+152
-0
GitlabUser.java
src/main/java/org/gitlab/api/models/GitlabUser.java
+198
-0
GitlabAPITest.java
src/test/java/org/gitlab/api/GitlabAPITest.java
+36
-0
GitlabHTTPRequestorTest.java
...est/java/org/gitlab/api/http/GitlabHTTPRequestorTest.java
+20
-0
No files found.
pom.xml
0 → 100644
View file @
2f87d8c5
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.gitlab
</groupId>
<artifactId>
java-gitlab-api
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<name>
Gitlab Java API Wrapper
</name>
<description>
A Java wrapper for the Gitlab Git Hosting Server API
</description>
<developers>
<developer>
<id>
timols
</id>
<name>
Tim Olshansky
</name>
<email>
tim.olshansky@gmail.com
</email>
</developer>
</developers>
<licenses>
<license>
<name>
The Apache Software License, Version 2.0
</name>
<url>
http://www.apache.org/licenses/LICENSE-2.0.txt
</url>
<distribution>
repo
</distribution>
</license>
</licenses>
<scm>
<connection>
scm:git:ssh://github.com/timols/java-gitlab-api.git
</connection>
<developerConnection>
scm:git:ssh://git@github.com/timols/java-gitlab-api.git
</developerConnection>
<url>
https://github.com/timols/java-gitlab-api
</url>
</scm>
<issueManagement>
<system>
Github
</system>
<url>
https://github.com/timols/java-gitlab-api/issues
</url>
</issueManagement>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>
org.codehaus.jackson
</groupId>
<artifactId>
jackson-core-asl
</artifactId>
<version>
1.9.9
</version>
</dependency>
<dependency>
<groupId>
org.codehaus.jackson
</groupId>
<artifactId>
jackson-mapper-asl
</artifactId>
<version>
1.9.9
</version>
</dependency>
<dependency>
<groupId>
commons-io
</groupId>
<artifactId>
commons-io
</artifactId>
<version>
1.4
</version>
</dependency>
<dependency>
<groupId>
org.hamcrest
</groupId>
<artifactId>
hamcrest-all
</artifactId>
<version>
1.3
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
4.11
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
src/main/java/org/gitlab/api/GitlabAPI.java
0 → 100644
View file @
2f87d8c5
package
org
.
gitlab
.
api
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.gitlab.api.http.GitlabHTTPRequestor
;
import
org.gitlab.api.models.GitlabCommit
;
import
org.gitlab.api.models.GitlabMergeRequest
;
import
org.gitlab.api.models.GitlabNote
;
import
org.gitlab.api.models.GitlabProject
;
/**
* Gitlab API Wrapper class
*
* @author @timols
*/
public
class
GitlabAPI
{
private
final
String
_hostUrl
;
private
final
String
_apiToken
;
private
boolean
_ignoreCertificateErrors
=
false
;
private
static
final
String
API_NAMESPACE
=
"/api/v3"
;
public
static
final
ObjectMapper
MAPPER
=
new
ObjectMapper
();
private
GitlabAPI
(
String
hostUrl
,
String
apiToken
)
{
_hostUrl
=
hostUrl
.
endsWith
(
"/"
)
?
hostUrl
.
replaceAll
(
"/$"
,
""
)
:
hostUrl
;
_apiToken
=
apiToken
;
}
public
static
GitlabAPI
connect
(
String
hostUrl
,
String
apiToken
)
{
return
new
GitlabAPI
(
hostUrl
,
apiToken
);
}
public
GitlabAPI
ignoreCertificateErrors
(
boolean
ignoreCertificateErrors
)
{
_ignoreCertificateErrors
=
ignoreCertificateErrors
;
return
this
;
}
public
GitlabHTTPRequestor
retrieve
()
{
return
new
GitlabHTTPRequestor
(
this
);
}
public
GitlabHTTPRequestor
dispatch
()
{
return
new
GitlabHTTPRequestor
(
this
).
method
(
"POST"
);
}
public
boolean
isIgnoreCertificateErrors
()
{
return
_ignoreCertificateErrors
;
}
public
URL
getAPIUrl
(
String
tailAPIUrl
)
throws
IOException
{
if
(
_apiToken
!=
null
)
{
tailAPIUrl
=
tailAPIUrl
+
(
tailAPIUrl
.
indexOf
(
'?'
)
>
0
?
'&'
:
'?'
)
+
"private_token="
+
_apiToken
;
}
if
(!
tailAPIUrl
.
startsWith
(
"/"
))
{
tailAPIUrl
=
"/"
+
tailAPIUrl
;
}
return
new
URL
(
_hostUrl
+
API_NAMESPACE
+
tailAPIUrl
);
}
public
URL
getUrl
(
String
tailAPIUrl
)
throws
IOException
{
if
(!
tailAPIUrl
.
startsWith
(
"/"
))
{
tailAPIUrl
=
"/"
+
tailAPIUrl
;
}
return
new
URL
(
_hostUrl
+
tailAPIUrl
);
}
public
GitlabProject
getProject
(
Integer
projectId
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
projectId
;
return
retrieve
().
to
(
tailUrl
,
GitlabProject
.
class
);
}
public
List
<
GitlabMergeRequest
>
getOpenMergeRequests
(
GitlabProject
project
)
throws
IOException
{
List
<
GitlabMergeRequest
>
allMergeRequests
=
getMergeRequests
(
project
);
List
<
GitlabMergeRequest
>
openMergeRequests
=
new
ArrayList
<
GitlabMergeRequest
>();
for
(
GitlabMergeRequest
mergeRequest
:
allMergeRequests
)
{
if
(
mergeRequest
.
isClosed
())
{
continue
;
}
openMergeRequests
.
add
(
mergeRequest
);
}
return
openMergeRequests
;
}
public
List
<
GitlabMergeRequest
>
getMergeRequests
(
Integer
projectId
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
projectId
+
GitlabMergeRequest
.
URL
;
return
fetchMergeRequests
(
tailUrl
);
}
public
List
<
GitlabMergeRequest
>
getMergeRequests
(
GitlabProject
project
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
project
.
getId
()
+
GitlabMergeRequest
.
URL
;
return
fetchMergeRequests
(
tailUrl
);
}
public
GitlabMergeRequest
getMergeRequest
(
GitlabProject
project
,
Integer
mergeRequestId
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
project
.
getId
()
+
"/merge_request/"
+
mergeRequestId
;
return
retrieve
().
to
(
tailUrl
,
GitlabMergeRequest
.
class
);
}
public
List
<
GitlabNote
>
getNotes
(
GitlabMergeRequest
mergeRequest
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
mergeRequest
.
getProjectId
()
+
GitlabMergeRequest
.
URL
+
"/"
+
mergeRequest
.
getId
()
+
GitlabNote
.
URL
;
GitlabNote
[]
notes
=
retrieve
().
to
(
tailUrl
,
GitlabNote
[].
class
);
return
Arrays
.
asList
(
notes
);
}
public
List
<
GitlabCommit
>
getCommits
(
GitlabMergeRequest
mergeRequest
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
mergeRequest
.
getProjectId
()
+
"/repository"
+
GitlabCommit
.
URL
+
"?ref_name="
+
mergeRequest
.
getSourceBranch
();
GitlabCommit
[]
commits
=
retrieve
().
to
(
tailUrl
,
GitlabCommit
[].
class
);
return
Arrays
.
asList
(
commits
);
}
public
GitlabNote
createNote
(
GitlabMergeRequest
mergeRequest
,
String
body
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
mergeRequest
.
getProjectId
()
+
GitlabMergeRequest
.
URL
+
"/"
+
mergeRequest
.
getId
()
+
GitlabNote
.
URL
;
return
dispatch
().
with
(
"body"
,
body
).
to
(
tailUrl
,
GitlabNote
.
class
);
}
private
List
<
GitlabMergeRequest
>
fetchMergeRequests
(
String
tailUrl
)
throws
IOException
{
GitlabMergeRequest
[]
mergeRequests
=
retrieve
().
to
(
tailUrl
,
GitlabMergeRequest
[].
class
);
return
Arrays
.
asList
(
mergeRequests
);
}
}
src/main/java/org/gitlab/api/http/GitlabHTTPRequestor.java
0 → 100644
View file @
2f87d8c5
package
org
.
gitlab
.
api
.
http
;
import
javax.net.ssl.HttpsURLConnection
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.SSLHandshakeException
;
import
javax.net.ssl.TrustManager
;
import
javax.net.ssl.X509TrustManager
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.lang.reflect.Field
;
import
java.net.HttpURLConnection
;
import
java.net.ProtocolException
;
import
java.net.URL
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.zip.GZIPInputStream
;
import
org.apache.commons.io.IOUtils
;
import
org.gitlab.api.GitlabAPI
;
/**
* Gitlab HTTP Requestor
*
* Responsible for handling HTTP requests to the Gitlab API
*
* @author @timols
*/
public
class
GitlabHTTPRequestor
{
private
final
GitlabAPI
_root
;
private
String
_method
=
"GET"
;
// Default to GET requests
private
Map
<
String
,
Object
>
_data
=
new
HashMap
<
String
,
Object
>();
private
enum
METHOD
{
GET
,
PUT
,
POST
,
PATCH
,
DELETE
,
HEAD
,
OPTIONS
,
TRACE
;
public
static
String
prettyValues
()
{
METHOD
[]
methods
=
METHOD
.
values
();
StringBuilder
builder
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
methods
.
length
;
i
++)
{
METHOD
method
=
methods
[
i
];
builder
.
append
(
method
.
toString
());
if
(
i
!=
methods
.
length
-
1
)
{
builder
.
append
(
", "
);
}
}
return
builder
.
toString
();
}
}
public
GitlabHTTPRequestor
(
GitlabAPI
root
)
{
_root
=
root
;
}
/**
* Sets the HTTP Request method for the request.
*
* Has a fluent api for method chaining.
*
* @param method The HTTP method
* @return this
*/
public
GitlabHTTPRequestor
method
(
String
method
)
{
try
{
_method
=
METHOD
.
valueOf
(
method
).
toString
();
}
catch
(
IllegalArgumentException
e
)
{
throw
new
IllegalArgumentException
(
"Invalid HTTP Method: "
+
method
+
". Must be one of "
+
METHOD
.
prettyValues
());
}
return
this
;
}
/**
* Sets the HTTP Form Post parameters for the request
*
* Has a fluent api for method chaining
*
* @param key
* @param value
* @return this
*/
public
GitlabHTTPRequestor
with
(
String
key
,
Object
value
)
{
if
(
value
!=
null
&&
key
!=
null
)
{
_data
.
put
(
key
,
value
);
}
return
this
;
}
public
<
T
>
T
to
(
String
tailAPIUrl
,
T
instance
)
throws
IOException
{
return
to
(
tailAPIUrl
,
null
,
instance
);
}
public
<
T
>
T
to
(
String
tailAPIUrl
,
Class
<
T
>
type
)
throws
IOException
{
return
to
(
tailAPIUrl
,
type
,
null
);
}
/**
* Opens the HTTP(S) connection, submits any data and parses the response.
* Will throw an error
* @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
* @throws java.io.IOException
*/
public
<
T
>
T
to
(
String
tailAPIUrl
,
Class
<
T
>
type
,
T
instance
)
throws
IOException
{
HttpURLConnection
connection
=
setupConnection
(
_root
.
getAPIUrl
(
tailAPIUrl
));
if
(
hasOutput
())
{
submitData
(
connection
);
}
try
{
return
parse
(
connection
,
type
,
instance
);
}
catch
(
IOException
e
)
{
handleAPIError
(
e
,
connection
);
}
return
null
;
}
private
void
submitData
(
HttpURLConnection
connection
)
throws
IOException
{
connection
.
setDoOutput
(
true
);
connection
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
GitlabAPI
.
MAPPER
.
writeValue
(
connection
.
getOutputStream
(),
_data
);
}
private
boolean
hasOutput
()
{
return
_method
.
equals
(
"POST"
)
||
_method
.
equals
(
"PUT"
)
&&
!
_data
.
isEmpty
();
}
private
HttpURLConnection
setupConnection
(
URL
url
)
throws
IOException
{
if
(
_root
.
isIgnoreCertificateErrors
())
{
ignoreCertificateErrors
();
}
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
try
{
connection
.
setRequestMethod
(
_method
);
}
catch
(
ProtocolException
e
)
{
// Hack in case the API uses a non-standard HTTP verb
try
{
Field
methodField
=
connection
.
getClass
().
getDeclaredField
(
"method"
);
methodField
.
setAccessible
(
true
);
methodField
.
set
(
connection
,
_method
);
}
catch
(
Exception
x
)
{
throw
(
IOException
)
new
IOException
(
"Failed to set the custom verb"
).
initCause
(
x
);
}
}
connection
.
setRequestProperty
(
"Accept-Encoding"
,
"gzip"
);
return
connection
;
}
private
<
T
>
T
parse
(
HttpURLConnection
connection
,
Class
<
T
>
type
,
T
instance
)
throws
IOException
{
InputStreamReader
reader
=
null
;
try
{
reader
=
new
InputStreamReader
(
wrapStream
(
connection
,
connection
.
getInputStream
()),
"UTF-8"
);
String
data
=
IOUtils
.
toString
(
reader
);
if
(
type
!=
null
)
{
return
GitlabAPI
.
MAPPER
.
readValue
(
data
,
type
);
}
else
if
(
instance
!=
null
)
{
return
GitlabAPI
.
MAPPER
.
readerForUpdating
(
instance
).
readValue
(
data
);
}
else
{
return
null
;
}
}
catch
(
SSLHandshakeException
e
)
{
throw
new
SSLHandshakeException
(
"You can disable certificate checking by setting ignoreCertificateErrors on GitlabHTTPRequestor"
);
}
finally
{
IOUtils
.
closeQuietly
(
reader
);
}
}
private
InputStream
wrapStream
(
HttpURLConnection
connection
,
InputStream
inputStream
)
throws
IOException
{
String
encoding
=
connection
.
getContentEncoding
();
if
(
encoding
==
null
||
inputStream
==
null
)
{
return
inputStream
;
}
else
if
(
encoding
.
equals
(
"gzip"
))
{
return
new
GZIPInputStream
(
inputStream
);
}
else
{
throw
new
UnsupportedOperationException
(
"Unexpected Content-Encoding: "
+
encoding
);
}
}
private
void
handleAPIError
(
IOException
e
,
HttpURLConnection
connection
)
throws
IOException
{
if
(
e
instanceof
FileNotFoundException
)
{
throw
e
;
// pass through 404 Not Found to allow the caller to handle it intelligently
}
InputStream
es
=
wrapStream
(
connection
,
connection
.
getErrorStream
());
try
{
if
(
es
!=
null
)
{
throw
(
IOException
)
new
IOException
(
IOUtils
.
toString
(
es
,
"UTF-8"
)).
initCause
(
e
);
}
else
{
throw
e
;
}
}
finally
{
IOUtils
.
closeQuietly
(
es
);
}
}
private
void
ignoreCertificateErrors
()
{
TrustManager
[]
trustAllCerts
=
new
TrustManager
[]{
new
X509TrustManager
()
{
public
java
.
security
.
cert
.
X509Certificate
[]
getAcceptedIssuers
()
{
return
null
;
}
public
void
checkClientTrusted
(
java
.
security
.
cert
.
X509Certificate
[]
certs
,
String
authType
)
{
}
public
void
checkServerTrusted
(
java
.
security
.
cert
.
X509Certificate
[]
certs
,
String
authType
)
{
}
}
};
try
{
SSLContext
sc
=
SSLContext
.
getInstance
(
"SSL"
);
sc
.
init
(
null
,
trustAllCerts
,
new
java
.
security
.
SecureRandom
());
HttpsURLConnection
.
setDefaultSSLSocketFactory
(
sc
.
getSocketFactory
());
}
catch
(
Exception
e
)
{
// Ignore it
}
}
}
src/main/java/org/gitlab/api/models/GitlabCommit.java
0 → 100644
View file @
2f87d8c5
package
org
.
gitlab
.
api
.
models
;
import
java.util.Date
;
import
org.codehaus.jackson.annotate.JsonProperty
;
public
class
GitlabCommit
{
public
final
static
String
URL
=
"/commits"
;
private
String
_id
;
private
String
_title
;
@JsonProperty
(
"short_id"
)
private
String
_shortId
;
@JsonProperty
(
"author_name"
)
private
String
_authorName
;
@JsonProperty
(
"author_email"
)
private
String
_authorEmail
;
@JsonProperty
(
"created_at"
)
private
Date
_createdAt
;
public
String
getId
()
{
return
_id
;
}
public
void
setId
(
String
id
)
{
_id
=
id
;
}
public
String
getShortId
()
{
return
_shortId
;
}
public
void
setShortId
(
String
shortId
)
{
_shortId
=
shortId
;
}
public
String
getTitle
()
{
return
_title
;
}
public
void
setTitle
(
String
title
)
{
_title
=
title
;
}
public
String
getAuthorName
()
{
return
_authorName
;
}
public
void
setAuthorName
(
String
authorName
)
{
_authorName
=
authorName
;
}
public
String
getAuthorEmail
()
{
return
_authorEmail
;
}
public
void
setAuthorEmail
(
String
authorEmail
)
{
_authorEmail
=
authorEmail
;
}
public
Date
getCreatedAt
()
{
return
_createdAt
;
}
public
void
setCreatedAt
(
Date
createdAt
)
{
_createdAt
=
createdAt
;
}
}
src/main/java/org/gitlab/api/models/GitlabMergeRequest.java
0 → 100644
View file @
2f87d8c5
package
org
.
gitlab
.
api
.
models
;
import
org.codehaus.jackson.annotate.JsonProperty
;
public
class
GitlabMergeRequest
{
public
static
final
String
URL
=
"/merge_requests"
;
private
Integer
_id
;
private
String
_title
;
private
String
_state
;
private
boolean
_closed
;
private
boolean
_merged
;
private
GitlabUser
_author
;
private
GitlabUser
_assignee
;
@JsonProperty
(
"target_branch"
)
private
String
_targetBranch
;
@JsonProperty
(
"source_branch"
)
private
String
_sourceBranch
;
@JsonProperty
(
"project_id"
)
private
Integer
_projectId
;
public
Integer
getId
()
{
return
_id
;
}
public
void
setId
(
Integer
id
)
{
_id
=
id
;
}
public
String
getTargetBranch
()
{
return
_targetBranch
;
}
public
void
setTargetBranch
(
String
targetBranch
)
{
_targetBranch
=
targetBranch
;
}
public
String
getSourceBranch
()
{
return
_sourceBranch
;
}
public
void
setSourceBranch
(
String
sourceBranch
)
{
_sourceBranch
=
sourceBranch
;
}
public
Integer
getProjectId
()
{
return
_projectId
;
}
public
void
setProjectId
(
Integer
projectId
)
{
_projectId
=
projectId
;
}
public
String
getTitle
()
{
return
_title
;
}
public
void
setTitle
(
String
title
)
{
_title
=
title
;
}
public
boolean
isClosed
()
{
return
_closed
;
}
public
void
setClosed
(
boolean
closed
)
{
_closed
=
closed
;
}
public
boolean
isMerged
()
{
return
_merged
;
}
public
void
setMerged
(
boolean
merged
)
{
_merged
=
merged
;
}
public
GitlabUser
getAuthor
()
{
return
_author
;
}
public
void
setAuthor
(
GitlabUser
author
)
{
_author
=
author
;
}
public
GitlabUser
getAssignee
()
{
return
_assignee
;
}
public
void
setAssignee
(
GitlabUser
assignee
)
{
_assignee
=
assignee
;
}
public
String
getState
()
{
return
_state
;
}
public
void
setState
(
String
state
)
{
_state
=
state
;
}
}
src/main/java/org/gitlab/api/models/GitlabNamespace.java
0 → 100644
View file @
2f87d8c5
package
org
.
gitlab
.
api
.
models
;
import
java.util.Date
;
import
org.codehaus.jackson.annotate.JsonProperty
;
public
class
GitlabNamespace
{
private
Integer
_id
;
private
String
_name
;
private
String
_path
;
@JsonProperty
(
"created_at"
)
private
Date
_createdAt
;
@JsonProperty
(
"updated_at"
)
private
Date
_updatedAt
;
@JsonProperty
(
"owner_id"
)
private
Integer
_ownerId
;
public
Integer
getId
()
{
return
_id
;
}
public
void
setId
(
Integer
id
)
{
_id
=
id
;
}
public
Date
getCreatedAt
()
{
return
_createdAt
;
}
public
void
setCreatedAt
(
Date
createdAt
)
{
_createdAt
=
createdAt
;
}
public
Date
getUpdatedAt
()
{
return
_updatedAt
;
}
public
void
setUpdatedAt
(
Date
updatedAt
)
{
_updatedAt
=
updatedAt
;
}
public
Integer
getOwnerId
()
{
return
_ownerId
;
}
public
void
setOwnerId
(
Integer
ownerId
)
{
_ownerId
=
ownerId
;
}
public
String
getName
()
{
return
_name
;
}
public
void
setName
(
String
name
)
{
_name
=
name
;
}
public
String
getPath
()
{
return
_path
;
}
public
void
setPath
(
String
path
)
{
_path
=
path
;
}
}
src/main/java/org/gitlab/api/models/GitlabNote.java
0 → 100644
View file @
2f87d8c5
package
org
.
gitlab
.
api
.
models
;
import
java.util.Date
;
import
org.codehaus.jackson.annotate.JsonProperty
;
public
class
GitlabNote
{
public
static
final
String
URL
=
"/notes"
;
private
Integer
_id
;
private
String
_body
;
private
String
_attachment
;
private
GitlabUser
_author
;
@JsonProperty
(
"created_at"
)
private
Date
_createdAt
;
public
Integer
getId
()
{
return
_id
;
}
public
void
setId
(
Integer
id
)
{
_id
=
id
;
}
public
String
getBody
()
{
return
_body
;
}
public
void
setBody
(
String
body
)
{
_body
=
body
;
}
public
GitlabUser
getAuthor
()
{
return
_author
;
}
public
void
setAuthor
(
GitlabUser
author
)
{
_author
=
author
;
}
public
Date
getCreatedAt
()
{
return
_createdAt
;
}
public
void
setCreatedAt
(
Date
createdAt
)
{
_createdAt
=
createdAt
;
}
public
String
getAttachment
()
{
return
_attachment
;
}
public
void
setAttachment
(
String
attachment
)
{
_attachment
=
attachment
;
}
}
src/main/java/org/gitlab/api/models/GitlabProject.java
0 → 100644
View file @
2f87d8c5
package
org
.
gitlab
.
api
.
models
;
import
java.util.Date
;
import
org.codehaus.jackson.annotate.JsonProperty
;
public
class
GitlabProject
{
public
static
final
String
URL
=
"/projects"
;
private
Integer
_id
;
private
String
_name
;
private
String
_description
;
@JsonProperty
(
"default_branch"
)
private
String
_defaultBranch
;
private
GitlabUser
_owner
;
private
boolean
_public
;
private
String
_path
;
@JsonProperty
(
"path_with_namespace"
)
private
String
_pathWithNamespace
;
@JsonProperty
(
"issues_enabled"
)
private
boolean
_issuesEnabled
;
@JsonProperty
(
"merge_requests_enabled"
)
private
boolean
_mergeRequestsEnabled
;
@JsonProperty
(
"wall_enabled"
)
private
boolean
_wallEnabled
;
@JsonProperty
(
"wiki_enabled"
)
private
boolean
_wikiEnabled
;
@JsonProperty
(
"created_at"
)
private
Date
_createdAt
;
private
GitlabNamespace
_namespace
;
public
Integer
getId
()
{
return
_id
;
}
public
void
setId
(
Integer
id
)
{
_id
=
id
;
}
public
String
getName
()
{
return
_name
;
}
public
void
setName
(
String
name
)
{
_name
=
name
;
}
public
String
getDescription
()
{
return
_description
;
}
public
void
setDescription
(
String
description
)
{
_description
=
description
;
}
public
String
getDefaultBranch
()
{
return
_defaultBranch
;
}
public
void
setDefaultBranch
(
String
defaultBranch
)
{
_defaultBranch
=
defaultBranch
;
}
public
GitlabUser
getOwner
()
{
return
_owner
;
}
public
void
setOwner
(
GitlabUser
owner
)
{
_owner
=
owner
;
}
public
String
getPath
()
{
return
_path
;
}
public
void
setPath
(
String
path
)
{
_path
=
path
;
}
public
String
getPathWithNamespace
()
{
return
_pathWithNamespace
;
}
public
void
setPathWithNamespace
(
String
pathWithNamespace
)
{
_pathWithNamespace
=
pathWithNamespace
;
}
public
boolean
isIssuesEnabled
()
{
return
_issuesEnabled
;
}
public
void
setIssuesEnabled
(
boolean
issuesEnabled
)
{
_issuesEnabled
=
issuesEnabled
;
}
public
boolean
isMergeRequestsEnabled
()
{
return
_mergeRequestsEnabled
;
}
public
void
setMergeRequestsEnabled
(
boolean
mergeRequestsEnabled
)
{
_mergeRequestsEnabled
=
mergeRequestsEnabled
;
}
public
boolean
isWallEnabled
()
{
return
_wallEnabled
;
}
public
void
setWallEnabled
(
boolean
wallEnabled
)
{
_wallEnabled
=
wallEnabled
;
}
public
boolean
isWikiEnabled
()
{
return
_wikiEnabled
;
}
public
void
setWikiEnabled
(
boolean
wikiEnabled
)
{
_wikiEnabled
=
wikiEnabled
;
}
public
Date
getCreatedAt
()
{
return
_createdAt
;
}
public
void
setCreatedAt
(
Date
createdAt
)
{
_createdAt
=
createdAt
;
}
public
GitlabNamespace
getNamespace
()
{
return
_namespace
;
}
public
void
setNamespace
(
GitlabNamespace
namespace
)
{
_namespace
=
namespace
;
}
public
boolean
isPublic
()
{
return
_public
;
}
public
void
setPublic
(
boolean
aPublic
)
{
_public
=
aPublic
;
}
}
src/main/java/org/gitlab/api/models/GitlabUser.java
0 → 100644
View file @
2f87d8c5
package
org
.
gitlab
.
api
.
models
;
import
java.util.Date
;
import
org.codehaus.jackson.annotate.JsonProperty
;
public
class
GitlabUser
{
public
static
String
URL
=
"/users"
;
private
Integer
_id
;
private
String
_username
;
private
String
_email
;
private
String
_name
;
private
String
_skype
;
private
String
_linkedin
;
private
String
_twitter
;
private
String
_provider
;
private
String
_state
;
private
boolean
_blocked
;
@JsonProperty
(
"created_at"
)
private
Date
_createdAt
;
@JsonProperty
(
"bio"
)
private
String
_bio
;
@JsonProperty
(
"dark_scheme"
)
private
boolean
_darkScheme
;
@JsonProperty
(
"theme_id"
)
private
Integer
_themeId
;
@JsonProperty
(
"extern_uid"
)
private
String
_externUid
;
@JsonProperty
(
"is_admin"
)
private
boolean
_isAdmin
;
@JsonProperty
(
"can_create_group"
)
private
boolean
_canCreateGroup
;
@JsonProperty
(
"can_create_project"
)
private
boolean
_canCreateProject
;
@JsonProperty
(
"can_create_team"
)
private
boolean
_canCreateTeam
;
public
Integer
getId
()
{
return
_id
;
}
public
void
setId
(
Integer
id
)
{
_id
=
id
;
}
public
String
getUsername
()
{
return
_username
;
}
public
void
setUsername
(
String
userName
)
{
_username
=
userName
;
}
public
String
getEmail
()
{
return
_email
;
}
public
void
setEmail
(
String
email
)
{
_email
=
email
;
}
public
String
getName
()
{
return
_name
;
}
public
void
setName
(
String
name
)
{
_name
=
name
;
}
public
boolean
isBlocked
()
{
return
_blocked
;
}
public
void
setBlocked
(
boolean
blocked
)
{
_blocked
=
blocked
;
}
public
Date
getCreatedAt
()
{
return
_createdAt
;
}
public
void
setCreatedAt
(
Date
createdAt
)
{
_createdAt
=
createdAt
;
}
public
String
getBio
()
{
return
_bio
;
}
public
void
setBio
(
String
bio
)
{
_bio
=
bio
;
}
public
String
getSkype
()
{
return
_skype
;
}
public
void
setSkype
(
String
skype
)
{
_skype
=
skype
;
}
public
String
getLinkedin
()
{
return
_linkedin
;
}
public
void
setLinkedin
(
String
linkedin
)
{
_linkedin
=
linkedin
;
}
public
String
getTwitter
()
{
return
_twitter
;
}
public
void
setTwitter
(
String
twitter
)
{
_twitter
=
twitter
;
}
public
boolean
isDarkScheme
()
{
return
_darkScheme
;
}
public
void
setDarkScheme
(
boolean
darkScheme
)
{
_darkScheme
=
darkScheme
;
}
public
Integer
getThemeId
()
{
return
_themeId
;
}
public
void
setThemeId
(
Integer
themeId
)
{
_themeId
=
themeId
;
}
public
String
getExternUid
()
{
return
_externUid
;
}
public
void
setExternUid
(
String
externUid
)
{
_externUid
=
externUid
;
}
public
String
getProvider
()
{
return
_provider
;
}
public
void
setProvider
(
String
provider
)
{
_provider
=
provider
;
}
public
String
getState
()
{
return
_state
;
}
public
void
setState
(
String
state
)
{
_state
=
state
;
}
public
boolean
isAdmin
()
{
return
_isAdmin
;
}
public
void
setAdmin
(
boolean
admin
)
{
_isAdmin
=
admin
;
}
public
boolean
isCanCreateGroup
()
{
return
_canCreateGroup
;
}
public
void
setCanCreateGroup
(
boolean
canCreateGroup
)
{
_canCreateGroup
=
canCreateGroup
;
}
public
boolean
isCanCreateProject
()
{
return
_canCreateProject
;
}
public
void
setCanCreateProject
(
boolean
canCreateProject
)
{
_canCreateProject
=
canCreateProject
;
}
public
boolean
isCanCreateTeam
()
{
return
_canCreateTeam
;
}
public
void
setCanCreateTeam
(
boolean
canCreateTeam
)
{
_canCreateTeam
=
canCreateTeam
;
}
}
src/test/java/org/gitlab/api/GitlabAPITest.java
0 → 100644
View file @
2f87d8c5
package
org
.
gitlab
.
api
;
import
java.io.IOException
;
import
java.net.URL
;
import
org.gitlab.api.models.GitlabProject
;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
public
class
GitlabAPITest
{
GitlabAPI
_api
;
@Before
public
void
setup
()
{
_api
=
GitlabAPI
.
connect
(
"http://localhost"
,
"token"
);
}
@Test
public
void
testConnect
()
throws
IOException
{
assertEquals
(
GitlabAPI
.
class
,
_api
.
getClass
());
}
@Test
public
void
testGetAPIUrl
()
throws
IOException
{
URL
expected
=
new
URL
(
"http://localhost/api/v3/?private_token=token"
);
assertEquals
(
expected
,
_api
.
getAPIUrl
(
""
));
}
@Test
public
void
testGetUrl
()
throws
IOException
{
URL
expected
=
new
URL
(
"http://localhost/"
);
assertEquals
(
expected
,
_api
.
getUrl
(
""
));
}
}
src/test/java/org/gitlab/api/http/GitlabHTTPRequestorTest.java
0 → 100644
View file @
2f87d8c5
package
org
.
gitlab
.
api
.
http
;
import
org.gitlab.api.GitlabAPI
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
public
class
GitlabHTTPRequestorTest
{
@Test
public
void
testSettingInvalidHTTPMethod
()
{
GitlabHTTPRequestor
http
=
new
GitlabHTTPRequestor
(
GitlabAPI
.
connect
(
"localhost"
,
"api"
));
try
{
http
.
method
(
"WRONG METHOD"
);
}
catch
(
Exception
e
)
{
assertEquals
(
"Invalid HTTP Method: WRONG METHOD. Must be one of GET, PUT, POST, PATCH, DELETE, HEAD, OPTIONS, TRACE"
,
e
.
getMessage
());
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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