提交 04643af2 authored 作者: 马晨俊's avatar 马晨俊

mcj:更新git上传接口

上级 809d6dae
......@@ -11,6 +11,7 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.tomcat.util.http.fileupload.disk.DiskFileItem;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpEntity;
......@@ -370,7 +371,7 @@ public class InspectController {
}
}
@PostMapping("/gitdownload")
private ResponseEntity gitDownloads(String gitAddress,String username,String password){
private ResponseEntity gitDownloads(String gitAddress,String username,String password) throws IOException, GitAPIException {
String gitPath = GitLabUtil.downLoadProject(gitAddress,username,password);
return ResponseEntity.ok(gitPath);
}
......
......@@ -17,28 +17,18 @@ import java.time.LocalDate;
@Component
public class GitLabUtil {
public static String downLoadProject(String path,String username,String password) {
public static String downLoadProject(String path, String username, String password) throws IOException, GitAPIException {
String name1 = LocalDate.now().toString();
String[] split1 = UUIDUtil.getUUID().split("-");
//String REMOTE_URL = "https://git.yfzx.zjtys.com.cn:8888/912-system/monitor/adaptation-master.git";
CloneCommand cloneCommand = Git.cloneRepository();
cloneCommand.setURI(path);
File file = new File("./"+name1+"/"+split1[0]+"/");
File file = new File("./" + name1 + "/" + split1[0] + "/");
file.mkdirs();
cloneCommand.setDirectory(file);
cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username,password));
try {
cloneCommand.call();
} catch (GitAPIException e) {
e.printStackTrace();
}
try {
return file.getCanonicalPath();
} catch (IOException e) {
e.printStackTrace();
}
return file.getAbsolutePath();
cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password));
cloneCommand.call();
return file.getCanonicalPath();
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论