1
0
Fork 0
mirror of synced 2024-07-01 20:50:49 +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; 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([ $deployment = $dbForProject->createDocument('deployments', new Document([
'$id' => $deploymentId, '$id' => $deploymentId,
'$permissions' => [ '$permissions' => [
@ -215,19 +221,10 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId
$github->updateCommitStatus($repositoryName, $providerCommitHash, $owner, 'pending', $message, $providerTargetUrl, $name); $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 = new Build();
$buildEvent $buildEvent
->setType(BUILD_TYPE_DEPLOYMENT) ->setType(BUILD_TYPE_DEPLOYMENT)
->setResource($function) ->setResource($function)
->setProviderContribution($contribution)
->setDeployment($deployment) ->setDeployment($deployment)
->setProject($project) ->setProject($project)
->trigger(); ->trigger();

View file

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

View file

@ -11,7 +11,6 @@ class Build extends Event
protected ?Document $resource = null; protected ?Document $resource = null;
protected ?Document $deployment = null; protected ?Document $deployment = null;
protected ?Document $template = null; protected ?Document $template = null;
protected ?Document $providerContribution = null;
public function __construct() public function __construct()
{ {
@ -44,19 +43,6 @@ class Build extends Event
return $this; 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. * Returns set resource document for the build event.
* *
@ -126,8 +112,7 @@ class Build extends Event
'resource' => $this->resource, 'resource' => $this->resource,
'deployment' => $this->deployment, 'deployment' => $this->deployment,
'type' => $this->type, 'type' => $this->type,
'template' => $this->template, 'template' => $this->template
'providerContribution' => $this->providerContribution
]); ]);
} }
} }