Search in sources :

Example 1 with LogInfo

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;
    }
}
Also used : Gits(com.orion.vcs.git.Gits) LogInfo(com.orion.vcs.git.info.LogInfo)

Example 2 with LogInfo

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;
    }
}
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)

Example 3 with LogInfo

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);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) LogInfo(com.orion.vcs.git.info.LogInfo) ObjectId(org.eclipse.jgit.lib.ObjectId) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

LogInfo (com.orion.vcs.git.info.LogInfo)3 Gits (com.orion.vcs.git.Gits)2 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