mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 06:42:42 +01:00
618b5cbbc4
Summary: Ref T4189. T4189 describes most of the intent here: - When updating hosted repositories, sync a pre-commit hook into them instead of doing a `git fetch`. - The hook calls into Phabricator. The acting Phabricator user is sent via PHABRICATOR_USER in the environment. The active repository is sent via CLI. - The hook doesn't do anything useful yet; it just veifies basic parameters, does a little parsing, and exits 0 to allow the commit. Test Plan: - Performed Git pushes and pulls over SSH and HTTP. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4189 Differential Revision: https://secure.phabricator.com/D7682
56 lines
1.4 KiB
PHP
Executable file
56 lines
1.4 KiB
PHP
Executable file
#!/usr/bin/env php
|
|
<?php
|
|
|
|
$root = dirname(dirname(dirname(__FILE__)));
|
|
require_once $root.'/scripts/__init_script__.php';
|
|
|
|
$username = getenv('PHABRICATOR_USER');
|
|
if (!$username) {
|
|
throw new Exception(pht('usage: define PHABRICATOR_USER in environment'));
|
|
}
|
|
|
|
$user = id(new PhabricatorPeopleQuery())
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
->withUsernames(array($username))
|
|
->executeOne();
|
|
if (!$user) {
|
|
throw new Exception(pht('No such user "%s"!', $username));
|
|
}
|
|
|
|
if ($argc < 2) {
|
|
throw new Exception(pht('usage: commit-hook <callsign>'));
|
|
}
|
|
|
|
$repository = id(new PhabricatorRepositoryQuery())
|
|
->setViewer($user)
|
|
->withCallsigns(array($argv[1]))
|
|
->requireCapabilities(
|
|
array(
|
|
// This capability check is redundant, but can't hurt.
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
DiffusionCapabilityPush::CAPABILITY,
|
|
))
|
|
->executeOne();
|
|
|
|
if (!$repository) {
|
|
throw new Exception(pht('No such repository "%s"!', $callsign));
|
|
}
|
|
|
|
if (!$repository->isHosted()) {
|
|
// This should be redundant too, but double check just in case.
|
|
throw new Exception(pht('Repository "%s" is not hosted!', $callsign));
|
|
}
|
|
|
|
$stdin = @file_get_contents('php://stdin');
|
|
if ($stdin === false) {
|
|
throw new Exception(pht('Failed to read stdin!'));
|
|
}
|
|
|
|
$engine = id(new DiffusionCommitHookEngine())
|
|
->setViewer($user)
|
|
->setRepository($repository)
|
|
->setStdin($stdin);
|
|
|
|
$err = $engine->execute();
|
|
|
|
exit($err);
|