每个GitHub API每次提交都不能传递多个文件?

时间:2015-11-04 22:54:53

标签: java git api github

我已经使用GitHub API进行自动提交 为此,我使用了Java Library from Kohsuke 它适用于此API command

Create a file
This method creates a new file in a repository
PUT /repos/:owner/:repo/contents/:path

但是,是否可以在1个GitHub API提交中包含多个文件?

2 个答案:

答案 0 :(得分:1)

不确定这是否是您想要的,也许更多的描述会有所帮助,但请看一下: https://developer.github.com/v3/git/

答案 1 :(得分:0)

以下代码段可让您准备包含多个文件的提交,然后使用Java library from Kohsuke

将新分支与之关联
// start with a Repository ref
GHRepository repo = ...

// get a sha to represent the root branch to start your commit from.  
// this can come from any number of classes:
//   GHBranch, GHCommit, GHTree, etc...

// for this example, we'll start from the master branch
GHBranch masterBranch = repo.getBranch("master");

// get a tree builder object to build up into the commit. 
// the base of the tree will be the master branch
GHTreeBuilder treeBuilder = repo.createTree().baseTree(masterBranch.getSHA1());

// add entries to the tree in various ways.  
// the nice thing about GHTreeBuilder.textEntry() is that it is an "upsert" (create new or update existing)
treeBuilder = treeBuilder.textEntry(pathToFile, contentOfFile, executable);

// repeat calls of treeBuider.textEntry() or .shaEntry() or .entry() ....

// perform the commit
GHCommit commit = repo.createCommit()
  // base the commit on the tree we built
  .tree(treeBuilder.create().getSha())
  // set the parent of the commit as the master branch
  .parent(masterBranch.getSHA1()).message("multi-file commit").create();

// create a new branch from that commit
String newBranchName = "myNewBranchName";
GHRef newRef = repo.createRef("/refs/heads/" + newBranchName, commit.getSHA1();
GHBranch newBranch = repo.getBranch(newBranchName);