com web/qa: Do a bit more of the verbose error handling: pulls/api.php
| From: | Johannes Schlüter | Date: | Wed, 21 Mar 2012 00:18:18 +0000 |
| Subject: | com web/qa: Do a bit more of the verbose error handling: pulls/api.php | ||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66165@lists.php.net to get a copy of this message | ||
Commit: 2b602e20d9369617a3a324fd42530315729d740b
Author: Johannes Schlüter <johannes@php.net> Wed, 21 Mar 2012 01:18:18 +0100
Parents: 10ef84bdfeb9174f2dd5f8087882620a1ab9b5ad
Branches: master
Link: http://git.php.net/?p=web/qa.git;a=commitdiff;h=2b602e20d9369617a3a324fd42530315729d740b
Log:
Do a bit more of the verbose error handling
Changed paths:
M pulls/api.php
Diff:
2b602e20d9369617a3a324fd42530315729d740b
diff --git a/pulls/api.php b/pulls/api.php
index e55477d..9c1700a 100644
--- a/pulls/api.php
+++ b/pulls/api.php
@@ -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);
@@ -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)
@@ -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()