-1

我接近让这个工作,但每次我尝试创建一棵树时,我都会收到服务器错误。有任何想法吗?这是我的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

谢谢!

4

1 回答 1

0

请求数据中的“树”项目需要是项目数组而不是单个项目,因为树是项目的集合。

$treeArr = array(
    "base_tree" => "d7126bd6c559ab461e851e96ef2c33675d851c5e",
    "tree" => array(
        array(
            "path" => "resources/blahTest.txt",
            "mode" => "100644",
            "type" => "blob",
            "sha" => "38d15319d3ee8a7292be0ec0da65fe111660a94d"
        )
    )
);
于 2013-12-09T15:53:44.430 回答