Bart\GitHook\CodeFreeze::run PHP Method

run() public method

Run the action
public run ( Commit $commit )
$commit Bart\Git\Commit commit to verify
    public function run(Commit $commit)
    {
        $frozenRepos = $this->config->frozenRepoNames();
        if (count($frozenRepos) == 0) {
            $this->logger->debug("No frozen repos.");
            return;
        }
        // Super users are exempt from frozen checks
        // So hope they don't do anything bad by mistake!
        if ($this->isSuperUser()) {
            $this->logger->debug("Superuser exempt from freeze");
            return;
        }
        if ($frozenRepos === ['all']) {
            throw new GitHookException('All repositories are frozen.');
        }
        $project = $commit->getProjectName();
        $this->logger->debug("Validating if {$project} is frozen");
        if (in_array($project, $frozenRepos)) {
            throw new GitHookException("{$project} repository is frozen.");
        }
    }

Usage Example

Beispiel #1
0
 /**
  * @expectedException \Bart\GitHook\GitHookException
  * @expectedExceptionMessage All repositories are frozen
  */
 public function testWhenAllFrozenRepoAndNoEnvVarConfigured()
 {
     $this->shmockAndDieselify('\\Bart\\GitHook\\GitHookSystemConfig', function ($config) {
         $config->envVarNameForPushUser()->once()->return_value(Option::fromValue(null));
         // This should not be called because env var name is None
         $config->superUserNames()->never();
         $config->frozenRepoNames()->once()->return_value(['all']);
     }, true);
     $freeze = new CodeFreeze();
     $freeze->run($this->head);
 }