fix(项目管理): 修复存储库文件更新时没有获取到最新commit的缺陷

--bug=1035308 --user=宋天阳 【用例管理】-用例关联文件,文件详情页关联用例列表中,用例关联的文件版本显示错误 https://www.tapd.cn/55049933/s/1460285
This commit is contained in:
song-tianyang 2024-02-04 18:55:24 +08:00 committed by 刘瑞斌
parent 370fc1661f
commit 2ad4ca9d0d
2 changed files with 9 additions and 6 deletions

View File

@ -140,11 +140,10 @@ public class GitRepositoryUtil {
private String getFileLastCommitId(ObjectId objectId, String filePath) throws Exception {
Iterable<RevCommit> logs = git.log().add(objectId).addPath(filePath).call();
String returnStr = StringUtils.EMPTY;
for (RevCommit rev : logs) {
returnStr = rev.getName();
return rev.getName();
}
return returnStr;
return null;
}
private RevCommit getRevTreeByRepositoryAndCommitId(InMemoryRepository repo, ObjectId fileCommitId) throws Exception {

View File

@ -532,13 +532,16 @@ public class FileMetadataService {
private void setFileVersionIsOld(FileMetadata oldFile, String operator) {
//删除旧的预览文件
TempFileUtils.deleteTmpFile(oldFile.getId());
//更新文件版本分支
//通过refId批量更新
FileMetadataExample example = new FileMetadataExample();
example.createCriteria().andRefIdEqualTo(oldFile.getRefId()).andLatestEqualTo(true);
FileMetadata updateModel = new FileMetadata();
updateModel.setId(oldFile.getId());
updateModel.setLatest(false);
updateModel.setUpdateTime(System.currentTimeMillis());
updateModel.setUpdateUser(operator);
fileMetadataMapper.updateByPrimaryKeySelective(updateModel);
fileMetadataMapper.updateByExampleSelective(updateModel, example);
}
private void genNewFileVersionByOldFile(FileMetadata oldFile, FileMetadata fileMetadata, String operator) {
@ -620,6 +623,7 @@ public class FileMetadataService {
//获取fileMetadata以及可能存在的fileMetadataRepository
FileMetadataExample example = new FileMetadataExample();
example.createCriteria().andRefIdEqualTo(fileMetadata.getRefId());
example.setOrderByClause(" create_time DESC ");
List<FileMetadata> fileMetadataList = fileMetadataMapper.selectByExample(example);
List<String> fileIdList = fileMetadataList.stream().map(FileMetadata::getId).toList();
FileMetadataRepositoryExample repositoryExample = new FileMetadataRepositoryExample();