通过Gitlab Open api代码来操作代码的合并及关闭,项目的模板生成........

方式一:

 使用java-gitlab-api(推荐)
接口文档Java Gitlab API Documentation

        <dependency>
            <groupId>org.gitlab</groupId>
            <artifactId>java-gitlab-api</artifactId>
            <version>4.1.1</version>
        </dependency>
 

 方式二:

gitlab4j-api
文档地址https://github.com/gitlab4j/gitlab4j-api#tagsapi

         <dependency>
            <groupId>org.gitlab4j</groupId>
            <artifactId>gitlab4j-api</artifactId>
            <version>4.15.7</version>
        </dependency>
 

编写调用局部代码:

@PostConstruct
public void init(){
    gitlabAPI = GitlabAPI.connect(gitLabConfigProperties.getHostUrl(),gitLabConfigProperties.getAdminAccessToken());
}

【例】分支比较,传递时需要对调分支

 ....

GitlabCommitComparison compare = gitlabAPI.compareCommits(mergeApplyDTO.getGitlabProjectId(),mergeApplyDTO.getTargetBranch(),mergeApplyDTO.getSourceBranch());
Assert.isTrue(!CollectionUtils.isEmpty(compare.getDiffs()), "分支合并申请,分支没有变化!");

...

 

 引申

Merge requests API | GitLabDocumentation for GitLab Community Edition, GitLab Enterprise Edition, Omnibus GitLab, and GitLab Runner.https://docs.gitlab.com/13.12/ee/api/merge_requests.html#create-mr

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐