|
|
@@ -25,6 +25,8 @@ import okhttp3.OkHttpClient;
|
|
|
import okhttp3.Request;
|
|
|
import okhttp3.Response;
|
|
|
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.stereotype.Service;
|
|
|
|
|
|
@@ -85,21 +87,25 @@ public class FileReviewServiceImpl implements FileReviewService {
|
|
|
}
|
|
|
|
|
|
@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());
|
|
|
}
|
|
|
|