Last active
December 16, 2015 07:08
-
-
Save dregad/5396208 to your computer and use it in GitHub Desktop.
This page allows testing of the SourceGithub plugin by simulating the sending of a Github post_receive hook's payload
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 | |
# Testing for SourceGithub checkin process | |
$bin = get( 'bin', '' ); | |
$req = get( 'req', '' ); | |
$api = 'http://requestb.in/api/v1/bins'; | |
$tpl_list = "$api/%s/requests"; | |
$tpl_reqs = "$api/%s/requests/%s"; | |
function get( $p_var, $p_default = '' ) { | |
if( isset( $_POST[$p_var] ) ) { | |
return $_POST[$p_var]; | |
} else { | |
return $p_default; | |
} | |
} | |
function get_url( $p_url ) { | |
$t_curl = curl_init( $p_url ); | |
curl_setopt( $t_curl, CURLOPT_RETURNTRANSFER, true ); | |
#curl_setopt( $t_curl, CURLOPT_PROXY, 'http://xxx@proxy:8080/' ); | |
$t_data = curl_exec( $t_curl ); | |
if( $t_data === false ){ | |
die( curl_error( $t_curl ) ); | |
} elseif( preg_match( '/Access Denied/', $t_data ) ) { | |
die( 'Could not retrieve Request URL with CURL: Access Denied' ); | |
} | |
curl_close( $t_curl ); | |
return $t_data; | |
} | |
?> | |
<title>MantisBT Source Integration Plugin - SourceGithub Testing</title> | |
<p> | |
This page allows testing of the SourceGithub plugin by simulating the | |
sending of a Github post_receive hook's payload. | |
</p> | |
<p> | |
See <a href="https://github.com/dregad/source-integration/wiki/SourceGithub-Plugin-Tests"> | |
this wiki page</a> for further info on setup and usage instructions. | |
</p> | |
<hr /> | |
<form method="post"> | |
<label> | |
<a href="http://requestb.in/">Request bin</a> ID | |
*<input name="bin" value="<?php echo $bin ?>" /> | |
</label> | |
<label> | |
Request ID | |
<input name="req" value="<?php echo $req ?>" /> | |
</label> | |
<br /> | |
<p>* The Bin ID is mandatory; | |
if no Request ID is provided, a list of available id's will be returned. | |
</p> | |
<input type="submit" value="Get payload" /> | |
</form> | |
<br /> | |
<?php | |
if( empty( $bin ) ) { | |
echo "Please specify Request Bin ID"; | |
} | |
else if( empty( $req ) ) { | |
# No request specified, get the list from RequestBin | |
$url = sprintf( $tpl_list, $bin ); | |
echo "Retrieving list of requests from $url ...<p />"; | |
$requests = json_decode( utf8_encode( get_url( $url ) ) ); | |
date_default_timezone_set ( 'UTC' ); | |
echo '<table border="1" cellspacing="0">'; | |
echo "<tr><td><b>Request ID</b></td><td><b>Time (UTC)</b></td><td><b>After SHA</b></td></tr>"; | |
foreach( $requests as $req ) { | |
if( is_null( $req->content_type ) ) { | |
continue; | |
} | |
$sha = json_decode($req->form_data[0][1])->after; | |
echo "<tr> | |
<td>$req->id</td> | |
<td>". date('Y-m-d H:i:s', $req->time) . "</td> | |
<td>$sha</td> | |
</tr>"; | |
} | |
echo '</table>'; | |
} else { | |
# Get the request's details | |
$url = sprintf( $tpl_reqs, $bin, $req ); | |
echo "<p>Retrieving request payload from $url ...</p>"; | |
$payload = json_decode( utf8_encode( get_url( $url ) ) ); | |
if( array_key_exists( 'error', $payload ) ) { | |
echo "<p><b>Error: $payload->error</b></p>"; | |
die; | |
} | |
$payload = $payload->form_data[0][1]; | |
if( !empty( $payload ) ) { | |
echo "After SHA: " . json_decode( $payload )->after. "<br />"; | |
?> | |
<form method="post" action="plugin.php?page=Source/checkin"> | |
<textarea name="payload" cols="120" rows="10"><?php echo htmlspecialchars( $payload ) ?></textarea><br /> | |
<label>API key: <input name="api_key" value="" /><br /></label> | |
<p> | |
Clicking Submit will call the Source Integration plugin's <em>checkin.php</em> | |
page with the above payload. | |
</p> | |
<input type="submit" /> | |
</form> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment