Browse Source

fix: 修改获取文件权限问题

shanshan 4 years ago
parent
commit
c647dc6631

+ 1 - 1
web/src/main/java/cn/seecoder/web/controller/code_review/CodeReviewController.java

@@ -150,7 +150,7 @@ public class CodeReviewController {
         try {
         try {
             if(path != null) return Response.buildSuccess(fileReviewService.getRepositoryTree(projectId, branch, path));
             if(path != null) return Response.buildSuccess(fileReviewService.getRepositoryTree(projectId, branch, path));
             else return Response.buildSuccess(fileReviewService.getRepositoryTree(projectId, branch));
             else return Response.buildSuccess(fileReviewService.getRepositoryTree(projectId, branch));
-        } catch (IOException exception) {
+        } catch (SeecoderGitlabException exception) {
             return Response.buildFailure(500, exception.getMessage());
             return Response.buildFailure(500, exception.getMessage());
         }
         }
     }
     }

+ 12 - 0
web/src/main/java/cn/seecoder/web/model/vo/code_review/FileNodeVO.java

@@ -3,6 +3,7 @@ package cn.seecoder.web.model.vo.code_review;
 import lombok.AllArgsConstructor;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.NoArgsConstructor;
+import org.gitlab4j.api.models.TreeItem;
 
 
 @Data
 @Data
 @AllArgsConstructor
 @AllArgsConstructor
@@ -22,4 +23,15 @@ public class FileNodeVO {
             this.leaf = true;
             this.leaf = true;
         }
         }
     }
     }
+
+    public FileNodeVO(TreeItem node) {
+        this.name = node.getName();
+        this.path = node.getPath();
+        if (node.getType().equals(TreeItem.Type.TREE)) {
+            this.leaf = false;
+        }
+        else {
+            this.leaf = true;
+        }
+    }
 }
 }

+ 1 - 1
web/src/main/java/cn/seecoder/web/service/code_review/FileReviewService.java

@@ -25,7 +25,7 @@ public interface FileReviewService {
 
 
     String getFile(int projectId, String branch, String path) throws SeecoderGitlabException;
     String getFile(int projectId, String branch, String path) throws SeecoderGitlabException;
 
 
-    List<FileNodeVO> getRepositoryTree(int projectId, String branch, String... path) throws IOException;
+    List<FileNodeVO> getRepositoryTree(int projectId, String branch, String... path) throws SeecoderGitlabException;
 
 
     UserVO inviteUser(String phoneNumber) throws ServiceException;
     UserVO inviteUser(String phoneNumber) throws ServiceException;
 
 

+ 21 - 15
web/src/main/java/cn/seecoder/web/service/impl/code_review/FileReviewServiceImpl.java

@@ -25,6 +25,8 @@ import okhttp3.OkHttpClient;
 import okhttp3.Request;
 import okhttp3.Request;
 import okhttp3.Response;
 import okhttp3.Response;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpStatus;
+import org.gitlab4j.api.GitLabApi;
+import org.gitlab4j.api.models.TreeItem;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
@@ -85,21 +87,25 @@ public class FileReviewServiceImpl implements FileReviewService {
     }
     }
 
 
     @Override
     @Override
-    public List<FileNodeVO> getRepositoryTree(int projectId, String branch, String... path) throws IOException {
-        ObjectMapper objectMapper = new ObjectMapper();
-        StringBuilder stringBuilder = new StringBuilder("https://seecoder-gitlab-gitlab.seec.seecoder.cn/api/v4/projects/")
-                .append(projectId)
-                .append("/repository/tree?ref=")
-                .append(branch).append("&").append("path=");
-        if(path.length > 0) stringBuilder.append(path[0]);
-        Request request = new Request.Builder().url(stringBuilder.toString()).build();
-        Response response = httpClient.newCall(request).execute();
-        List<FileNodeCreateVO> result;
-        try {
-            result = objectMapper.readValue(response.body().string(), new TypeReference<List<FileNodeCreateVO>>(){});
-        } catch (IOException exception) {
-            throw new IOException("获取文件夹内容失败,请确保您的GitLab代码仓库权限设置为public");
-        }
+    public List<FileNodeVO> getRepositoryTree(int projectId, String branch, String... path) throws SeecoderGitlabException {
+//        ObjectMapper objectMapper = new ObjectMapper();
+//        StringBuilder stringBuilder = new StringBuilder("https://seecoder-gitlab-gitlab.seec.seecoder.cn/api/v4/projects/")
+//                .append(projectId)
+//                .append("/repository/tree?ref=")
+//                .append(branch).append("&").append("path=");
+//        if(path.length > 0) stringBuilder.append(path[0]);
+//        Request request = new Request.Builder().url(stringBuilder.toString()).build();
+//        Response response = httpClient.newCall(request).execute();
+//        List<FileNodeCreateVO> result;
+//        try {
+//            result = objectMapper.readValue(response.body().string(), new TypeReference<List<FileNodeCreateVO>>(){});
+//        } catch (IOException exception) {
+//            throw new IOException("获取文件夹内容失败,请确保您的GitLab代码仓库权限设置为public");
+//        }
+
+        String filePath = "/";
+        if (path.length > 0) filePath = path[0];
+        List<TreeItem> result = seecoderGitlabApi.getRepositoryTree(projectId, filePath, branch);
         return result.stream().map(item -> new FileNodeVO(item)).collect(Collectors.toList());
         return result.stream().map(item -> new FileNodeVO(item)).collect(Collectors.toList());
     }
     }
 
 

+ 3 - 0
web/src/main/resources/application-wph.yml

@@ -52,6 +52,9 @@ seecoder:
     registryUsername: admin
     registryUsername: admin
     registryPassword: NJU67nexus
     registryPassword: NJU67nexus
     tls: true
     tls: true
+  sonar:
+    host: https://sonarqube-test.seec.seecoder.cn
+    loginToken: 787658b11f0332f631bfb186aa1bfcd7898b0498
 
 
 
 
 
 

+ 24 - 0
web/src/main/resources/sql/table_init.sql

@@ -283,4 +283,28 @@ create table if not exists devcloud.inspection_result
     file_review_id int not null ,
     file_review_id int not null ,
     reviewer_id int not null,
     reviewer_id int not null,
     pass int not null
     pass int not null
+)charset = utf8;
+
+create table if not exists devcloud.interface_test_info(
+                                       `id` int(11) NOT NULL AUTO_INCREMENT,
+                                       `name` varchar(255) NOT NULL,
+                                       `project_id` int(11) NOT NULL,
+                                       `create_time` datetime NOT NULL,
+                                       `username` varchar(255) NOT NULL,
+                                       `url` varchar(255) NOT NULL,
+                                       `method` varchar(255) NOT NULL,
+                                       `params` json DEFAULT NULL,
+                                       PRIMARY KEY (`id`)
+)charset = utf8;
+
+CREATE TABLE if not exists devcloud.interface_test_result (
+                                         `id` int(11) NOT NULL AUTO_INCREMENT,
+                                         `test_id` int(11) NOT NULL,
+                                         `execute_time` datetime NOT NULL,
+                                         `username` varchar(255) NOT NULL,
+                                         `code` int(11) NOT NULL,
+                                         `cost` int(11) NOT NULL,
+                                         `result` longtext,
+                                         `deployment_id` int(11) DEFAULT NULL,
+                                         PRIMARY KEY (`id`)
 )charset = utf8;
 )charset = utf8;