Gitea 自动合并代码Java 实现

先pom文件中集成gitea jar包

<dependency>
  <groupId>com.github.zeripath</groupId>
  <artifactId>java-gitea-api</artifactId>
  <version>1.18.0</version>
</dependency>

具体Api 查看地址 https://github.com/zeripath/java-gitea-api

下面贴出demo

@Test
    public void giteaConfig() {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        defaultClient.setBasePath("http://localhost:9211/api/v1");
//        defaultClient.setAccessToken("f59246b894af6733a71102da35b07d547c96f4d4");
        ((ApiKeyAuth)defaultClient.getAuthentication("AccessToken")).setApiKey("f921e3be1da9c5578492df4d22f4577ddfb6a2ab");

        RepositoryApi apiInstance = new RepositoryApi();
        apiInstance.setApiClient(defaultClient);
        String owner = "root"; // String | owner of the repo
        String repo = "xxx"; // String | name of the repo
        CreatePullRequestOption body = new CreatePullRequestOption(); // CreatePullRequestOption |
        try {
            // 从 head 合并至 base
            
            body.setHead("xxxx");
            body.setBase("development");
            
//            OffsetDateTime time = OffsetDateTime.now();
//            time.plusMinutes(1l);
//            body.setDueDate(time);
            
            body.setTitle("devops auto merge");
            body.setBody("merge by xxx");
            //创建合并请求
            PullRequest result = apiInstance.repoCreatePullRequest(owner, repo, body);
            
            Long index = result.getNumber();
            
            MergePullRequestOption mBody = new MergePullRequestOption();
            mBody._do(DoEnum.MERGE);
            mBody.setForceMerge(true);
            mBody.setDeleteBranchAfterMerge(false);
            //执行合并请求
            apiInstance.repoMergePullRequest(owner, repo, index, mBody);
            
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling RepositoryApi#repoCreatePullRequest");
            e.printStackTrace();
        }
    }


版权声明:本文为u013248350原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。