Skip to content

Commit

Permalink
Do a bit more of the verbose error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes committed Mar 21, 2012
1 parent 10ef84b commit 2b602e2
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions pulls/api.php
Expand Up @@ -52,21 +52,10 @@ function verify_password_DEV($user, $pass)
return $user === 'johannes';
}

function ghpostcomment($pull, $comment)
function do_http_request($url, $ctxt)
{
global $errors;

$post = json_encode(array("body" => "**Comment on behalf of $_SESSION[user] at php.net:**\n\n$comment"));


$opts = array(
'method' => 'POST',
'content' => $post,
);

$ctx = stream_context_create(array('http' => $opts));

$url = str_replace('https://', 'https://'.GITHUB_USER.':'.GITHUB_PASS.'@', $pull->_links->comments->href);
$old_track_errors = ini_get('track_errors');
ini_set('track_errors', true);
$s = @file_get_contents($url, false, $ctx);
Expand All @@ -76,12 +65,32 @@ function ghpostcomment($pull, $comment)
$errors[] = "Server responded: ".$http_response_header[0];
$errors[] = "Github user: ".GITHUB_USER;
if ($_SESSION['user'] === 'johannes') {
/* This might include the password or such, so not everybody should get it */
/* This might include the password or such, so not everybody should get it
The good news is that the HTTP Status code usually is a good enough hint
*/
$errors[] = $php_errormsg;
}
return false;
}
return true;
return $s;
}

function ghpostcomment($pull, $comment)
{
global $errors;

$post = json_encode(array("body" => "**Comment on behalf of $_SESSION[user] at php.net:**\n\n$comment"));


$opts = array(
'method' => 'POST',
'content' => $post,
);

$ctx = stream_context_create(array('http' => $opts));

$url = str_replace('https://', 'https://'.GITHUB_USER.':'.GITHUB_PASS.'@', $pull->_links->comments->href);
return (bool)do_http_request($url, $ctx);
}

function ghchangestate($pull, $state)
Expand All @@ -96,8 +105,7 @@ function ghchangestate($pull, $state)
$ctx = stream_context_create(array('http' => $opts));

$url = str_replace('https://', 'https://'.GITHUB_USER.':'.GITHUB_PASS.'@', $pull->_links->self->href);
$s = @file_get_contents($url, false, $ctx);
return (bool)$s;
return (bool)do_http_request($url, $ctx);
}

function login()
Expand Down

0 comments on commit 2b602e2

Please sign in to comment.