Merge branch 'feat-git-integration' of https://github.com/appwrite/appwrite into feat-git-integration
This commit is contained in:
commit
1bd226ab81
5 changed files with 155 additions and 145 deletions
|
@ -1 +1 @@
|
|||
Subproject commit dff906f8bffe31678a4e494082065535bca06d2c
|
||||
Subproject commit 65bd2441e69662a1275f123df0d02709bc0f8613
|
|
@ -48,7 +48,7 @@ use MaxMind\Db\Reader;
|
|||
|
||||
include_once __DIR__ . '/../shared/api.php';
|
||||
|
||||
$redeployVcsLogic = function (Request $request, Document $function, Document $project, Document $installation, Database $dbForProject, Document $template) {
|
||||
$redeployVcsLogic = function (Request $request, Document $function, Document $project, Document $installation, Database $dbForProject, Document $vcsTemplate) {
|
||||
$deploymentId = ID::unique();
|
||||
$entrypoint = $function->getAttribute('entrypoint', '');
|
||||
$deployment = $dbForProject->createDocument('deployments', new Document([
|
||||
|
@ -77,15 +77,15 @@ $redeployVcsLogic = function (Request $request, Document $function, Document $pr
|
|||
$projectId = $project->getId();
|
||||
$functionId = $function->getId();
|
||||
|
||||
$targetUrl = $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$projectId/functions/function-$functionId";
|
||||
$vcsTargetUrl = $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$projectId/functions/function-$functionId";
|
||||
|
||||
$buildEvent = new Build();
|
||||
$buildEvent
|
||||
->setType(BUILD_TYPE_DEPLOYMENT)
|
||||
->setResource($function)
|
||||
->setDeployment($deployment)
|
||||
->setTargetUrl($targetUrl)
|
||||
->setTemplate($template)
|
||||
->setVcsTargetUrl($vcsTargetUrl)
|
||||
->setVcsTemplate($vcsTemplate)
|
||||
->setProject($project)
|
||||
->trigger();
|
||||
};
|
||||
|
@ -135,9 +135,9 @@ App::post('/v1/functions')
|
|||
$functionId = ($functionId == 'unique()') ? ID::unique() : $functionId;
|
||||
|
||||
// build from template
|
||||
$template = new Document([]);
|
||||
$vcsTemplate = new Document([]);
|
||||
if (!empty($templateRepositoryName) && !empty($templateOwnerName)) {
|
||||
$template->setAttribute('repositoryName', $templateRepositoryName)
|
||||
$vcsTemplate->setAttribute('repositoryName', $templateRepositoryName)
|
||||
->setAttribute('ownerName', $templateOwnerName)
|
||||
->setAttribute('rootDirectory', $templateRootDirectory)
|
||||
->setAttribute('branch', $templateBranch);
|
||||
|
@ -228,7 +228,7 @@ App::post('/v1/functions')
|
|||
|
||||
// Redeploy vcs logic
|
||||
if (!empty($vcsRepositoryId)) {
|
||||
$redeployVcsLogic($request, $function, $project, $installation, $dbForProject, $template);
|
||||
$redeployVcsLogic($request, $function, $project, $installation, $dbForProject, $vcsTemplate);
|
||||
}
|
||||
|
||||
$functionsDomain = App::getEnv('_APP_DOMAIN_FUNCTIONS', '');
|
||||
|
|
|
@ -49,6 +49,7 @@ App::get('/v1/vcs/github/installations')
|
|||
->label('sdk.response.code', Response::STATUS_CODE_MOVED_PERMANENTLY)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_HTML)
|
||||
->label('sdk.methodType', 'webAuth')
|
||||
->label('sdk.hide', true)
|
||||
->param('redirect', '', fn ($clients) => new Host($clients), 'URL to redirect back to your Git authorization. Only console hostnames are allowed.', true, ['clients'])
|
||||
->param('projectId', '', new UID(), 'Project ID')
|
||||
->inject('response')
|
||||
|
@ -123,10 +124,10 @@ App::get('/v1/vcs/github/redirect')
|
|||
// OAuth Authroization
|
||||
if (!empty($code)) {
|
||||
$oauth2 = new OAuth2Github(App::getEnv('VCS_GITHUB_CLIENT_ID', ''), App::getEnv('VCS_GITHUB_CLIENT_SECRET', ''), "");
|
||||
$accessToken = $oauth2->getAccessToken($code);
|
||||
$refreshToken = $oauth2->getRefreshToken($code);
|
||||
$accessTokenExpiry = $oauth2->getAccessTokenExpiry($code);
|
||||
$personalSlug = $oauth2->getUserSlug($accessToken);
|
||||
$accessToken = $oauth2->getAccessToken($code) ?? '';
|
||||
$refreshToken = $oauth2->getRefreshToken($code) ?? '';
|
||||
$accessTokenExpiry = $oauth2->getAccessTokenExpiry($code) ?? '';
|
||||
$personalSlug = $oauth2->getUserSlug($accessToken) ?? '';
|
||||
|
||||
$user = $user
|
||||
->setAttribute('vcsGithubAccessToken', $accessToken)
|
||||
|
@ -141,7 +142,7 @@ App::get('/v1/vcs/github/redirect')
|
|||
$privateKey = App::getEnv('VCS_GITHUB_PRIVATE_KEY');
|
||||
$githubAppId = App::getEnv('VCS_GITHUB_APP_ID');
|
||||
$github->initialiseVariables($installationId, $privateKey, $githubAppId);
|
||||
$owner = $github->getOwnerName($installationId);
|
||||
$owner = $github->getOwnerName($installationId) ?? '';
|
||||
|
||||
$projectInternalId = $project->getInternalId();
|
||||
|
||||
|
@ -186,6 +187,69 @@ App::get('/v1/vcs/github/redirect')
|
|||
->redirect($redirect);
|
||||
});
|
||||
|
||||
App::get('/v1/vcs/github/installations/:installationId/repositories/:repositoryId/detection')
|
||||
->desc('Detect runtime settings from source code')
|
||||
->groups(['api', 'vcs'])
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'vcs')
|
||||
->label('sdk.method', 'createRepositoryDetection')
|
||||
->label('sdk.description', '')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_DETECTION)
|
||||
->param('installationId', '', new Text(256), 'Installation Id')
|
||||
->param('repositoryId', '', new Text(256), 'Repository Id')
|
||||
->param('rootDirectoryPath', '', new Text(256), 'Path to Root Directory', true)
|
||||
->inject('gitHub')
|
||||
->inject('response')
|
||||
->inject('project')
|
||||
->inject('dbForConsole')
|
||||
->action(function (string $vcsInstallationId, string $repositoryId, string $rootDirectoryPath, GitHub $github, Response $response, Document $project, Database $dbForConsole) {
|
||||
$installation = $dbForConsole->getDocument('vcsInstallations', $vcsInstallationId, [
|
||||
Query::equal('projectInternalId', [$project->getInternalId()])
|
||||
]);
|
||||
|
||||
if ($installation->isEmpty()) {
|
||||
throw new Exception(Exception::INSTALLATION_NOT_FOUND);
|
||||
}
|
||||
|
||||
$installationId = $installation->getAttribute('installationId');
|
||||
$privateKey = App::getEnv('VCS_GITHUB_PRIVATE_KEY');
|
||||
$githubAppId = App::getEnv('VCS_GITHUB_APP_ID');
|
||||
$github->initialiseVariables($installationId, $privateKey, $githubAppId);
|
||||
|
||||
$owner = $github->getOwnerName($installationId);
|
||||
$repositoryName = $github->getRepositoryName($repositoryId);
|
||||
|
||||
if (empty($repositoryName)) {
|
||||
throw new Exception(Exception::REPOSITORY_NOT_FOUND);
|
||||
}
|
||||
|
||||
$files = $github->listRepositoryContents($owner, $repositoryName, $rootDirectoryPath);
|
||||
$languages = $github->getRepositoryLanguages($owner, $repositoryName);
|
||||
|
||||
$detectorFactory = new Detector($files, $languages);
|
||||
|
||||
$detectorFactory
|
||||
->addDetector(new JavaScript())
|
||||
->addDetector(new PHP())
|
||||
->addDetector(new Python())
|
||||
->addDetector(new Dart())
|
||||
->addDetector(new Swift())
|
||||
->addDetector(new Ruby())
|
||||
->addDetector(new Java())
|
||||
->addDetector(new CPP())
|
||||
->addDetector(new Deno())
|
||||
->addDetector(new Dotnet());
|
||||
|
||||
$runtime = $detectorFactory->detect();
|
||||
|
||||
$detection = [];
|
||||
$detection['runtime'] = $runtime;
|
||||
|
||||
$response->dynamic(new Document($detection), Response::MODEL_DETECTION);
|
||||
});
|
||||
|
||||
App::get('/v1/vcs/github/installations/:installationId/repositories')
|
||||
->desc('List Repositories')
|
||||
->groups(['api', 'vcs'])
|
||||
|
@ -349,8 +413,8 @@ App::post('/v1/vcs/github/installations/:installationId/repositories')
|
|||
$repository = $github->createRepository($owner, $name, $private);
|
||||
}
|
||||
|
||||
$repository['id'] = \strval($repository['id']);
|
||||
$repository['pushedAt'] = $repository['pushed_at'];
|
||||
$repository['id'] = \strval($repository['id']) ?? '';
|
||||
$repository['pushedAt'] = $repository['pushed_at'] ?? '';
|
||||
$repository['organization'] = $installation->getAttribute('organization', '');
|
||||
$repository['provider'] = $installation->getAttribute('provider', '');
|
||||
|
||||
|
@ -387,8 +451,8 @@ App::get('/v1/vcs/github/installations/:installationId/repositories/:repositoryI
|
|||
$githubAppId = App::getEnv('VCS_GITHUB_APP_ID');
|
||||
$github->initialiseVariables($installationId, $privateKey, $githubAppId);
|
||||
|
||||
$owner = $github->getOwnerName($installationId);
|
||||
$repositoryName = $github->getRepositoryName($repositoryId);
|
||||
$owner = $github->getOwnerName($installationId) ?? '';
|
||||
$repositoryName = $github->getRepositoryName($repositoryId) ?? '';
|
||||
|
||||
if (empty($repositoryName)) {
|
||||
throw new Exception(Exception::REPOSITORY_NOT_FOUND);
|
||||
|
@ -396,8 +460,8 @@ App::get('/v1/vcs/github/installations/:installationId/repositories/:repositoryI
|
|||
|
||||
$repository = $github->getRepository($owner, $repositoryName);
|
||||
|
||||
$repository['id'] = \strval($repository['id']);
|
||||
$repository['pushedAt'] = $repository['pushed_at'];
|
||||
$repository['id'] = \strval($repository['id']) ?? '';
|
||||
$repository['pushedAt'] = $repository['pushed_at'] ?? '';
|
||||
$repository['organization'] = $installation->getAttribute('organization', '');
|
||||
$repository['provider'] = $installation->getAttribute('provider', '');
|
||||
|
||||
|
@ -434,9 +498,14 @@ App::get('/v1/vcs/github/installations/:installationId/repositories/:repositoryI
|
|||
$githubAppId = App::getEnv('VCS_GITHUB_APP_ID');
|
||||
$github->initialiseVariables($installationId, $privateKey, $githubAppId);
|
||||
|
||||
$owner = $github->getOwnerName($installationId);
|
||||
$repoName = $github->getRepositoryName($repositoryId);
|
||||
$branches = $github->listBranches($owner, $repoName);
|
||||
$owner = $github->getOwnerName($installationId) ?? '';
|
||||
$repositoryName = $github->getRepositoryName($repositoryId) ?? '';
|
||||
|
||||
if (empty($repositoryName)) {
|
||||
throw new Exception(Exception::REPOSITORY_NOT_FOUND);
|
||||
}
|
||||
|
||||
$branches = $github->listBranches($owner, $repositoryName) ?? [];
|
||||
|
||||
$response->dynamic(new Document([
|
||||
'branches' => \array_map(function ($branch) {
|
||||
|
@ -446,7 +515,7 @@ App::get('/v1/vcs/github/installations/:installationId/repositories/:repositoryI
|
|||
]), Response::MODEL_BRANCH_LIST);
|
||||
});
|
||||
|
||||
$createGitDeployments = function (GitHub $github, string $installationId, array $vcsRepos, string $branchName, string $SHA, string $pullRequest, bool $external, Database $dbForConsole, callable $getProjectDB, Request $request) {
|
||||
$createGitDeployments = function (GitHub $github, string $installationId, array $vcsRepos, string $branchName, string $vcsCommitHash, string $pullRequest, bool $external, Database $dbForConsole, callable $getProjectDB, Request $request) {
|
||||
foreach ($vcsRepos as $resource) {
|
||||
$resourceType = $resource->getAttribute('resourceType');
|
||||
|
||||
|
@ -499,8 +568,12 @@ $createGitDeployments = function (GitHub $github, string $installationId, array
|
|||
}
|
||||
}
|
||||
|
||||
$owner = $github->getOwnerName($installationId);
|
||||
$repositoryName = $github->getRepositoryName($repositoryId);
|
||||
$owner = $github->getOwnerName($installationId) ?? '';
|
||||
$repositoryName = $github->getRepositoryName($repositoryId) ?? '';
|
||||
|
||||
if (empty($repositoryName)) {
|
||||
throw new Exception(Exception::REPOSITORY_NOT_FOUND);
|
||||
}
|
||||
|
||||
$isAuthorized = !$external;
|
||||
|
||||
|
@ -561,12 +634,12 @@ $createGitDeployments = function (GitHub $github, string $installationId, array
|
|||
$projectName = $project->getAttribute('name');
|
||||
$name = "{$functionName} ({$projectName})";
|
||||
$message = 'Authorization required for external contributor.';
|
||||
$targetUrl = $request->getProtocol() . '://' . $request->getHostname() . "/git/authorize-contributor?projectId={$projectId}&installationId={$vcsInstallationId}&vcsRepositoryId={$vcsRepoId}&pullRequest={$pullRequest}";
|
||||
$vcsTargetUrl = $request->getProtocol() . '://' . $request->getHostname() . "/git/authorize-contributor?projectId={$projectId}&installationId={$vcsInstallationId}&vcsRepositoryId={$vcsRepoId}&pullRequest={$pullRequest}";
|
||||
|
||||
$repositoryId = $resource->getAttribute('repositoryId');
|
||||
$repositoryName = $github->getRepositoryName($repositoryId);
|
||||
$owner = $github->getOwnerName($installationId);
|
||||
$github->updateCommitStatus($repositoryName, $SHA, $owner, 'failure', $message, $targetUrl, $name);
|
||||
$github->updateCommitStatus($repositoryName, $vcsCommitHash, $owner, 'failure', $message, $vcsTargetUrl, $name);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -593,9 +666,9 @@ $createGitDeployments = function (GitHub $github, string $installationId, array
|
|||
'activate' => $activate,
|
||||
]));
|
||||
|
||||
$targetUrl = $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$projectId/functions/function-$functionId";
|
||||
$vcsTargetUrl = $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$projectId/functions/function-$functionId";
|
||||
|
||||
if (!empty($SHA) && $function->getAttribute('vcsSilentMode', false) === false) {
|
||||
if (!empty($vcsCommitHash) && $function->getAttribute('vcsSilentMode', false) === false) {
|
||||
$functionName = $function->getAttribute('name');
|
||||
$projectName = $project->getAttribute('name');
|
||||
$name = "{$functionName} ({$projectName})";
|
||||
|
@ -604,7 +677,7 @@ $createGitDeployments = function (GitHub $github, string $installationId, array
|
|||
$repositoryId = $resource->getAttribute('repositoryId');
|
||||
$repositoryName = $github->getRepositoryName($repositoryId);
|
||||
$owner = $github->getOwnerName($installationId);
|
||||
$github->updateCommitStatus($repositoryName, $SHA, $owner, 'pending', $message, $targetUrl, $name);
|
||||
$github->updateCommitStatus($repositoryName, $vcsCommitHash, $owner, 'pending', $message, $vcsTargetUrl, $name);
|
||||
}
|
||||
|
||||
$contribution = new Document([]);
|
||||
|
@ -621,8 +694,8 @@ $createGitDeployments = function (GitHub $github, string $installationId, array
|
|||
->setResource($function)
|
||||
->setVcsContribution($contribution)
|
||||
->setDeployment($deployment)
|
||||
->setTargetUrl($targetUrl)
|
||||
->setSHA($SHA)
|
||||
->setVcsTargetUrl($vcsTargetUrl)
|
||||
->setVcsCommitHash($vcsCommitHash)
|
||||
->setProject($project)
|
||||
->trigger();
|
||||
|
||||
|
@ -658,10 +731,10 @@ App::post('/v1/vcs/github/events')
|
|||
$parsedPayload = $github->getEvent($event, $payload);
|
||||
|
||||
if ($event == $github::EVENT_PUSH) {
|
||||
$branchName = $parsedPayload["branch"];
|
||||
$repositoryId = $parsedPayload["repositoryId"];
|
||||
$installationId = $parsedPayload["installationId"];
|
||||
$SHA = $parsedPayload["SHA"];
|
||||
$branchName = $parsedPayload["branch"] ?? '';
|
||||
$repositoryId = $parsedPayload["repositoryId"] ?? '';
|
||||
$installationId = $parsedPayload["installationId"] ?? '';
|
||||
$vcsCommitHash = $parsedPayload["SHA"] ?? '';
|
||||
|
||||
$github->initialiseVariables($installationId, $privateKey, $githubAppId);
|
||||
|
||||
|
@ -671,7 +744,7 @@ App::post('/v1/vcs/github/events')
|
|||
Query::limit(100),
|
||||
]);
|
||||
|
||||
$createGitDeployments($github, $installationId, $vcsRepos, $branchName, $SHA, '', false, $dbForConsole, $getProjectDB, $request);
|
||||
$createGitDeployments($github, $installationId, $vcsRepos, $branchName, $vcsCommitHash, '', false, $dbForConsole, $getProjectDB, $request);
|
||||
} elseif ($event == $github::EVENT_INSTALLATION) {
|
||||
if ($parsedPayload["action"] == "deleted") {
|
||||
// TODO: Use worker for this job instead (update function as well)
|
||||
|
@ -697,12 +770,12 @@ App::post('/v1/vcs/github/events')
|
|||
}
|
||||
} elseif ($event == $github::EVENT_PULL_REQUEST) {
|
||||
if ($parsedPayload["action"] == "opened" || $parsedPayload["action"] == "reopened" || $parsedPayload["action"] == "synchronize") {
|
||||
$branchName = $parsedPayload["branch"];
|
||||
$repositoryId = $parsedPayload["repositoryId"];
|
||||
$installationId = $parsedPayload["installationId"];
|
||||
$pullRequestNumber = $parsedPayload["pullRequestNumber"];
|
||||
$SHA = $parsedPayload["SHA"];
|
||||
$external = $parsedPayload["external"];
|
||||
$branchName = $parsedPayload["branch"] ?? '';
|
||||
$repositoryId = $parsedPayload["repositoryId"] ?? '';
|
||||
$installationId = $parsedPayload["installationId"] ?? '';
|
||||
$pullRequestNumber = $parsedPayload["pullRequestNumber"] ?? '';
|
||||
$vcsCommitHash = $parsedPayload["SHA"] ?? '';
|
||||
$external = $parsedPayload["external"] ?? true;
|
||||
|
||||
// Ignore sync for non-external. We handle it in push webhook
|
||||
if (!$external && $parsedPayload["action"] == "synchronize") {
|
||||
|
@ -716,13 +789,13 @@ App::post('/v1/vcs/github/events')
|
|||
Query::orderDesc('$createdAt')
|
||||
]);
|
||||
|
||||
$createGitDeployments($github, $installationId, $vcsRepos, $branchName, $SHA, $pullRequestNumber, $external, $dbForConsole, $getProjectDB, $request);
|
||||
$createGitDeployments($github, $installationId, $vcsRepos, $branchName, $vcsCommitHash, $pullRequestNumber, $external, $dbForConsole, $getProjectDB, $request);
|
||||
} elseif ($parsedPayload["action"] == "closed") {
|
||||
// Allowed external contributions cleanup
|
||||
|
||||
$repositoryId = $parsedPayload["repositoryId"];
|
||||
$pullRequestNumber = $parsedPayload["pullRequestNumber"];
|
||||
$external = $parsedPayload["external"];
|
||||
$repositoryId = $parsedPayload["repositoryId"] ?? '';
|
||||
$pullRequestNumber = $parsedPayload["pullRequestNumber"] ?? '';
|
||||
$external = $parsedPayload["external"] ?? true;
|
||||
|
||||
if ($external) {
|
||||
$vcsRepos = $dbForConsole->find('vcsRepos', [
|
||||
|
@ -866,69 +939,6 @@ App::delete('/v1/vcs/installations/:installationId')
|
|||
$response->noContent();
|
||||
});
|
||||
|
||||
App::get('/v1/vcs/github/installations/:installationId/repositories/:repositoryId/detection')
|
||||
->desc('Detect runtime settings from source code')
|
||||
->groups(['api', 'vcs'])
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'vcs')
|
||||
->label('sdk.method', 'createRepositoryDetection')
|
||||
->label('sdk.description', '')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_DETECTION)
|
||||
->param('installationId', '', new Text(256), 'Installation Id')
|
||||
->param('repositoryId', '', new Text(256), 'Repository Id')
|
||||
->param('rootDirectoryPath', '', new Text(256), 'Path to Root Directory', true)
|
||||
->inject('gitHub')
|
||||
->inject('response')
|
||||
->inject('project')
|
||||
->inject('dbForConsole')
|
||||
->action(function (string $vcsInstallationId, string $repositoryId, string $rootDirectoryPath, GitHub $github, Response $response, Document $project, Database $dbForConsole) {
|
||||
$installation = $dbForConsole->getDocument('vcsInstallations', $vcsInstallationId, [
|
||||
Query::equal('projectInternalId', [$project->getInternalId()])
|
||||
]);
|
||||
|
||||
if ($installation->isEmpty()) {
|
||||
throw new Exception(Exception::INSTALLATION_NOT_FOUND);
|
||||
}
|
||||
|
||||
$installationId = $installation->getAttribute('installationId');
|
||||
$privateKey = App::getEnv('VCS_GITHUB_PRIVATE_KEY');
|
||||
$githubAppId = App::getEnv('VCS_GITHUB_APP_ID');
|
||||
$github->initialiseVariables($installationId, $privateKey, $githubAppId);
|
||||
|
||||
$owner = $github->getOwnerName($installationId);
|
||||
$repositoryName = $github->getRepositoryName($repositoryId);
|
||||
|
||||
if (empty($repositoryName)) {
|
||||
throw new Exception(Exception::REPOSITORY_NOT_FOUND);
|
||||
}
|
||||
|
||||
$files = $github->listRepositoryContents($owner, $repositoryName, $rootDirectoryPath);
|
||||
$languages = $github->getRepositoryLanguages($owner, $repositoryName);
|
||||
|
||||
$detectorFactory = new Detector($files, $languages);
|
||||
|
||||
$detectorFactory
|
||||
->addDetector(new JavaScript())
|
||||
->addDetector(new PHP())
|
||||
->addDetector(new Python())
|
||||
->addDetector(new Dart())
|
||||
->addDetector(new Swift())
|
||||
->addDetector(new Ruby())
|
||||
->addDetector(new Java())
|
||||
->addDetector(new CPP())
|
||||
->addDetector(new Deno())
|
||||
->addDetector(new Dotnet());
|
||||
|
||||
$runtime = $detectorFactory->detect();
|
||||
|
||||
$detection = [];
|
||||
$detection['runtime'] = $runtime;
|
||||
|
||||
$response->dynamic(new Document($detection), Response::MODEL_DETECTION);
|
||||
});
|
||||
|
||||
App::patch('/v1/vcs/github/installations/:installationId/vcsRepositories/:vcsRepositoryId')
|
||||
->desc('Authorize external deployment')
|
||||
->groups(['api', 'vcs'])
|
||||
|
@ -988,9 +998,9 @@ App::patch('/v1/vcs/github/installations/:installationId/vcsRepositories/:vcsRep
|
|||
$pullRequestResponse = $github->getPullRequest($owner, $repositoryName, $pullRequest);
|
||||
|
||||
$branchName = \explode(':', $pullRequestResponse['head']['label'])[1] ?? '';
|
||||
$SHA = $pullRequestResponse['head']['sha'] ?? '';
|
||||
$vcsCommitHash = $pullRequestResponse['head']['sha'] ?? '';
|
||||
|
||||
$createGitDeployments($github, $installationId, $vcsRepos, $branchName, $SHA, $pullRequest, true, $dbForConsole, $getProjectDB, $request);
|
||||
$createGitDeployments($github, $installationId, $vcsRepos, $branchName, $vcsCommitHash, $pullRequest, true, $dbForConsole, $getProjectDB, $request);
|
||||
|
||||
$response->noContent();
|
||||
});
|
||||
|
|
|
@ -48,9 +48,9 @@ class BuildsV1 extends Worker
|
|||
$project = new Document($this->args['project'] ?? []);
|
||||
$resource = new Document($this->args['resource'] ?? []);
|
||||
$deployment = new Document($this->args['deployment'] ?? []);
|
||||
$template = new Document($this->args['template'] ?? []);
|
||||
$SHA = $this->args['SHA'] ?? '';
|
||||
$targetUrl = $this->args['targetUrl'] ?? '';
|
||||
$vcsTemplate = new Document($this->args['vcsTemplate'] ?? []);
|
||||
$vcsCommitHash = $this->args['vcsCommitHash'] ?? '';
|
||||
$vcsTargetUrl = $this->args['vcsTargetUrl'] ?? '';
|
||||
$vcsContribution = new Document($this->args['vcsContribution'] ?? []);
|
||||
|
||||
switch ($type) {
|
||||
|
@ -58,7 +58,7 @@ class BuildsV1 extends Worker
|
|||
case BUILD_TYPE_RETRY:
|
||||
Console::info('Creating build for deployment: ' . $deployment->getId());
|
||||
$github = new GitHub($this->getCache());
|
||||
$this->buildDeployment($github, $project, $resource, $deployment, $template, $SHA, $targetUrl, $vcsContribution);
|
||||
$this->buildDeployment($github, $project, $resource, $deployment, $vcsTemplate, $vcsCommitHash, $vcsTargetUrl, $vcsContribution);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -67,7 +67,7 @@ class BuildsV1 extends Worker
|
|||
}
|
||||
}
|
||||
|
||||
protected function buildDeployment(GitHub $github, Document $project, Document $function, Document $deployment, Document $template, string $SHA = '', string $targetUrl = '', Document $vcsContribution = null)
|
||||
protected function buildDeployment(GitHub $github, Document $project, Document $function, Document $deployment, Document $vcsTemplate, string $vcsCommitHash = '', string $vcsTargetUrl = '', Document $vcsContribution = null)
|
||||
{
|
||||
global $register;
|
||||
|
||||
|
@ -185,11 +185,11 @@ class BuildsV1 extends Worker
|
|||
}
|
||||
|
||||
// Build from template
|
||||
$templateRepositoryName = $template->getAttribute('repositoryName', '');
|
||||
$templateOwnerName = $template->getAttribute('ownerName', '');
|
||||
$templateBranch = $template->getAttribute('branch', '');
|
||||
$templateRepositoryName = $vcsTemplate->getAttribute('repositoryName', '');
|
||||
$templateOwnerName = $vcsTemplate->getAttribute('ownerName', '');
|
||||
$templateBranch = $vcsTemplate->getAttribute('branch', '');
|
||||
|
||||
$templateRootDirectory = $template->getAttribute('rootDirectory', '');
|
||||
$templateRootDirectory = $vcsTemplate->getAttribute('rootDirectory', '');
|
||||
$templateRootDirectory = \rtrim($templateRootDirectory, '/');
|
||||
$templateRootDirectory = \ltrim($templateRootDirectory, '.');
|
||||
$templateRootDirectory = \ltrim($templateRootDirectory, '/');
|
||||
|
@ -221,10 +221,10 @@ class BuildsV1 extends Worker
|
|||
$exit = Console::execute('cd ' . $tmpDirectory . ' && git rev-parse HEAD', '', $stdout, $stderr);
|
||||
|
||||
if ($exit !== 0) {
|
||||
throw new \Exception('Unable to get commit SHA: ' . $stderr);
|
||||
throw new \Exception('Unable to get vcs commit SHA: ' . $stderr);
|
||||
}
|
||||
|
||||
$SHA = \trim($stdout);
|
||||
$vcsCommitHash = \trim($stdout);
|
||||
}
|
||||
|
||||
Console::execute('tar --exclude code.tar.gz -czf /tmp/builds/' . $buildId . '/code.tar.gz -C /tmp/builds/' . $buildId . '/code' . (empty($rootDirectory) ? '' : '/' . $rootDirectory) . ' .', '', $stdout, $stderr);
|
||||
|
@ -249,7 +249,7 @@ class BuildsV1 extends Worker
|
|||
$build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttribute('source', $source));
|
||||
|
||||
if ($isVcsEnabled) {
|
||||
$this->runGitAction('processing', $github, $SHA, $owner, $repositoryName, $targetUrl, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
|
||||
$this->runGitAction('processing', $github, $vcsCommitHash, $owner, $repositoryName, $vcsTargetUrl, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ class BuildsV1 extends Worker
|
|||
$build = $dbForProject->updateDocument('builds', $buildId, $build);
|
||||
|
||||
if ($isVcsEnabled) {
|
||||
$this->runGitAction('building', $github, $SHA, $owner, $repositoryName, $targetUrl, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
|
||||
$this->runGitAction('building', $github, $vcsCommitHash, $owner, $repositoryName, $vcsTargetUrl, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
|
||||
}
|
||||
|
||||
/** Trigger Webhook */
|
||||
|
@ -412,7 +412,7 @@ class BuildsV1 extends Worker
|
|||
$build->setAttribute('stdout', $response['stdout']);
|
||||
|
||||
if ($isVcsEnabled) {
|
||||
$this->runGitAction('ready', $github, $SHA, $owner, $repositoryName, $targetUrl, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
|
||||
$this->runGitAction('ready', $github, $vcsCommitHash, $owner, $repositoryName, $vcsTargetUrl, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
|
||||
}
|
||||
|
||||
Console::success("Build id: $buildId created");
|
||||
|
@ -444,7 +444,7 @@ class BuildsV1 extends Worker
|
|||
Console::error($th->getMessage());
|
||||
|
||||
if ($isVcsEnabled) {
|
||||
$this->runGitAction('failed', $github, $SHA, $owner, $repositoryName, $targetUrl, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
|
||||
$this->runGitAction('failed', $github, $vcsCommitHash, $owner, $repositoryName, $vcsTargetUrl, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
|
||||
}
|
||||
} finally {
|
||||
$build = $dbForProject->updateDocument('builds', $buildId, $build);
|
||||
|
@ -484,7 +484,7 @@ class BuildsV1 extends Worker
|
|||
}
|
||||
}
|
||||
|
||||
protected function runGitAction(string $status, GitHub $github, string $SHA, string $owner, string $repositoryName, string $targetUrl, Document $project, Document $function, string $deploymentId, Database $dbForProject, Database $dbForConsole)
|
||||
protected function runGitAction(string $status, GitHub $github, string $vcsCommitHash, string $owner, string $repositoryName, string $vcsTargetUrl, Document $project, Document $function, string $deploymentId, Database $dbForProject, Database $dbForConsole)
|
||||
{
|
||||
if ($function->getAttribute('vcsSilentMode', false) === true) {
|
||||
return;
|
||||
|
@ -493,7 +493,7 @@ class BuildsV1 extends Worker
|
|||
$deployment = $dbForProject->getDocument('deployments', $deploymentId);
|
||||
$commentId = $deployment->getAttribute('vcsCommentId', '');
|
||||
|
||||
if (!empty($SHA)) {
|
||||
if (!empty($vcsCommitHash)) {
|
||||
$message = match ($status) {
|
||||
'ready' => 'Build succeeded.',
|
||||
'failed' => 'Build failed.',
|
||||
|
@ -513,7 +513,7 @@ class BuildsV1 extends Worker
|
|||
|
||||
$name = "{$functionName} ({$projectName})";
|
||||
|
||||
$github->updateCommitStatus($repositoryName, $SHA, $owner, $state, $message, $targetUrl, $name);
|
||||
$github->updateCommitStatus($repositoryName, $vcsCommitHash, $owner, $state, $message, $vcsTargetUrl, $name);
|
||||
}
|
||||
|
||||
if (!empty($commentId)) {
|
||||
|
|
|
@ -10,9 +10,9 @@ class Build extends Event
|
|||
protected string $type = '';
|
||||
protected ?Document $resource = null;
|
||||
protected ?Document $deployment = null;
|
||||
protected ?Document $template = null;
|
||||
protected string $SHA = '';
|
||||
protected string $targetUrl = '';
|
||||
protected ?Document $vcsTemplate = null;
|
||||
protected string $vcsCommitHash = '';
|
||||
protected string $vcsTargetUrl = '';
|
||||
protected ?Document $vcsContribution = null;
|
||||
|
||||
public function __construct()
|
||||
|
@ -23,12 +23,12 @@ class Build extends Event
|
|||
/**
|
||||
* Sets template for the build event.
|
||||
*
|
||||
* @param Document $template
|
||||
* @param Document $vcsTemplate
|
||||
* @return self
|
||||
*/
|
||||
public function setTemplate(Document $template): self
|
||||
public function setVcsTemplate(Document $vcsTemplate): self
|
||||
{
|
||||
$this->template = $template;
|
||||
$this->vcsTemplate = $vcsTemplate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -36,12 +36,12 @@ class Build extends Event
|
|||
/**
|
||||
* Sets commit SHA for the build event.
|
||||
*
|
||||
* @param string $SHA is the commit hash of the incoming commit
|
||||
* @param string $vcsCommitHash is the commit hash of the incoming commit
|
||||
* @return self
|
||||
*/
|
||||
public function setSHA(string $SHA): self
|
||||
public function setVcsCommitHash(string $vcsCommitHash): self
|
||||
{
|
||||
$this->SHA = $SHA;
|
||||
$this->vcsCommitHash = $vcsCommitHash;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -49,12 +49,12 @@ class Build extends Event
|
|||
/**
|
||||
* Sets redirect target url for the deployment
|
||||
*
|
||||
* @param string $targetUrl is the url that is to be set
|
||||
* @param string $vcsTargetUrl is the url that is to be set
|
||||
* @return self
|
||||
*/
|
||||
public function setTargetUrl(string $targetUrl): self
|
||||
public function setVcsTargetUrl(string $vcsTargetUrl): self
|
||||
{
|
||||
$this->targetUrl = $targetUrl;
|
||||
$this->vcsTargetUrl = $vcsTargetUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -154,9 +154,9 @@ class Build extends Event
|
|||
'resource' => $this->resource,
|
||||
'deployment' => $this->deployment,
|
||||
'type' => $this->type,
|
||||
'template' => $this->template,
|
||||
'SHA' => $this->SHA,
|
||||
'targetUrl' => $this->targetUrl,
|
||||
'vcsTemplate' => $this->vcsTemplate,
|
||||
'vcsCommitHash' => $this->vcsCommitHash,
|
||||
'vcsTargetUrl' => $this->vcsTargetUrl,
|
||||
'vcsContribution' => $this->vcsContribution
|
||||
]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue