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
dcaa67a6
Commit
dcaa67a6
authored
Aug 08, 2018
by
zhangzhenglong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加enable deploy key接口
parent
3d791ca4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
27 deletions
+99
-27
GitlabAPI.java
src/main/java/org/gitlab/api/GitlabAPI.java
+9
-0
DeployKey.java
src/main/java/org/gitlab/api/models/DeployKey.java
+51
-0
GitLabClient.java
src/test/java/org/gitlab/api/GitLabClient.java
+8
-1
test.java
src/test/java/org/gitlab/api/test.java
+31
-26
No files found.
src/main/java/org/gitlab/api/GitlabAPI.java
View file @
dcaa67a6
...
...
@@ -302,6 +302,15 @@ public class GitlabAPI {
retrieve
().
method
(
"POST"
).
to
(
tailUrl
,
Void
.
class
);
}
public
DeployKey
enableDeployKey
(
Integer
projectId
,
Integer
deployKeyId
)
throws
IOException
{
String
tailUrl
=
"projects/"
+
projectId
+
"/deploy_keys/"
+
deployKeyId
+
"/enable"
;
return
retrieve
().
method
(
"POST"
).
to
(
tailUrl
,
DeployKey
.
class
);
}
/**
* Create a new ssh key for the user
*
...
...
src/main/java/org/gitlab/api/models/DeployKey.java
0 → 100644
View file @
dcaa67a6
package
org
.
gitlab
.
api
.
models
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
java.util.Date
;
public
class
DeployKey
{
public
static
final
String
URL
=
"/comments"
;
private
Integer
id
;
private
String
key
;
private
String
title
;
@JsonProperty
(
"created_at"
)
private
Date
createdAt
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
String
getKey
()
{
return
key
;
}
public
void
setKey
(
String
key
)
{
this
.
key
=
key
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
Date
getCreatedAt
()
{
return
createdAt
;
}
public
void
setCreatedAt
(
Date
createdAt
)
{
this
.
createdAt
=
createdAt
;
}
}
src/test/java/org/gitlab/api/GitLabClient.java
View file @
dcaa67a6
...
...
@@ -16,7 +16,7 @@ public class GitLabClient {
private
static
final
String
GITLAB_SERVER
=
"http://gitlab2.dui88.com"
;
private
static
final
String
TOKEN
=
"
HUCQzy6EyyffAsyAmkCg
"
;
private
static
final
String
TOKEN
=
"
rCyBy1sQ-JckquyFmo4c
"
;
private
GitLabClient
()
{
}
...
...
@@ -87,4 +87,11 @@ public class GitLabClient {
return
null
;
}
}
public
static
DeployKey
enableDeployKey
(
Integer
projectId
,
Integer
deployKeyId
){
try
{
return
client
.
enableDeployKey
(
projectId
,
deployKeyId
);
}
catch
(
IOException
e
)
{
return
null
;
}
}
}
src/test/java/org/gitlab/api/test.java
View file @
dcaa67a6
package
org
.
gitlab
.
api
;
import
org.gitlab.api.models.DeployKey
;
import
org.gitlab.api.models.GitlabMergeRequest
;
import
org.gitlab.api.models.GitlabProject
;
...
...
@@ -25,32 +26,36 @@ public class test {
//获取这一周时间 所有工程 发起的和并都develop的MR次数
public
static
void
main
(
String
[]
args
)
throws
IOException
{
// GitlabAPI gitlabAPI = GitLabClient.getClient();
// //获取所有的工程
// int allMergeCount = 0;
// int all = 0;
// List<GitlabProject> gitlabProject = GitLabClient.getAllProject();
// Date startDate = parse(8, 01);
// Date endDate = parse(8, 30);
// System.out.println(startDate);
// System.out.println(endDate);
// for (GitlabProject project : gitlabProject) {
// int mergeCount = 0;
// List<GitlabMergeRequest> mergeRequests = gitlabAPI.getAllMergeRequests(project);
// for (GitlabMergeRequest mergeRequest : mergeRequests) {
// if (mergeRequest.getTargetBranch().equalsIgnoreCase("develop")
// && mergeRequest.getCreatedAt().after(startDate)
// && mergeRequest.getCreatedAt().before(endDate)) {
// mergeCount++;
// allMergeCount++;
// }
// all++;
// }
// if (mergeCount > 0) {
// System.out.println(project.getPathWithNamespace()+","+ mergeCount);
// }
// }
// System.out.println("合并到Develop的MR总数:" + allMergeCount);
// System.out.println("所有的MR总数" +all);
GitlabAPI
gitlabAPI
=
GitLabClient
.
getClient
();
//获取所有的工程
int
allMergeCount
=
0
;
int
all
=
0
;
List
<
GitlabProject
>
gitlabProject
=
GitLabClient
.
getAllProject
();
Date
startDate
=
parse
(
8
,
01
);
Date
endDate
=
parse
(
8
,
30
);
System
.
out
.
println
(
startDate
);
System
.
out
.
println
(
endDate
);
for
(
GitlabProject
project
:
gitlabProject
)
{
int
mergeCount
=
0
;
List
<
GitlabMergeRequest
>
mergeRequests
=
gitlabAPI
.
getAllMergeRequests
(
project
);
for
(
GitlabMergeRequest
mergeRequest
:
mergeRequests
)
{
if
(
mergeRequest
.
getTargetBranch
().
equalsIgnoreCase
(
"develop"
)
&&
mergeRequest
.
getCreatedAt
().
after
(
startDate
)
&&
mergeRequest
.
getCreatedAt
().
before
(
endDate
))
{
mergeCount
++;
allMergeCount
++;
}
all
++;
}
if
(
mergeCount
>
0
)
{
System
.
out
.
println
(
project
.
getPathWithNamespace
()+
","
+
mergeCount
);
}
}
System
.
out
.
println
(
"合并到Develop的MR总数:"
+
allMergeCount
);
System
.
out
.
println
(
"所有的MR总数"
+
all
);
DeployKey
deployKey
=
gitlabAPI
.
enableDeployKey
(
630
,
469
);
}
}
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