xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
<root> / inc / wh / http / slack.inc.php (3e2b77a6e38305f8feca7d3a25ec862bee5153af) (1,252B) (mode 100644) [raw]
<?php

function rg_wh_slack_validate_vars($rg, &$errmsg)
{
	return rg_wh_validate_json($rg, $errmsg);
}

function rg_wh_slack_send_pre(&$ev, $junk)
{
	// Enforce content type
	$ev['wh']['idata']['content_type'] = 'application/json';
}

function rg_wh_slack_cosmetic_pre(&$row, $junk)
{
	$row['url_is_sensitive'] = 1;
}

function rg_wh_slack_add_form_pre($db, &$rg)
{
	$a = $rg['wh']['idata'];

	if (!isset($rg['wh']['description']))
		$rg['wh']['description'] = 'Slack integration';

	$a['itype'] = 2;
	$a['itype_force'] = 1;
	$a['url_example'] = 'https://hooks.slack.com/services/ID1/ID2/ID3';

	if (!isset($a['events']))
		$a['events'] = 'P';

	if (!isset($a['custom_body']))
		$a['custom_body'] = '{' . "\n"
			. '"channel": "#rocketgit-##branch##",' . "\n"
			. '"username": "RocketGit robot (hook ##hook_id##)",' . "\n"
			. '"text": "Repo ##repo##, branch ##branch## pushed: <##commit_url##> (ip ##ip##)",' . "\n"
			. '"icon_emoji": ":ghost:"' . "\n"
			. '}';

	$rg['wh']['idata'] = $a;
}

$cb = array(
	'validate_vars' => 'rg_wh_slack_validate_vars',
	'cosmetic_pre' => 'rg_wh_slack_cosmetic_pre',
	'send_pre' => 'rg_wh_slack_send_pre',
	'add_form_pre' => 'rg_wh_slack_add_form_pre'
);

rg_wh_register_subtype('http', 'slack', 'Slack', $cb);

Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master