Search in sources :

Example 1 with ApplicationVcsInfoVO

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;
    }
}
Also used : Gits(com.orion.vcs.git.Gits) EventKeys(com.orion.ops.consts.event.EventKeys) LogInfo(com.orion.vcs.git.info.LogInfo) Exceptions(com.orion.utils.Exceptions) java.util(java.util) ApplicationVcsCommitVO(com.orion.ops.entity.vo.ApplicationVcsCommitVO) ValueMix(com.orion.ops.utils.ValueMix) ApplicationVcsRequest(com.orion.ops.entity.request.ApplicationVcsRequest) ApplicationInfoDAO(com.orion.ops.dao.ApplicationInfoDAO) MessageConst(com.orion.ops.consts.MessageConst) ApplicationVcsBranchVO(com.orion.ops.entity.vo.ApplicationVcsBranchVO) EventParamsHolder(com.orion.ops.consts.event.EventParamsHolder) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) ApplicationVcsDAO(com.orion.ops.dao.ApplicationVcsDAO) VcsStatus(com.orion.ops.consts.app.VcsStatus) ApplicationBuildDAO(com.orion.ops.dao.ApplicationBuildDAO) ApplicationVcsInfoVO(com.orion.ops.entity.vo.ApplicationVcsInfoVO) Streams(com.orion.utils.io.Streams) Service(org.springframework.stereotype.Service) Arrays1(com.orion.utils.Arrays1) VcsAuthType(com.orion.ops.consts.app.VcsAuthType) Utils(com.orion.ops.utils.Utils) Const(com.orion.ops.consts.Const) DataGrid(com.orion.lang.wrapper.DataGrid) ApplicationVcsDO(com.orion.ops.entity.domain.ApplicationVcsDO) ApplicationVcsVO(com.orion.ops.entity.vo.ApplicationVcsVO) Resource(javax.annotation.Resource) BranchInfo(com.orion.vcs.git.info.BranchInfo) Valid(com.orion.ops.utils.Valid) File(java.io.File) Files1(com.orion.utils.io.Files1) DataQuery(com.orion.ops.utils.DataQuery) Converts(com.orion.utils.convert.Converts) Slf4j(lombok.extern.slf4j.Slf4j) VcsTokenType(com.orion.ops.consts.app.VcsTokenType) SystemEnvAttr(com.orion.ops.consts.system.SystemEnvAttr) ApplicationVcsService(com.orion.ops.service.api.ApplicationVcsService) VcsType(com.orion.ops.consts.app.VcsType) Strings(com.orion.utils.Strings) Gits(com.orion.vcs.git.Gits) Transactional(org.springframework.transaction.annotation.Transactional) ApplicationVcsBranchVO(com.orion.ops.entity.vo.ApplicationVcsBranchVO) LogInfo(com.orion.vcs.git.info.LogInfo) ApplicationVcsInfoVO(com.orion.ops.entity.vo.ApplicationVcsInfoVO) ApplicationVcsCommitVO(com.orion.ops.entity.vo.ApplicationVcsCommitVO)

Aggregations

LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 DataGrid (com.orion.lang.wrapper.DataGrid)1 Const (com.orion.ops.consts.Const)1 MessageConst (com.orion.ops.consts.MessageConst)1 VcsAuthType (com.orion.ops.consts.app.VcsAuthType)1 VcsStatus (com.orion.ops.consts.app.VcsStatus)1 VcsTokenType (com.orion.ops.consts.app.VcsTokenType)1 VcsType (com.orion.ops.consts.app.VcsType)1 EventKeys (com.orion.ops.consts.event.EventKeys)1 EventParamsHolder (com.orion.ops.consts.event.EventParamsHolder)1 SystemEnvAttr (com.orion.ops.consts.system.SystemEnvAttr)1 ApplicationBuildDAO (com.orion.ops.dao.ApplicationBuildDAO)1 ApplicationInfoDAO (com.orion.ops.dao.ApplicationInfoDAO)1 ApplicationVcsDAO (com.orion.ops.dao.ApplicationVcsDAO)1 ApplicationVcsDO (com.orion.ops.entity.domain.ApplicationVcsDO)1 ApplicationVcsRequest (com.orion.ops.entity.request.ApplicationVcsRequest)1 ApplicationVcsBranchVO (com.orion.ops.entity.vo.ApplicationVcsBranchVO)1 ApplicationVcsCommitVO (com.orion.ops.entity.vo.ApplicationVcsCommitVO)1 ApplicationVcsInfoVO (com.orion.ops.entity.vo.ApplicationVcsInfoVO)1 ApplicationVcsVO (com.orion.ops.entity.vo.ApplicationVcsVO)1