1
0
Fork 0
mirror of synced 2024-06-29 19:50:26 +12:00

Even more PR review changes

This commit is contained in:
Matej Bačo 2023-08-11 18:52:13 +02:00
parent f0125ac3bb
commit c24e2786fb
3 changed files with 11 additions and 30 deletions

View file

@ -169,6 +169,12 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId
continue;
}
if ($external) {
$pullRequestResponse = $github->getPullRequest($owner, $repositoryName, $providerPullRequestId);
$providerRepositoryName = $pullRequestResponse['head']['repo']['owner']['login'];
$providerRepositoryOwner = $pullRequestResponse['head']['repo']['name'];
}
$deployment = $dbForProject->createDocument('deployments', new Document([
'$id' => $deploymentId,
'$permissions' => [
@ -215,19 +221,10 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId
$github->updateCommitStatus($repositoryName, $providerCommitHash, $owner, 'pending', $message, $providerTargetUrl, $name);
}
$contribution = new Document([]);
if ($external) {
$pullRequestResponse = $github->getPullRequest($owner, $repositoryName, $providerPullRequestId);
$contribution->setAttribute('ownerName', $pullRequestResponse['head']['repo']['owner']['login']);
$contribution->setAttribute('repositoryName', $pullRequestResponse['head']['repo']['name']);
}
$buildEvent = new Build();
$buildEvent
->setType(BUILD_TYPE_DEPLOYMENT)
->setResource($function)
->setProviderContribution($contribution)
->setDeployment($deployment)
->setProject($project)
->trigger();

View file

@ -49,14 +49,13 @@ class BuildsV1 extends Worker
$resource = new Document($this->args['resource'] ?? []);
$deployment = new Document($this->args['deployment'] ?? []);
$template = new Document($this->args['template'] ?? []);
$providerContribution = new Document($this->args['providerContribution'] ?? []);
switch ($type) {
case BUILD_TYPE_DEPLOYMENT:
case BUILD_TYPE_RETRY:
Console::info('Creating build for deployment: ' . $deployment->getId());
$github = new GitHub($this->getCache());
$this->buildDeployment($github, $project, $resource, $deployment, $template, $providerContribution);
$this->buildDeployment($github, $project, $resource, $deployment, $template);
break;
default:
@ -70,7 +69,7 @@ class BuildsV1 extends Worker
* @throws \Utopia\Database\Exception\Structure
* @throws Throwable
*/
protected function buildDeployment(GitHub $github, Document $project, Document $function, Document $deployment, Document $template, Document $providerContribution = null)
protected function buildDeployment(GitHub $github, Document $project, Document $function, Document $deployment, Document $template)
{
global $register;
@ -173,8 +172,8 @@ class BuildsV1 extends Worker
$owner = $github->getOwnerName($providerInstallationId);
$repositoryName = $github->getRepositoryName($providerRepositoryId);
$cloneOwner = !empty($providerContribution) ? $providerContribution->getAttribute('owner', $owner) : $owner;
$cloneRepository = !empty($providerContribution) ? $providerContribution->getAttribute('repository', $repositoryName) : $repositoryName;
$cloneOwner = $deployment->getAttribute('providerRepositoryOwner', $owner);
$cloneRepository = $deployment->getAttribute('providerRepositoryName', $repositoryName);
$branchName = $deployment->getAttribute('providerBranch');
$gitCloneCommand = $github->generateCloneCommand($cloneOwner, $cloneRepository, $branchName, $tmpDirectory, $rootDirectory);

View file

@ -11,7 +11,6 @@ class Build extends Event
protected ?Document $resource = null;
protected ?Document $deployment = null;
protected ?Document $template = null;
protected ?Document $providerContribution = null;
public function __construct()
{
@ -44,19 +43,6 @@ class Build extends Event
return $this;
}
/**
* Sets custom owner and repository for VCS clone command during build
*
* @param Document $providerContribution
* @return self
*/
public function setProviderContribution(Document $providerContribution): self
{
$this->providerContribution = $providerContribution;
return $this;
}
/**
* Returns set resource document for the build event.
*
@ -126,8 +112,7 @@ class Build extends Event
'resource' => $this->resource,
'deployment' => $this->deployment,
'type' => $this->type,
'template' => $this->template,
'providerContribution' => $this->providerContribution
'template' => $this->template
]);
}
}