|
4 | 4 | $root = dirname(dirname(dirname(__FILE__)));
|
5 | 5 | require_once $root.'/scripts/__init_script__.php';
|
6 | 6 |
|
7 |
| -$username = getenv('PHABRICATOR_USER'); |
8 |
| -if (!$username) { |
9 |
| - throw new Exception(pht('usage: define PHABRICATOR_USER in environment')); |
10 |
| -} |
11 |
| - |
12 |
| -$user = id(new PhabricatorPeopleQuery()) |
13 |
| - ->setViewer(PhabricatorUser::getOmnipotentUser()) |
14 |
| - ->withUsernames(array($username)) |
15 |
| - ->executeOne(); |
16 |
| -if (!$user) { |
17 |
| - throw new Exception(pht('No such user "%s"!', $username)); |
18 |
| -} |
19 |
| - |
20 | 7 | if ($argc < 2) {
|
21 | 8 | throw new Exception(pht('usage: commit-hook <callsign>'));
|
22 | 9 | }
|
23 | 10 |
|
| 11 | +$engine = new DiffusionCommitHookEngine(); |
| 12 | + |
24 | 13 | $repository = id(new PhabricatorRepositoryQuery())
|
25 |
| - ->setViewer($user) |
| 14 | + ->setViewer(PhabricatorUser::getOmnipotentUser()) |
26 | 15 | ->withCallsigns(array($argv[1]))
|
27 |
| - ->requireCapabilities( |
28 |
| - array( |
29 |
| - // This capability check is redundant, but can't hurt. |
30 |
| - PhabricatorPolicyCapability::CAN_VIEW, |
31 |
| - DiffusionCapabilityPush::CAPABILITY, |
32 |
| - )) |
33 | 16 | ->executeOne();
|
34 | 17 |
|
35 | 18 | if (!$repository) {
|
36 | 19 | throw new Exception(pht('No such repository "%s"!', $callsign));
|
37 | 20 | }
|
38 | 21 |
|
39 | 22 | if (!$repository->isHosted()) {
|
40 |
| - // This should be redundant too, but double check just in case. |
| 23 | + // This should be redundant, but double check just in case. |
41 | 24 | throw new Exception(pht('Repository "%s" is not hosted!', $callsign));
|
42 | 25 | }
|
43 | 26 |
|
| 27 | +$engine->setRepository($repository); |
| 28 | + |
| 29 | + |
| 30 | +// Figure out which user is writing the commit. |
| 31 | + |
| 32 | +if ($repository->isGit()) { |
| 33 | + $username = getenv('PHABRICATOR_USER'); |
| 34 | + if (!strlen($username)) { |
| 35 | + throw new Exception(pht('usage: PHABRICATOR_USER should be defined!')); |
| 36 | + } |
| 37 | +} else if ($repository->isSVN()) { |
| 38 | + // NOTE: In Subversion, the entire environment gets wiped so we can't read |
| 39 | + // PHABRICATOR_USER. Instead, we've set "--tunnel-user" to specify the |
| 40 | + // correct user; read this user out of the commit log. |
| 41 | + |
| 42 | + if ($argc < 4) { |
| 43 | + throw new Exception(pht('usage: commit-hook <callsign> <repo> <txn>')); |
| 44 | + } |
| 45 | + |
| 46 | + $svn_repo = $argv[2]; |
| 47 | + $svn_txn = $argv[3]; |
| 48 | + list($username) = execx('svnlook author -t %s %s', $svn_txn, $svn_repo); |
| 49 | + $username = rtrim($username, "\n"); |
| 50 | + |
| 51 | + $engine->setSubversionTransactionInfo($svn_txn, $svn_repo); |
| 52 | +} else { |
| 53 | + throw new Exceptiont(pht('Unknown repository type.')); |
| 54 | +} |
| 55 | + |
| 56 | +$user = id(new PhabricatorPeopleQuery()) |
| 57 | + ->setViewer(PhabricatorUser::getOmnipotentUser()) |
| 58 | + ->withUsernames(array($username)) |
| 59 | + ->executeOne(); |
| 60 | + |
| 61 | +if (!$user) { |
| 62 | + throw new Exception(pht('No such user "%s"!', $username)); |
| 63 | +} |
| 64 | + |
| 65 | +$engine->setViewer($user); |
| 66 | + |
| 67 | + |
| 68 | +// Read stdin for the hook engine. |
| 69 | + |
44 | 70 | $stdin = @file_get_contents('php://stdin');
|
45 | 71 | if ($stdin === false) {
|
46 | 72 | throw new Exception(pht('Failed to read stdin!'));
|
47 | 73 | }
|
48 | 74 |
|
49 |
| -$engine = id(new DiffusionCommitHookEngine()) |
50 |
| - ->setViewer($user) |
51 |
| - ->setRepository($repository) |
52 |
| - ->setStdin($stdin); |
| 75 | +$engine->setStdin($stdin); |
53 | 76 |
|
54 | 77 | $err = $engine->execute();
|
55 | 78 |
|
|
0 commit comments