提交 21b6711e authored 作者: 马晨俊's avatar 马晨俊

mcj:更新git上传接口

上级 ce64c408
...@@ -378,7 +378,7 @@ public class InspectController { ...@@ -378,7 +378,7 @@ public class InspectController {
} }
@PostMapping("/uploads") @PostMapping("/uploads")
private ResponseEntity uploads(@RequestParam(value = "file") MultipartFile multfile){ private ResponseEntity uploads(@RequestParam(value = "file") MultipartFile multfile,String s){
try { try {
File file = FileUtil.saveToLocal(multfile); File file = FileUtil.saveToLocal(multfile);
String name = file.getName(); String name = file.getName();
...@@ -390,7 +390,7 @@ public class InspectController { ...@@ -390,7 +390,7 @@ public class InspectController {
} }
} }
@PostMapping("/gitdownload") @PostMapping("/gitdownload")
private ResponseEntity gitDownloads(String gitAddress){ private ResponseEntity gitDownloads(String gitAddress,String username,String password){
String gitPath = GitLabUtil.downLoadProject(gitAddress); String gitPath = GitLabUtil.downLoadProject(gitAddress);
return ResponseEntity.ok(gitPath); return ResponseEntity.ok(gitPath);
} }
......
...@@ -3,6 +3,7 @@ package com.zjty.inspect.utils; ...@@ -3,6 +3,7 @@ package com.zjty.inspect.utils;
import org.eclipse.jgit.api.CloneCommand; import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.File; import java.io.File;
...@@ -16,7 +17,7 @@ import java.time.LocalDate; ...@@ -16,7 +17,7 @@ import java.time.LocalDate;
@Component @Component
public class GitLabUtil { public class GitLabUtil {
public static String downLoadProject(String path) { public static String downLoadProject(String path,String username,String password) {
String name1 = LocalDate.now().toString(); String name1 = LocalDate.now().toString();
String[] split1 = UUIDUtil.getUUID().split("-"); String[] split1 = UUIDUtil.getUUID().split("-");
//String REMOTE_URL = "https://git.yfzx.zjtys.com.cn:8888/912-system/monitor/adaptation-master.git"; //String REMOTE_URL = "https://git.yfzx.zjtys.com.cn:8888/912-system/monitor/adaptation-master.git";
...@@ -25,7 +26,9 @@ public class GitLabUtil { ...@@ -25,7 +26,9 @@ public class GitLabUtil {
File file = new File("./"+name1+"/"+split1[0]+"/"); File file = new File("./"+name1+"/"+split1[0]+"/");
file.mkdirs(); file.mkdirs();
cloneCommand.setDirectory(file); cloneCommand.setDirectory(file);
cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username,password));
try { try {
cloneCommand.call(); cloneCommand.call();
} catch (GitAPIException e) { } catch (GitAPIException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -38,11 +41,6 @@ public class GitLabUtil { ...@@ -38,11 +41,6 @@ public class GitLabUtil {
return file.getAbsolutePath(); return file.getAbsolutePath();
} }
public static void main(String[] args) {
String hostsss = GitLabUtil.downLoadProject("https://git.yfzx.zjtys.com.cn/912-system/monitor/inspect.git");
System.out.println(hostsss);
}
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论