Browse Source

优化

dev-DXTZYK
chenzhihang 1 year ago
parent
commit
f6e7ddd1bf
1 changed files with 11 additions and 8 deletions
  1. +11
    -8
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/GitServiceImpl.java

+ 11
- 8
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/GitServiceImpl.java View File

@@ -30,6 +30,9 @@ public class GitServiceImpl implements GitService {
private String redisHost; private String redisHost;
@Value("${spring.redis.port}") @Value("${spring.redis.port}")
private Integer redisPort; private Integer redisPort;
@Value("${git.endpoint}")
String gitendpoint;

private static final Logger log = LoggerFactory.getLogger(GitServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(GitServiceImpl.class);


@Override @Override
@@ -43,7 +46,7 @@ public class GitServiceImpl implements GitService {
params.put("client_secret", "L3wBKTNnRo-wPen7bxR3F1myCvtVDgpWa6MnpfyWeJE"); params.put("client_secret", "L3wBKTNnRo-wPen7bxR3F1myCvtVDgpWa6MnpfyWeJE");
try { try {
// 发送POST请求 // 发送POST请求
String req = HttpUtils.sendPostRequest("https://www.gitlink.org.cn/oauth/token", null, JsonUtils.mapToJson(params));
String req = HttpUtils.sendPostRequest(gitendpoint + "/oauth/token", null, JsonUtils.mapToJson(params));
// 解析响应JSON // 解析响应JSON
if (StringUtils.isEmpty(req)) { if (StringUtils.isEmpty(req)) {
throw new RuntimeException("终止响应内容为空。"); throw new RuntimeException("终止响应内容为空。");
@@ -55,7 +58,7 @@ public class GitServiceImpl implements GitService {
String accessToken = (String) runResMap.get("access_token"); String accessToken = (String) runResMap.get("access_token");


//通过access_token获取用户信息 //通过access_token获取用户信息
String userReq = HttpUtils.sendGetWithToken("https://www.gitlink.org.cn/api/users/get_user_info.json", null, accessToken);
String userReq = HttpUtils.sendGetWithToken(gitendpoint + "/api/users/get_user_info.json", null, accessToken);
if (StringUtils.isEmpty(userReq)) { if (StringUtils.isEmpty(userReq)) {
throw new RuntimeException("终止响应内容为空。"); throw new RuntimeException("终止响应内容为空。");
} }
@@ -100,7 +103,7 @@ public class GitServiceImpl implements GitService {


@Override @Override
public Map createProject(String token,GitProjectVo gitProjectVo) throws Exception { public Map createProject(String token,GitProjectVo gitProjectVo) throws Exception {
String userReq = HttpUtils.sendPostWithToken("https://www.gitlink.org.cn/api/projects.json", JsonUtils.objectToJson(gitProjectVo), token);
String userReq = HttpUtils.sendPostWithToken(gitendpoint + "/api/projects.json", JsonUtils.objectToJson(gitProjectVo), token);
return JsonUtils.jsonToMap(userReq); return JsonUtils.jsonToMap(userReq);
} }


@@ -125,12 +128,12 @@ public class GitServiceImpl implements GitService {
Map<String, Object> resMap = new HashMap<>(); Map<String, Object> resMap = new HashMap<>();
resMap.put("project_id", id); resMap.put("project_id", id);
resMap.put("name", topicName); resMap.put("name", topicName);
String req = HttpUtils.sendPostWithToken("https://www.gitlink.org.cn/api/v1/project_topics.json", JsonUtils.objectToJson(resMap), token);
String req = HttpUtils.sendPostWithToken(gitendpoint + "/api/v1/project_topics.json", JsonUtils.objectToJson(resMap), token);
} }


@Override @Override
public List<Map<String, Object>> getBrancheList(String token,String owner, String projectName) throws Exception { public List<Map<String, Object>> getBrancheList(String token,String owner, String projectName) throws Exception {
String req = HttpUtils.sendGetWithToken("https://www.gitlink.org.cn/api/v1/" + owner + "/" + projectName + "/branches/all.json", null, token);
String req = HttpUtils.sendGetWithToken(gitendpoint + "/api/v1/" + owner + "/" + projectName + "/branches/all.json", null, token);
// 解析响应JSON // 解析响应JSON
if (StringUtils.isEmpty(req)) { if (StringUtils.isEmpty(req)) {
throw new RuntimeException("终止响应内容为空。"); throw new RuntimeException("终止响应内容为空。");
@@ -142,7 +145,7 @@ public class GitServiceImpl implements GitService {


@Override @Override
public void deleteProject(String token,String owner, String projectName) throws Exception { public void deleteProject(String token,String owner, String projectName) throws Exception {
HttpUtils.sendDeleteRequest("https://www.gitlink.org.cn/api/" + owner + "/" + projectName + ".json", token);
HttpUtils.sendDeleteRequest(gitendpoint + "/api/" + owner + "/" + projectName + ".json", token);
} }


@Override @Override
@@ -153,12 +156,12 @@ public class GitServiceImpl implements GitService {
} catch (IOException | GitAPIException e) { } catch (IOException | GitAPIException e) {
log.error("Exception occurred while creating local branch based on master",e); log.error("Exception occurred while creating local branch based on master",e);
} }
HttpUtils.sendDeleteRequest("https://www.gitlink.org.cn/api/v1/" + owner + "/" + projectName + "/branches/" + branchName + ".json", token);
HttpUtils.sendDeleteRequest(gitendpoint + "/api/v1/" + owner + "/" + projectName + "/branches/" + branchName + ".json", token);
} }


@Override @Override
public Map getUserInfo(String token) throws Exception { public Map getUserInfo(String token) throws Exception {
String userReq = HttpUtils.sendGetWithToken("https://www.gitlink.org.cn/api/users/get_user_info.json",null, token);
String userReq = HttpUtils.sendGetWithToken(gitendpoint + "/api/users/get_user_info.json",null, token);
if (StringUtils.isEmpty(userReq)){ if (StringUtils.isEmpty(userReq)){
return null; return null;
} }


Loading…
Cancel
Save