如何使用Kohsuke github复制文件

时间:2019-05-24 22:02:04

标签: api file github add

我正在使用org.kohsuke.github。*;

  1. 我有一个示例存储库,其中有一个提交(sha),其中包含一堆用作模板的文件。
  2. 当我在应用程序上收到一个带有仓库名称xyz的请求时,我需要分叉仓库xyz,从#1抓取文件,将文件添加到分叉仓库中,然后将分叉仓库中的PR提交给原始仓库xyz。

通过kohsuke github可能吗?

通过kohsuke的文档

  public static GHRepository createFork(String repo) throws IOException{
        GHRepository mainRepo = github.getRepository(repo);
        GHRepository forkedRepo = mainRepo.fork();
        GHCommit commit = copyFiles();
        /*QUESTION: Here is where I need help. Now that I have the 
         commit that has the files I need how to I add them to 
        forkedRepo?******** */
        GHCommitBuilder builder = forkedRepo.createCommit();
        return forkedRepo;
    }

    public static GHCommit copyFiles() throws IOException {
        GHRepository mainRepo = github.getRepository("sandbox/xyz");
        /* xxxxxxxxx is the sha of commit that has templated files.        
        GHCommit commit = mainRepo.getCommit("xxxxxxxxxxx"); 

        GHContent content = new GHContent();
        return commit;
    }

0 个答案:

没有答案