PHP code example of namelesscoder / gizzle

1. Go to this page and download the library: Download namelesscoder/gizzle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

namelesscoder / gizzle example snippets


$data = file_get_contents('php://input');
$secret = 'mysecret';
$gizzle = new \NamelessCoder\Gizzle\Payload($data, $secret);

// Plugins are then loaded from the packages used in, and in the order of, file `settings/Settings.yml` (see below)
// * alternative loading 1: $gizzle->loadPlugins('MyVendor\\MyPackage');
// * alternative loading 2: $gizzle->loadPlugins($arrayOfPackageNames);
// * alternative loading 3: $gizzle->loadPlugins($package1, $package2, $package3);
// using either alternative causes the all plugins returned by the PluginList to be ran. Settings are still applied
// but not used for determining plugins to run and in which order, as it is when running a settings file.

/** @var \NamelessCoder\Gizzle\Response $response */
$response = $gizzle->process();

/** @var integer $code */
$code = $response->getCode();
// code >0 indicates errors are present; value indicates exact error. Code =0 means no errors.

/** @var \RuntimeException[] $errors */
$errors = $response->getErrors();

$settingsFile = 'Settings/SpecialSettings.yml';
$payload = new Payload($data = '{}', $secret = '', $settingsFile);

$api = $payload->getApi();
if (TRUE === empty($api->getToken()) {
	// avoid doing anything with the API when there is
	// no token loaded; UNLESS you are able to provide
	// your own token from inside the plugin code.
} else {
	$response = $api->get('/emoji');
	$emojis = $api->decode($response);
}

$message = new NamelessCoder\Gizzle\Message(
	'This is an inline message for a line in a file',
	'/path/to/file.txt',
	123
);
$message->setCommit($payload->getHead());
$payload->sendMessage($message);

$message = new NamelessCoder\Gizzle\Message(
	'This is a comment for the pull request itself'
);
$message->setPullRequest($payload->getPullRequest());
$payload->sendMessage($message);

foreach ($payload->getCommits() as $commit) {
	// Example loop. An implementation like this one would for example
	// pull information from $commit and validate the message or read
	// a list of files changed and run a code style check directly on
	// GitHub's "raw" hosted file or download the file and then check it.
	$message = new NamelessCoder\Gizzle\Message(
		'This is an inline review comment',
		'/path/to/file',
		123
	);
	$message->setPullRequest($payload->getPullRequest());
	$message->setCommit($commit);
	$payload->sendMessage($message);
}


namespace NamelessCoder\Gizzle\GizzlePlugins;

use NamelessCoder\Gizzle\PluginInterface;
use NamelessCoder\Gizzle\AbstractPlugin;


/**
 * Example Gizzle Plugin
 *
 * Sends an email to the person who pushed the commit,
 * but only if the commit was made to the "demo" branch.
 */
class ExamplePlugin extends AbstractPlugin implements PluginInterface {

	/**
	 * Returns TRUE to trigger this Plugin if branch
	 * is "demo", as determined by REF of Payload.
	 *
	 * @param Payload $payload
	 * @return boolean
	 */
	public function trigger(Payload $payload) {
		return 'refs/heads/demo' === $payload->getRef();
	}

	/**
	 * Send a thank you email to commit pusher.
	 *
	 * @param Payload $payload
	 * @return void
	 * @throws \RuntimeException
	 */
	public function process(Payload $payload) {
		$pusherEmail = $payload->getPusher()->getEmail();
		$body = 'A big thank you from ' . $payload->getRepository()->getOwner()->getName();
		$mailed = mail($pusherEmail, 'Thank you for contributing!', $body);
		if (FALSE === $mailed) {
			throw new \RuntimeException('Could not email the kind contributor at ' . $pusherEmail);
		}
	}

}
bash
echo "mysupersecretkey" > .secret

http://mydomain.foo/github-webhook.php?settings=Settings/SpecialSettings.yml

http://mydomain.foo/github-webhook.php?settings[]=Settings/SpecialSettings.yml&settings[]=Settings/OtherSettings.yml