Commit dcaa67a6 authored by zhangzhenglong's avatar zhangzhenglong

添加enable deploy key接口

parent 3d791ca4
......@@ -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
*
......
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;
}
}
......@@ -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;
}
}
}
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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment