Skip to content
This repository has been archived by the owner on Jul 30, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release-candidate' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Verkoeyen committed Jul 5, 2016
2 parents 7490f5c + bd3312e commit 55f1e8b
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.phutil_module_cache
6 changes: 6 additions & 0 deletions CHANGELOG.md
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.
90 changes: 89 additions & 1 deletion README.md
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.
3 changes: 3 additions & 0 deletions __phutil_library_init__.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

phutil_register_library('hook-conphig', __FILE__);
20 changes: 20 additions & 0 deletions __phutil_library_map__.php
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'
),
));
61 changes: 61 additions & 0 deletions src/HookConphig.php
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);
}

?>

0 comments on commit 55f1e8b

Please sign in to comment.