/** * Trigger if enabled flag evaluates to TRUE and * this Gizzle installation is configured with a * personal access token (see README.md). * * Note: the token requirement is circumvented * when this plugin is used as event handler. * * @param Payload $payload * @return boolean */ public function trigger(Payload $payload) { $enabled = (bool) (TRUE === isset($this->settings[self::OPTION_ENABLED]) ? $this->settings[self::OPTION_ENABLED] : TRUE); $api = $payload->getApi(); return $enabled && FALSE === empty($api); }
/** * @param Payload $payload * @return boolean */ protected function validateCodeStyleOfPhpFilesInCommits(Payload $payload) { $url = $payload->getPullRequest()->resolveApiUrl(PullRequest::API_URL_COMMITS); $response = $payload->getApi()->get($url); $commits = json_decode($response->getContent(), JSON_OBJECT_AS_ARRAY); $hasErrors = FALSE; foreach ($commits as $commitData) { $commitUrl = $commitData['url']; $commitResponse = $payload->getApi()->get($commitUrl); $commitData = json_decode($commitResponse->getContent(), JSON_OBJECT_AS_ARRAY); $commit = new Commit($commitData); $commit->setId($commitData['sha']); foreach ($commitData['files'] as $fileData) { $extension = pathinfo($fileData['filename'], PATHINFO_EXTENSION); if (self::PHP_EXTENSION === $extension) { $result = $this->validateCodeStyleOfPhpFile($payload, $commit, $fileData['raw_url'], $fileData['filename']); $hasErrors = TRUE !== $result || TRUE === $hasErrors; } } } return FALSE === $hasErrors; }