Skip to content

Commit

Permalink
Let the configuration file specify verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin VanEvery committed Jan 30, 2012
1 parent 0966ad3 commit ba21940
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ This hook checks the health of a jenkins job. See below for example configuratio
; Otherwise, use this config to override
job_name = 'the-build'

; Show progress as hook runs
verbose = yes

enabled = yes


Expand All @@ -84,6 +87,9 @@ for example configuration.
host = gerrit.internal-ip.company.com
port = 29418

; Show progress as hook runs
verbose = yes

enabled = yes


Expand Down
8 changes: 4 additions & 4 deletions hooks/pre-receive
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ declare BART_HOOKS="$(dirname $(readlink $0))"
# The main 'while' loop goes over each branch.
# The inner 'for' loop goes ever each commit on that branch
while true; do
read oldhead newhead branch
read oldhead newhead branch || exit 0

# Check if we're done looping thru every branch
if [ -z "$oldhead" -a -z "$newhead" -a -z "$branch" ]; then
Expand All @@ -26,8 +26,8 @@ while true; do

# Check if we have everything as expected
if [ -z "$oldhead" -o -z "$newhead" -o -z "$branch" ]; then
echo "Unexpected: One of the required parameters is empty"
echo "oldhead: $oldhead, newhead: $newhead, branch: $branch"
echo >&2 "Unexpected: One of the required parameters is empty"
echo >&2 "oldhead: $oldhead, newhead: $newhead, branch: $branch"

exit 1
fi
Expand All @@ -46,7 +46,7 @@ while true; do
--repo $REPO \
"$commit_hash"

if [ $? -ne 0 ]; then
if [[ $? -ne 0 ]]; then
echo >&2 "
Hooks failed."
exit 1
Expand Down
4 changes: 3 additions & 1 deletion hooks/pre-receive.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function show_usage($exit_status)
{
$hook = new Git_Hook_Pre_Receive($git_dir, $repo, $witness);
$hook->verify_all($hash);
$witness->report('All hooks passed');
}
catch(Exception $e)
{
Expand All @@ -71,4 +72,5 @@ function verify_param($name)

echo2(Escape_Colors::fg_color('red', 'Incorrect parameters: missing ' . $name));
show_usage(1);
}
}

5 changes: 4 additions & 1 deletion lib/Git_Hook/Pre_Receive.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ private function create_hook_for($hook_name)

if (!$conf['enabled']) return null;

return new $class($conf, $this->git_dir, $this->repo, $this->w, $this->di);
$w = ($conf['verbose']) ? new Witness() : $this->w;
$w->report('...pre-receive verifying ' . $hook_name);

return new $class($conf, $this->git_dir, $this->repo, $w, $this->di);
}
}
3 changes: 2 additions & 1 deletion test/lib/Git_Hook/Pre_Receive_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function test_verify_fails()
'pre_receive' => array('names' => 'jenkins'),
'jenkins' => array(
'class' => 'For_Testing',
'verbose' => false,
'enabled' => true,
'super' => 'duper',
),
Expand Down Expand Up @@ -134,4 +135,4 @@ public function verify($commit_hash)
$phpu->assertEquals('.git', $this->dir, 'Wrong git dir passed');
$phpu->assertEquals('duper', $this->conf['super'], 'Wrong conf passed');
}
}
}

0 comments on commit ba21940

Please sign in to comment.