Created
April 11, 2014 21:39
-
-
Save bainternet/10503752 to your computer and use it in GitHub Desktop.
create bitbucket issue php api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* Function submitBug - sends the bug to the bitbucket API. Must contain title and content. User name/email is optional.*/ | |
| function submitBug($title, $content, $user='Anonymous', $bbAccount, $bbRepo, $basicAuth, $component='', $status='new', $priority='major', $kind='bug'){ | |
| $url = 'https://api.bitbucket.org/1.0/repositories/'.$bbAccount.'/'.$bbRepo.'/issues/'; | |
| $ch = curl_init($url); | |
| if (get_magic_quotes_gpc()) { | |
| $title = stripslashes($title); | |
| $content = stripslashes($content); | |
| $user = stripslashes($user); | |
| $component = stripslashes($component); | |
| $bbAccount = stripslashes($bbAccount); | |
| $bbRepo = stripslashes($bbRepo); | |
| } | |
| $fields = array( | |
| 'title' => urlencode($title), | |
| 'content' => urlencode($content."\n\nSubmitted By: ".$user), | |
| 'status' => urlencode($status), | |
| 'priority' => urlencode($priority), | |
| 'kind' => urlencode($kind), | |
| 'component' => urlencode($component) | |
| ); | |
| // Build POST url: | |
| $fieldsStr = ''; | |
| foreach($fields as $key=>$value) { | |
| $fieldsStr .= $key.'='.$value.'&'; | |
| } | |
| rtrim($fieldsStr, '&'); | |
| curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic '.$basicAuth)); //YXZpbnVzOmJpdHBhc3MxOQ== | |
| curl_setopt($ch, CURLOPT_URL, $url); | |
| curl_setopt($ch, CURLOPT_POST, count($fields)); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsStr); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
| $response = curl_exec($ch); | |
| curl_close($ch); | |
| //print_r($response); // Debugging | |
| if( $response !== FALSE){ | |
| $response = json_decode($response); | |
| if(isset($response->local_id) && intval($response->local_id) > 0 ){ | |
| $bugurl = "https://bitbucket.org/".ltrim($response->resource_uri, "/1.0/repositories/"); | |
| $bugurl = str_replace('/issues/', '/issue/', $bugurl); | |
| return( array('issueid'=>$response->local_id, 'issueurl'=>$bugurl) ); | |
| }else{ | |
| return(FALSE); | |
| } | |
| }else{ | |
| return(FALSE); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment