public function toArray() { $mr = ['url' => null, 'number' => null, 'state' => null, 'title' => null, 'body' => null, 'labels' => [], 'milestone' => null, 'created_at' => new \DateTime(), 'updated_at' => null, 'user' => null, 'assignee' => null, 'merged' => false, 'merged_by' => null, 'head' => ['ref' => null, 'sha' => null, 'user' => null, 'repo' => null], 'base' => ['ref' => null, 'label' => null, 'sha' => null, 'repo' => null, 'user' => null]]; foreach (static::$properties as $property) { switch ($property) { case 'id': $mr['number'] = $this->{$property}; break; case 'author': $mr['author'] = $this->{$property}->username; break; case 'source_project_id': if ($this->project->id === $this->{$property}) { $sourceProject = $this->project; } else { $sourceProject = Model\Project::fromArray($this->getClient(), $this->getClient()->api('projects')->show($this->{$property})); } $mr['head']['user'] = $sourceProject->namespace->path; $mr['head']['repo'] = $sourceProject->name; break; case 'state': $mr['state'] = 'opened' === $this->{$property} ? 'open' : $this->{$property}; $mr['merged'] = $this->{$property} === 'merged'; break; case 'source_branch': $mr['head']['ref'] = $this->{$property}; break; case 'target_project_id': if ($this->project->id === $this->{$property}) { $targetProject = $this->project; } else { $targetProject = Model\Project::fromArray($this->getClient(), $this->getClient()->api('projects')->show($this->{$property})); } $mr['base']['user'] = $targetProject->namespace->path; $mr['base']['repo'] = $targetProject->name; break; case 'target_branch': $mr['base']['ref'] = $this->{$property}; break; case 'created_at': case 'updated_at': // remove microseconds precision (2014-11-28T08:43:59.354Z -> 2014-11-28T08:43:59Z) $mr[$property] = new \DateTime(preg_replace('{\\.\\d+}', '', $this->{$property})); break; case 'description': $mr['body'] = $this->{$property}; break; default: $mr[$property] = $this->{$property}; break; } } return $mr; }
/** * @param Client $client * @param array $data * @return Group */ public static function fromArray(Client $client, array $data) { $group = new static($data['id'], $client); if (isset($data['projects'])) { $projects = array(); foreach ($data['projects'] as $project) { $projects[] = Project::fromArray($client, $project); } $data['projects'] = $projects; } return $group->hydrate($data); }
/** * @inheritdoc */ public function saveGit() { $client = new Client($this->enterpriseUrl); $client->authenticate($this->authKey, Client::AUTH_URL_TOKEN); $projects = $client->getHttpClient()->get('projects/')->getContent(); foreach ($projects as $data) { if ($data['path_with_namespace'] == $this->owner . '/' . $this->repository) { $id = $data['id']; break; } } if (!isset($id)) { throw new HttpException(404, "Repository " . $this->repository . " not found."); } /** * @var Project $project */ $project = Project::fromArray($client, compact('id')); $project->updateFile($this->remotePath, $this->content, 'master', $this->comment); return true; }
protected function findProject($namespace, $projectName) { return Model\Project::fromArray($this->client, $this->client->api('projects')->show($namespace . '/' . $projectName)); }
/** * @param int $id * @return Project */ public function createForkRelation($id) { $data = $this->api('projects')->createForkRelation($this->id, $id); return Project::fromArray($this->getClient(), $data); }
/** * Disable a GitLab webhook for the given Package. * * @param Package $package * * @return bool */ public function disableHook(Package $package) { $config = $this->getConfig($package); if (!$config->isEnabled()) { return true; } if ($package->getHookExternalId()) { $client = $this->getClient($package->getRemote()); $project = Project::fromArray($client, (array) $client->api('projects')->show($package->getExternalId())); $project->removeHook($package->getHookExternalId()); } $package->setHookExternalId(''); $config->setEnabled(false); return true; }
/** * @return Project[] * @throws \Gitlab\Exception\InvalidArgumentException */ public function getAllProjects() { if (null === $this->allProjects) { $client = $this->getGitLabClient(); $allProjects = []; /** @var \Gitlab\Api\Projects $apiProjects */ $apiProjects = $client->api('projects'); for ($i = 1; $i < static::MAX_PAGE; $i++) { $projects = $apiProjects->all($i, self::PER_PAGE); if (0 === count($projects)) { break; } foreach ($projects as $project) { $project = Project::fromArray($client, $project); $allProjects[$project->id] = $project; } } $this->allProjects = $allProjects; } return $this->allProjects; }