This repository has been archived by the owner on Jul 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release-candidate' into stable
- Loading branch information
Showing
6 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.phutil_module_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# 1.0.0 | ||
|
||
- Initial release. | ||
- Supports post-workflow commands. | ||
|
||
Only post-diff has been tested. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,89 @@ | ||
# Arcanist Hook Configuration | ||
# arc-hook-conphig | ||
|
||
arc-hook-conphig is a hookable configuration engine for use with | ||
[Phabricator](http://phabricator.org)'s `arc` command line tool. | ||
|
||
## Features | ||
|
||
Create hooks to customize your workflows. | ||
|
||
## Supported hooks | ||
|
||
The following hooks have been tested thus far: | ||
|
||
- post-`arc diff` | ||
|
||
## Installation | ||
|
||
### Project-specific | ||
|
||
Add this repository as a git submodule. | ||
|
||
git submodule init | ||
git submodule add <url for this repo> | ||
|
||
Your `.arcconfig` should list `arc-hook-conphig` in the `load` configuration: | ||
|
||
{ | ||
"load": [ | ||
"path/to/arc-hook-conphig" | ||
] | ||
} | ||
|
||
### Global | ||
|
||
Clone this repository to the same directory where `arcanist` and | ||
`libphutil` are globally located. Your directory structure will | ||
look like so: | ||
|
||
arcanist/ | ||
libphutil/ | ||
arc-hook-conphig/ | ||
|
||
Your `.arcconfig` should list `arc-hook-conphig` in the `load` | ||
configuration (without a path): | ||
|
||
{ | ||
"load": [ | ||
"arc-hook-conphig" | ||
] | ||
} | ||
|
||
## Usage | ||
|
||
Create a `.arc-hooks` directory in the root of your project. This directory will contain all of your | ||
hooks. | ||
|
||
Hooks go in sub-directories, organized by type of workflow. For example, `.arc-hooks/post-diff/` | ||
hooks will be executed after the `arc diff` operation has completed. | ||
|
||
mkdir -p .arc-hooks/post-diff/ | ||
|
||
To create a hook, create a sub-directory for your hook. For example: | ||
`.arc-hooks/post-diff/github-issues`. This sub-directory should be structured like a typical arc | ||
library (use `arc liberate` to populate one). | ||
|
||
Here's one possible folder hierarchy: | ||
|
||
.arc-hooks/ | ||
post-diff/ | ||
github-issues/ | ||
src/ | ||
MyCustomArcanistHook.php | ||
__phutil_library_init__.php | ||
__phutil_library_map__.php | ||
|
||
Finally, load the hook in your `.arcconfig`: | ||
|
||
{ | ||
"load": [ | ||
".arc-hooks/post-diff/arc-hook-github-issues" | ||
] | ||
} | ||
|
||
Any classes located in the library's `src/` directory ending with 'ArcanistHook' will be loaded and | ||
executed. | ||
|
||
## License | ||
|
||
Licensed under the Apache 2.0 license. See LICENSE for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
phutil_register_library('hook-conphig', __FILE__); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* This file is automatically generated. Use 'arc liberate' to rebuild it. | ||
* | ||
* @generated | ||
* @phutil-library-version 2 | ||
*/ | ||
phutil_register_library_map(array( | ||
'__library_version__' => 2, | ||
'class' => array( | ||
'HookConphig' => 'src/HookConphig.php' | ||
), | ||
'function' => array( | ||
'endsWith' => 'src/HookConphig.php', | ||
), | ||
'xmap' => array( | ||
'HookConphig' => 'ArcanistConfiguration' | ||
), | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/* | ||
Copyright 2016-present The arc-hook-conphig Authors. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
# | ||
# Hookable arcanist configuration. | ||
# | ||
class HookConphig extends ArcanistConfiguration { | ||
|
||
const HOOK_DIR = '.arc-hooks'; | ||
|
||
# Post-workflow hooks | ||
public function didRunWorkflow($command, ArcanistWorkflow $workflow, $err) { | ||
if (!$err) { | ||
$workflowName = $workflow->getWorkflowName(); | ||
|
||
if (!$workflow->requiresRepositoryAPI()) { | ||
return; | ||
} | ||
|
||
$dir = $workflow->getRepositoryAPI()->getPath().self::HOOK_DIR."/post-$workflowName"; | ||
if (!file_exists($dir)) { | ||
return; | ||
} | ||
foreach (scandir($dir) as $path) { | ||
if (substr($path, 0, 1) == '.') { | ||
continue; | ||
} | ||
$subdir = "$dir/$path/src"; | ||
foreach (scandir($subdir) as $subpath) { | ||
if (endsWith($subpath, 'ArcanistHook.php')) { | ||
$class = substr($subpath, 0, strlen($subpath) - 4); | ||
if (class_exists($class)) { | ||
$hook = new $class(); | ||
$hook->doHook($workflow); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
function endsWith($haystack, $needle) { | ||
return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false); | ||
} | ||
|
||
?> |