You could probably find a way to automate this via the System Hooks API. Listen for the project_create
hook event, then make a call to the project hook endpoint to add the one you want.
It's webhooks all the way down!
Question
I have GitLab setup on a server. Every time I create a new project under my user, I have to manually add a Web Hook by navigating to Project -> Settings -> Web Hooks -> Add Web Hook
Since many users will be creating projects on the hosted GitLab it will be difficult to setup Web Hooks for each project individually.
Is there a way, so that when a new project is created, it automatically (as default) sets up a Web Hook as part of the new project?
Any help is much appreciated.
Solution
You could probably find a way to automate this via the System Hooks API. Listen for the project_create
hook event, then make a call to the project hook endpoint to add the one you want.
It's webhooks all the way down!
OTHER TIPS
I found this script what do all you need:
recive the hook and execute the query insert of web hook
Run with php -S 0.0.0.0:8080
<?php
$allowed_host = "ip_of_your_gitlab_server";
$sql_host = "localhost_or_ip_of_your_mysql_server";
$sql_user = "..";
$sql_password = "..";
$database = "gitlabhq_production";
if ($_SERVER['REMOTE_ADDR'] == $allowed_host) { // ofc you could increase security with some kind of API key or w/e
$sql = mysqli_connect($sql_host, $sql_user, $sql_password, $database);
if (mysqli_connect_errno()) {
exit;
}
$file = fopen("/tmp/sql_error", "a"); // you can use this as debug log too ;)
$input = json_decode(file_get_contents('php://input'), true);
$pid = $input['project_id'];
if ($input['event_name'] == "project_create") {
$url = 'url_of_your_project_hook';
// this creates a project hook, specify it for your needs..
$q = mysqli_query($sql, "INSERT INTO gitlabhq_production.web_hooks (url, project_id) VALUES('$url', '$pid')");
if (!$q) fwrite($file, $sql->error);
} elseif ($input['event_name'] == "project_destroy")
$q = mysqli_query($sql, "DELETE FROM gitlabhq_production.web_hooks WHERE project_id='$pid'");
mysqli_close($sql);
} else {
// redirect?
exit;
}