use of com.orion.vcs.git.info.LogInfo in project orion-ops by lijiahangmax.
the class ApplicationVcsServiceImpl method getVcsCommitList.
@Override
public List<ApplicationVcsCommitVO> getVcsCommitList(Long id, String branchName) {
// 打开git
try (Gits gits = this.openEventGit(id)) {
gits.fetch(branchName.split("/")[0]);
// 查询提交信息
List<LogInfo> logList = gits.logList(branchName, Const.VCS_COMMIT_LIMIT);
return Converts.toList(logList, ApplicationVcsCommitVO.class);
} catch (Exception e) {
log.error("获取vcs-commit列表失败: id: {}, branch: {}", id, branchName, e);
throw e;
}
}
use of com.orion.vcs.git.info.LogInfo 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;
}
}
use of com.orion.vcs.git.info.LogInfo in project orion-kit by lijiahangmax.
the class Gits method logList.
public List<LogInfo> logList(String branch, int count) {
try {
Repository repo = git.getRepository();
Ref b = git.branchList().setContains(branch).setListMode(ListBranchCommand.ListMode.ALL).call().get(0);
if (b == null) {
return new ArrayList<>();
}
ObjectId bid = repo.resolve(b.getName());
Iterable<RevCommit> commits = git.log().setMaxCount(count).add(bid).call();
List<LogInfo> logs = new ArrayList<>();
for (RevCommit commit : commits) {
LogInfo log = new LogInfo();
log.setId(commit.getId().name());
log.setEmail(commit.getCommitterIdent().getName());
log.setName(commit.getCommitterIdent().getName());
log.setTime(commit.getCommitTime());
log.setMessage(commit.getFullMessage());
logs.add(log);
}
return logs;
} catch (Exception e) {
throw Exceptions.vcs(e);
}
}
Aggregations