Browse Source

优化新建分支

dev-DXTZYK
chenzhihang 1 year ago
parent
commit
0450c74392
3 changed files with 38 additions and 5 deletions
  1. +11
    -4
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java
  2. +3
    -1
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java
  3. +24
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/FileUtil.java

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

@@ -596,7 +596,7 @@ public class ModelsServiceImpl implements ModelsService {
String rootPath = localPath + ci4sUsername + "/model/" + gitlinIid + "/" + repositoryName;
String modelPath = rootPath + "/model";
String metaPath = rootPath + "/metadata";
String relatePath = ci4sUsername + "/model/" + gitlinIid + "/" + repositoryName+ "/model";
String relatePath = ci4sUsername + "/model/" + gitlinIid + "/" + repositoryName + "/model";

dvcUtils.gitClone(rootPath, projectUrl, branchName, gitLinkUsername, gitLinkPassword);
dvcUtils.moveFiles(sourcePath, modelPath);
@@ -673,6 +673,10 @@ public class ModelsServiceImpl implements ModelsService {
String gitLinkUsername = loginUser.getSysUser().getGitLinkUsername();
String gitLinkPassword = loginUser.getSysUser().getGitLinkPassword();

// String ci4sUsername = "admin";
// String gitLinkUsername = "fanshuai";
// String gitLinkPassword = "h1n2x3j4y5@";

Map<String, Object> userInfo = getUserInfo(ci4sUsername, gitLinkUsername, gitLinkPassword);

String repositoryName = modelsVo.getIdentifier() == null ? ci4sUsername + "_model_" + DateUtils.dateTimeNow() : modelsVo.getIdentifier();
@@ -688,7 +692,6 @@ public class ModelsServiceImpl implements ModelsService {
String owner = (String) userInfo.get("login");

String projectUrl = gitendpoint + "/" + owner + "/" + repositoryName + ".git";
String sourcePath = modelsVo.getModelVersionVos().get(0).getUrl();
String rootPath = localPath + ci4sUsername + "/model/" + modelsVo.getId() + "/" + repositoryName;
String modelPath = rootPath + "/model";
String metaPath = rootPath + "/metadata";
@@ -702,7 +705,11 @@ public class ModelsServiceImpl implements ModelsService {
dvcUtils.createLocalBranchBasedOnMaster(rootPath, branchName);
//dvc checkout
dvcUtils.dvcCheckout(rootPath);
dvcUtils.moveFiles(sourcePath, modelPath);

if (modelsVo.getModelVersionVos().size() != 0) {
String sourcePath = modelsVo.getModelVersionVos().get(0).getUrl();
dvcUtils.moveFiles(sourcePath, modelPath);
}

//拼接生产的元数据后写入yaml文件
ModelMetaVo modelMetaVo = new ModelMetaVo();
@@ -772,7 +779,7 @@ public class ModelsServiceImpl implements ModelsService {
// 构建objectName
String username = SecurityUtils.getLoginUser().getUsername();
String fileName = file.getOriginalFilename();
String path = localPath + "/temp/" + username + "/models/" + uuid;
String path = localPath + "temp/" + username + "/models/" + uuid;
long sizeInBytes = file.getSize();
String formattedSize = FileUtil.formatFileSize(sizeInBytes);
File targetFile = new File(path, file.getOriginalFilename());


+ 3
- 1
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java View File

@@ -73,6 +73,8 @@ public class DVCUtils {

if (!Files.exists(targetDir)) {
Files.createDirectories(targetDir);
} else {
FileUtil.deleteDir(targetPath);
}

Files.move(sourceDir, targetDir, StandardCopyOption.REPLACE_EXISTING);
@@ -585,6 +587,6 @@ public class DVCUtils {
} catch (Exception e) {
log.error("Error occurred while getting file details after git pull", e);
}
return null;
return new ArrayList<>();
}
}

+ 24
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/FileUtil.java View File

@@ -101,4 +101,28 @@ public class FileUtil {
}
return fileInfoList;
}


public static boolean deleteDir(String path){
File file = new File(path);
if(!file.exists()){//判断是否待删除目录是否存在
System.err.println("文件夹不存在");
return false;
}

String[] content = file.list();//取得当前目录下所有文件和文件夹
for(String name : content){
File temp = new File(path, name);
if(temp.isDirectory()){//判断是否是目录
deleteDir(temp.getAbsolutePath());//递归调用,删除目录里的内容
temp.delete();//删除空目录
}else{
if(!temp.delete()){//直接删除文件
System.err.println(name+":删除失败!");
}
}
}
return true;
}

}

Loading…
Cancel
Save