从PHP cURL在Bitbucket上创建新的repo

时间:2015-05-21 07:51:20

标签: php laravel curl bitbucket

使用PHP cURL创建一个bitbucket存储库..

Bitbucket doc:https://confluence.atlassian.com/display/BITBUCKET/repository+Resource

POST https://api.bitbucket.org/2.0/repositories/{owner}/{repo_slug} 

$ curl -X POST -v -u username:password -H "Content-Type: application/json" \
https://api.bitbucket.org/2.0/repositories/teamsinspace/new-repository4 \
-d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks" }' 

这是我的代码:

    $fields = [
        'scm'           => 'git',
        'is_private'    => 'true',
        'fork_policy'   => 'no_public_forks'
    ];

    $url= "https://api.bitbucket.org/2.0/repositories/MYUSERNAME/NEWREPO";

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERPWD, 'MYUSERNAME:MYPASS');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json'                                                                                                                                                 
    ));
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

    $result = curl_exec($ch);
    $info = curl_getinfo($ch);

    curl_close($ch);

    //var_dump($info);
    dd($result);

适合我;)

0 个答案:

没有答案