我接近让这个工作,但每次我尝试创建一棵树时,我都会收到服务器错误。有任何想法吗?这是我的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 是我使用相同的 send_data 函数创建的新创建的 blob。base_tree sha 是从基本提交中找到的树。另外,我在这里关注这个例子:http ://www.pqpq.de/2011/07/pithub-how-to-commit-new-file-via.html
谢谢!