我接近让它工作,但每次我尝试创建一个树时,我都会收到服务器错误。有任何想法吗?这是我的PHP代码:
function send_data($url, $content) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERPWD, 'myuser:mypass');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($content));
$a = array();
$a['d'] = curl_exec($ch);
$a['i'] = curl_getinfo($ch);
curl_close($ch);
return $a;
}
$treeArr = array(
"base_tree" => "d7126bd6c559ab461e851e96ef2c33675d851c5e",
"tree" => array(
"path" => "resources/blahTest.txt",
"mode" => "100644",
"type" => "blob",
"sha" => "38d15319d3ee8a7292be0ec0da65fe111660a94d"
)
);
$x = send_data("https://api.github.com/repos/srolfe26/Branch-IDE/git/trees",$treeArr);
print_r($x);
我为blob提供的sha是一个新创建的blob,我使用相同的send_data函数。 base_tree sha是在基本提交之后找到的树。另外,我在这里关注这个例子:http://www.pqpq.de/2011/07/pithub-how-to-commit-new-file-via.html
谢谢!
答案 0 :(得分:0)
请求数据中的“树”项需要是项目数组而不是单个项目,因为树是项目的集合。
$treeArr = array(
"base_tree" => "d7126bd6c559ab461e851e96ef2c33675d851c5e",
"tree" => array(
array(
"path" => "resources/blahTest.txt",
"mode" => "100644",
"type" => "blob",
"sha" => "38d15319d3ee8a7292be0ec0da65fe111660a94d"
)
)
);