private function fixProvider(OutputInterface $output, Project $project)
 {
     if (strlen($project->getProviderName()) > 0) {
         $output->writeln('project <info>' . $project->getFullName() . '</info> already migrated');
         return false;
     }
     $output->writeln('migrating project <info>' . $project->getFullName() . '</info>');
     $project->setFullName($project->getGithubFullName());
     $project->setProviderName('github');
     $project->setProviderData(['clone_url' => $project->getCloneUrl(), 'ssh_url' => $project->getSshUrl(), 'keys_url' => $project->getKeysUrl(), 'hooks_url' => $project->getHooksUrl(), 'contents_url' => $project->getContentsUrl(), 'id' => $project->getGithubId(), 'full_name' => $project->getGithubFullName(), 'owner_login' => $project->getGithubOwnerLogin(), 'hook_id' => $project->getGithubHookId(), 'deploy_key_id' => $project->getGithubDeployKeyId(), 'private' => $project->getGithubPrivate(), 'url' => $project->getGithubUrl()]);
     return true;
 }
예제 #2
0
 /**
  * @todo the policy check and Payload->isBuildable() could be implemented
  *       as a voting system
  */
 private function schedulePullRequest(PayloadInterface $payload, Project $project)
 {
     $logger = $this->get('logger');
     switch ($project->getSettings()->getPolicy()) {
         case ProjectSettings::POLICY_ALL:
         case ProjectSettings::POLICY_PR:
             $doBuild = true;
             break;
         case ProjectSettings::POLICY_PATTERNS:
         case ProjectSettings::POLICY_NONE:
             $doBuild = false;
             break;
         default:
             $logger->error('could not find a build policy', ['project' => $project->getFullName(), 'pull_request_number' => $payload->getPullRequestNumber()]);
             return new JsonResponse(['project' => $project->getFullName(), 'class' => 'danger', 'policy' => $project->getSettings()->getPolicy(), 'message' => 'Could not find a valid build policy'], 400);
     }
     if (!$doBuild) {
         $logger->info('build declined by project policy', ['project' => $project->getId(), 'number' => $payload->getPullRequestNumber()]);
         return new JsonResponse(['class' => 'info', 'message' => 'Build declined by project policy (' . $project->getSettings()->getPolicy() . ')'], 200);
     }
     if (!$payload->isBuildable()) {
         return new JsonResponse(json_encode(['class' => 'danger', 'message' => 'pull request is not buildable']), 200);
     }
     $ref = sprintf('pull/%d/head', $payload->getPullRequestNumber());
     $provider = $this->get('app_core.provider.factory')->getProvider($project);
     return [$ref, $provider->getHashFromRef($project, $ref)];
 }
예제 #3
0
 /**
  * @param Project $project
  *
  * @return Client
  */
 public function configureClientForProject(Project $project)
 {
     if (count($project->getUsers()) === 0) {
         throw new InvalidArgumentException('Project "' . $project->getFullName() . '" has no users');
     }
     return $this->configureClientForUser($project->getUsers()->first());
 }
예제 #4
0
 /**
  * @param Project $project
  */
 protected function doPullRequests(Project $project)
 {
     // right now, there's no clean way to checkout bitbucket's pull request, so we're just going to not support them
     return;
     // @bitbucketapi sometimes its {owner}, sometimes {accountname}
     // also, URL is wrong in documentation (is 1.0, should be 2.0)
     // see https://confluence.atlassian.com/display/BITBUCKET/pullrequests+Resource#pullrequestsResource-GETalistofopenpullrequests
     $url = sprintf('2.0/repositories/%s/pullrequests?state=OPEN', $project->getFullName());
     foreach ($this->fetchPullRequests($url) as $data) {
         $pr = new PullRequest();
         $pr->setNumber($data['id']);
         $pr->setOpen(true);
         $pr->setTitle($data['title']);
         // $pr->setRef(sprintf('pull/%d/head', $data['number']));
         $pr->setProject($project);
         $project->addPullRequest($pr);
     }
 }
예제 #5
0
 private function getGithubInfos(Project $project)
 {
     if (!array_key_exists($project->getFullName(), $this->githubInfos)) {
         $provider = $this->getContainer()->get('app_core.provider.github');
         $client = $provider->configureClientForProject($project);
         $request = $client->get($project->getGithubUrl());
         $response = $request->send();
         $this->githubInfos[$project->getFullName()] = $response->json();
     }
     return $this->githubInfos[$project->getFullName()];
 }
예제 #6
0
 /**
  * @param Project $project
  * @param string  $ref
  *
  * @return string
  */
 public function getHashFromRef(Project $project, $ref)
 {
     if (substr($ref, 0, 4) !== 'pull') {
         $ref = 'heads/' . $ref;
     }
     $url = sprintf('/repos/%s/git/refs/%s', $project->getFullName(), $ref);
     $client = $this->configureClientForProject($project);
     return $client->get($url)->send()->json()['object']['sha'];
 }
예제 #7
0
 /**
  * @param Project $project
  *
  * @return boolean
  */
 protected function doPullRequests(Project $project)
 {
     $url = sprintf('/repos/%s/pulls', $project->getFullName());
     $request = $this->client->get($url);
     $response = $request->send();
     foreach ($response->json() as $data) {
         $pr = new PullRequest();
         $pr->setNumber($data['number']);
         $pr->setOpen($data['state'] === 'open');
         $pr->setTitle($data['title']);
         $pr->setRef(sprintf('pull/%d/head', $data['number']));
         $pr->setProject($project);
         $project->addPullRequest($pr);
     }
 }