Skip to content

Commit

Permalink
Use enum instead of config file for directives
Browse files Browse the repository at this point in the history
  • Loading branch information
nadeemahmad committed Feb 29, 2016
1 parent fe84c81 commit 9a7fbcb
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 34 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"php": ">=5.4.0",
"chobie/jira-api-restclient": "2.0.*@dev",
"apache/log4php": "2.3.0",
"phpoption/phpoption": "^1.5"
"phpoption/phpoption": "^1.5",
"eloquent/enumeration": "^5.1"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
Expand Down
57 changes: 54 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/Bart/GitHook/Directives.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Bart\GitHook;

use Eloquent\Enumeration\AbstractEnumeration;

/**
* Class Directives
* @package Bart\GitHook
*/
class Directives extends AbstractEnumeration
{
/**
* Used by StopTheLineJenkins Hook Action to allow commits that have this
* directive to go through, when the build is broken.
*/
const buildFix = '{buildFix}';

}
17 changes: 1 addition & 16 deletions src/Bart/GitHook/GitHookConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ public function README()
; %s will be replaced with commit revision hash
comment_template = 'Commit %s pushed to JIRA. See online at https://git.example.com/?h=%s'
[jenkins]
; Used by StopTheLineJenkins Hook Action to allow
; commits that have this directive to go through,
; when the build is broken. Defaults to {buildfix}.
build_fix_directive = '{buildfix}'
[notifications]
; Optional email address to notify when emergencies are pushed
emergency_notification_email = emergencies@example.com
Expand Down Expand Up @@ -68,14 +62,6 @@ public function jiraCommentTemplate()
return $this->getValue('jira', 'comment_template');
}

/**
* @return string Build fix directive used to allow commits that fix builds to go through
*/
public function jenkinsBuildFixDirective()
{
return $this->getValue('jenkins', 'build_fix_directive', '{buildFix}', false);
}

/**
* @return \string[] List of refs to run git hooks on
*/
Expand Down Expand Up @@ -108,5 +94,4 @@ public function getEmergencyNotificationBody()
return $this->getValue('notifications', 'body', '', false);
}


}
}
4 changes: 1 addition & 3 deletions src/Bart/GitHook/StopTheLineJenkins.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ public function run(Commit $commit)
$this->logger->info('Jenkins job is not healthy...asserting that commit message contains {buildfix} hash');
$messageSubject = $commit->messageSubject();

/** @var GitHookConfig $gitHookConfig */
$gitHookConfig = Diesel::create('\Bart\GitHook\GitHookConfig');
$buildFixDirective = $gitHookConfig->jenkinsBuildFixDirective();
$buildFixDirective = Directives::buildFix();

// Check if commit has buildfix directive
if (preg_match("/{$buildFixDirective}/", $messageSubject) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/Bart/Jenkins/JenkinsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function protocol()
}

/**
* @return string The port that the Jenkins instance is running on
* @return int The port that the Jenkins instance is running on
* @throws ConfigurationException
*/
public function port()
Expand Down
10 changes: 0 additions & 10 deletions test/Bart/GitHook/StopTheLineJenkinsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

class StopTheLineJenkinsTest extends TestBase
{
private static $buildFixDirective = '{buildFix}';

public function testHealthyBuild()
{
$this->mockJenkinsJobWithDependencies();
Expand Down Expand Up @@ -35,10 +33,6 @@ public function dataProviderValidBuildFixDirectives()
public function testUnhealthyBuildAndValidBuildFixDirectives($message)
{
$this->mockJenkinsJobWithDependencies(false);
$this->shmockAndDieselify('\Bart\GitHook\GitHookConfig', function ($hConfigs) {
$hConfigs->jenkinsBuildFixDirective()->once()->return_value(self::$buildFixDirective);
}, true);

$mockCommit = CommitTest::getStubCommit($this, 'HEAD', function ($head) use ($message) {
$head->messageSubject()->once()->return_value($message);
});
Expand All @@ -64,10 +58,6 @@ public function dataProviderInvalidBuildFixDirectives()
public function testUnhealthyBuildAndInvalidBuildFixDirectives($message)
{
$this->mockJenkinsJobWithDependencies(false);
$this->shmockAndDieselify('\Bart\GitHook\GitHookConfig', function ($hConfigs) {
$hConfigs->jenkinsBuildFixDirective()->once()->return_value(self::$buildFixDirective);
}, true);

$mockCommit = CommitTest::getStubCommit($this, 'HEAD', function ($head) use ($message) {
$head->messageSubject()->once()->return_value($message);
});
Expand Down

0 comments on commit 9a7fbcb

Please sign in to comment.