Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Commands/ProjectCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,14 @@ public function createProject(
function ($state) use ($ci_env, $target, $target_org, $siteDir, $visibility) {

$target_project = $this->git_provider->createRepository($siteDir, $target, $target_org, $visibility);

$projectId = $this->git_provider->getProjectID($target_project);
$repositoryAttributes = $ci_env->getState('repository');
// $github_token = $repositoryAttributes->token();

// $target_project = $this->createGitHub($target, $siteDir, $target_org, $github_token);
$this->log()->notice('The target is {target}', ['target' => $target_project]);
$repositoryAttributes->setProjectId($target_project);
$this->log()->notice('The id is {id}', ['id' => $projectId]);
$repositoryAttributes->setProjectId($projectId);
})

// TODO: rollback GitHub repository create
Expand Down
15 changes: 10 additions & 5 deletions src/ServiceProviders/RepositoryProviders/GitLab/GitLabProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,19 @@ public function commentOnCommit($target_project, $commit_hash, $message) {
}

public function getProjectID($target_project) {
$project = $this->api()
->request("api/v4/projects/" . urlencode($target_project));
$projects = $this->api()->request("api/v4/projects");

if (empty($project)) {
throw new TerminusException('Error: No GitLab project found for {target_project}', ['target_project' => $target_project]);
if (empty($projects)) {
throw new TerminusException('Error: No GitLab projects found.');
}

return $project['id'];
// Loop through all the projects and look for the project just created
// by matching the target_project value to path_with_namespace key.
foreach ($projects as $project) {
if ($target_project == $project['path_with_namespace']) {
return $project['id'];
}
}
}

/**
Expand Down