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
5daa647d
Commit
5daa647d
authored
Feb 15, 2014
by
Tim Olshansky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2 from nalbion/master
Added support for un/protectBranch
parents
983e34fe
20675373
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
129 additions
and
0 deletions
+129
-0
GitlabAPI.java
src/main/java/org/gitlab/api/GitlabAPI.java
+52
-0
GitlabHTTPRequestor.java
src/main/java/org/gitlab/api/http/GitlabHTTPRequestor.java
+4
-0
GitlabBranch.java
src/main/java/org/gitlab/api/models/GitlabBranch.java
+32
-0
GitlabProjectHook.java
src/main/java/org/gitlab/api/models/GitlabProjectHook.java
+41
-0
No files found.
src/main/java/org/gitlab/api/GitlabAPI.java
View file @
5daa647d
...
...
@@ -3,13 +3,16 @@ package org.gitlab.api;
import
org.codehaus.jackson.map.DeserializationConfig
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.gitlab.api.http.GitlabHTTPRequestor
;
import
org.gitlab.api.models.GitlabBranch
;
import
org.gitlab.api.models.GitlabCommit
;
import
org.gitlab.api.models.GitlabMergeRequest
;
import
org.gitlab.api.models.GitlabNote
;
import
org.gitlab.api.models.GitlabProject
;
import
org.gitlab.api.models.GitlabProjectHook
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.net.URLEncoder
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Iterator
;
...
...
@@ -188,6 +191,55 @@ public class GitlabAPI {
return
dispatch
().
with
(
"body"
,
body
).
to
(
tailUrl
,
GitlabNote
.
class
);
}
public
List
<
GitlabBranch
>
getBranches
(
GitlabProject
project
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
project
.
getId
()
+
GitlabBranch
.
URL
;
GitlabBranch
[]
branches
=
retrieve
().
to
(
tailUrl
,
GitlabBranch
[].
class
);
return
Arrays
.
asList
(
branches
);
}
public
GitlabBranch
getBranch
(
GitlabProject
project
,
String
branchName
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
project
.
getId
()
+
GitlabBranch
.
URL
+
branchName
;
GitlabBranch
branch
=
retrieve
().
to
(
tailUrl
,
GitlabBranch
.
class
);
return
branch
;
}
public
void
protectBranch
(
GitlabProject
project
,
String
branchName
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
project
.
getId
()
+
GitlabBranch
.
URL
+
branchName
+
"/protect"
;
retrieve
().
method
(
"PUT"
).
to
(
tailUrl
,
Void
.
class
);
}
public
void
unprotectBranch
(
GitlabProject
project
,
String
branchName
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
project
.
getId
()
+
GitlabBranch
.
URL
+
branchName
+
"/unprotect"
;
retrieve
().
method
(
"PUT"
).
to
(
tailUrl
,
Void
.
class
);
}
public
List
<
GitlabProjectHook
>
getProjectHooks
(
GitlabProject
project
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
project
.
getId
()
+
GitlabProjectHook
.
URL
;
GitlabProjectHook
[]
hooks
=
retrieve
().
to
(
tailUrl
,
GitlabProjectHook
[].
class
);
return
Arrays
.
asList
(
hooks
);
}
public
GitlabProjectHook
getProjectHook
(
GitlabProject
project
,
String
hookId
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
project
.
getId
()
+
GitlabProjectHook
.
URL
+
"/"
+
hookId
;
GitlabProjectHook
hook
=
retrieve
().
to
(
tailUrl
,
GitlabProjectHook
.
class
);
return
hook
;
}
public
GitlabProjectHook
addProjectHook
(
GitlabProject
project
,
String
url
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
project
.
getId
()
+
GitlabProjectHook
.
URL
+
"?url="
+
URLEncoder
.
encode
(
url
,
"UTF-8"
);
return
dispatch
().
to
(
tailUrl
,
GitlabProjectHook
.
class
);
}
public
GitlabProjectHook
editProjectHook
(
GitlabProject
project
,
String
hookId
,
String
url
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
project
.
getId
()
+
GitlabProjectHook
.
URL
+
"/"
+
hookId
+
"?url="
+
URLEncoder
.
encode
(
url
,
"UTF-8"
);
return
retrieve
().
method
(
"PUT"
).
to
(
tailUrl
,
GitlabProjectHook
.
class
);
}
public
void
deleteProjectHook
(
GitlabProject
project
,
String
hookId
)
throws
IOException
{
String
tailUrl
=
GitlabProject
.
URL
+
"/"
+
project
.
getId
()
+
GitlabProjectHook
.
URL
+
"/"
+
hookId
;
retrieve
().
method
(
"DELETE"
).
to
(
tailUrl
,
Void
.
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
View file @
5daa647d
...
...
@@ -113,6 +113,10 @@ public class GitlabHTTPRequestor {
if
(
hasOutput
())
{
submitData
(
connection
);
}
else
if
(
"PUT"
.
equals
(
_method
)
)
{
// PUT requires Content-Length: 0 even when there is no body (eg: API for protecting a branch)
connection
.
setDoOutput
(
true
);
connection
.
setFixedLengthStreamingMode
(
0
);
}
try
{
...
...
src/main/java/org/gitlab/api/models/GitlabBranch.java
0 → 100644
View file @
5daa647d
package
org
.
gitlab
.
api
.
models
;
import
org.codehaus.jackson.annotate.JsonProperty
;
public
class
GitlabBranch
{
public
final
static
String
URL
=
"/repository/branches/"
;
@JsonProperty
(
"name"
)
private
String
_name
;
// @JsonProperty("commit")
// private GitlabCommit _commit;
@JsonProperty
(
"protected"
)
private
boolean
_protected
;
public
String
getName
()
{
return
_name
;
}
public
void
setName
(
String
name
)
{
this
.
_name
=
name
;
}
public
boolean
isProtected
()
{
return
_protected
;
}
public
void
setProtected
(
boolean
isProtected
)
{
this
.
_protected
=
isProtected
;
}
}
src/main/java/org/gitlab/api/models/GitlabProjectHook.java
0 → 100644
View file @
5daa647d
package
org
.
gitlab
.
api
.
models
;
import
java.util.Date
;
import
org.codehaus.jackson.annotate.JsonProperty
;
public
class
GitlabProjectHook
{
public
final
static
String
URL
=
"/hooks"
;
private
String
_id
;
private
String
_url
;
@JsonProperty
(
"created_at"
)
private
Date
_createdAt
;
public
String
getId
()
{
return
_id
;
}
public
void
setId
(
String
id
)
{
_id
=
id
;
}
public
String
getUrl
()
{
return
_url
;
}
public
void
setUrl
(
String
url
)
{
this
.
_url
=
url
;
}
public
Date
getCreatedAt
()
{
return
_createdAt
;
}
public
void
setCreatedAt
(
Date
createdAt
)
{
_createdAt
=
createdAt
;
}
}
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