use of com.orion.ops.entity.vo.ApplicationVcsInfoVO in project orion-ops by lijiahangmax.
the class ApplicationVcsServiceImpl method getVcsInfo.
@Override
public ApplicationVcsInfoVO getVcsInfo(ApplicationVcsRequest request) {
Long id = request.getId();
// 打开git
try (Gits gits = this.openEventGit(id)) {
gits.fetch();
ApplicationVcsInfoVO vcsInfo = new ApplicationVcsInfoVO();
ApplicationVcsBranchVO defaultBranch;
// 获取分支列表
List<ApplicationVcsBranchVO> branches = Converts.toList(gits.branchList(), ApplicationVcsBranchVO.class);
// 获取当前环境上次构建分支
String lastBranchName = applicationBuildDAO.selectLastBuildBranch(request.getAppId(), request.getProfileId(), id);
if (lastBranchName != null) {
defaultBranch = branches.stream().filter(s -> s.getName().equals(lastBranchName)).findFirst().orElseGet(() -> branches.get(branches.size() - 1));
} else {
defaultBranch = branches.get(branches.size() - 1);
}
defaultBranch.setIsDefault(Const.IS_DEFAULT);
vcsInfo.setBranches(branches);
// 获取commit
try {
List<LogInfo> logList = gits.logList(defaultBranch.getName(), Const.VCS_COMMIT_LIMIT);
vcsInfo.setCommits(Converts.toList(logList, ApplicationVcsCommitVO.class));
} catch (Exception e) {
log.error("获取vcs-commit列表失败: id: {}, branch: {}, e: {}", id, defaultBranch.getName(), e);
throw e;
}
return vcsInfo;
}
}
Aggregations