Skip to content

Instantly share code, notes, and snippets.

@mikeselander
Created July 11, 2015 15:45
Show Gist options
  • Save mikeselander/06f9abc920bcdccf730a to your computer and use it in GitHub Desktop.
Save mikeselander/06f9abc920bcdccf730a to your computer and use it in GitHub Desktop.
Create Bitbucket repos en masse
$sites = array(
// Our site array
);
foreach ( $sites as $site ){
$data = array( "name" => $site, "scm" => "git", "is_private" => "true", "fork_policy" => "no_public_forks", "website" => $site );
$data_string = json_encode( $data );
$service_url = 'https://api.bitbucket.org/2.0/repositories/oldtownmedia/'.$data['name'];
$curl = curl_init( $service_url );
curl_setopt( $curl, CURLOPT_USERPWD, 'username:password' );
curl_setopt( $curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $data_string );
curl_setopt( $curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
//'Content-Length: ' . strlen( $data_string )
) );
$curl_response = curl_exec( $curl );
if ( $curl_response === false ) {
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additional info: ' . var_export($info));
}
curl_close( $curl );
$response = json_decode( $curl_response, true );
echo "<pre>";
echo $service_url."<br>";
echo $response."<br>";
print_r( $data );
echo "</pre>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment