Re-add PR creation deployment
This commit is contained in:
parent
df17c8a3dc
commit
4665c2a2a4
1 changed files with 72 additions and 67 deletions
|
@ -166,37 +166,8 @@ App::get('v1/vcs/github/installations/:installationId/repositories')
|
|||
]), Response::MODEL_REPOSITORY_LIST);
|
||||
});
|
||||
|
||||
App::post('/v1/vcs/github/incomingwebhook')
|
||||
->desc('Captures GitHub Webhook Events')
|
||||
->groups(['api', 'vcs'])
|
||||
->label('scope', 'public')
|
||||
->inject('request')
|
||||
->inject('response')
|
||||
->inject('dbForConsole')
|
||||
->inject('getProjectDB')
|
||||
->action(
|
||||
function (Request $request, Response $response, Database $dbForConsole, callable $getProjectDB) {
|
||||
$event = $request->getHeader('x-github-event', '');
|
||||
$payload = $request->getRawPayload();
|
||||
$github = new GitHub();
|
||||
$privateKey = App::getEnv('VCS_GITHUB_PRIVATE_KEY');
|
||||
$githubAppId = App::getEnv('VCS_GITHUB_APP_ID');
|
||||
$parsedPayload = $github->parseWebhookEventPayload($event, $payload);
|
||||
|
||||
if ($event == $github::EVENT_PUSH) {
|
||||
$branchName = $parsedPayload["branch"];
|
||||
$repositoryId = $parsedPayload["repositoryId"];
|
||||
$installationId = $parsedPayload["installationId"];
|
||||
$SHA = $parsedPayload["SHA"];
|
||||
$owner = $parsedPayload["owner"];
|
||||
|
||||
//find functionId from functions table
|
||||
$resources = $dbForConsole->find('vcs_repos', [
|
||||
Query::equal('repositoryId', [$repositoryId]),
|
||||
Query::limit(100),
|
||||
]);
|
||||
|
||||
foreach ($resources as $resource) {
|
||||
$createGitDeployments = function (array $vcsRepos, string $branchName, string $SHA, Database $dbForConsole, callable $getProjectDB, Request $request) {
|
||||
foreach ($vcsRepos as $resource) {
|
||||
$resourceType = $resource->getAttribute('resourceType');
|
||||
|
||||
if ($resourceType === "function") {
|
||||
|
@ -216,7 +187,6 @@ App::post('/v1/vcs/github/incomingwebhook')
|
|||
$productionBranch = $resource->getAttribute('branch', 'main');
|
||||
$activate = false;
|
||||
|
||||
// TODO: Configurable in function settings
|
||||
if ($branchName == $productionBranch) {
|
||||
$activate = true;
|
||||
}
|
||||
|
@ -259,6 +229,39 @@ App::post('/v1/vcs/github/incomingwebhook')
|
|||
//TODO: Add event?
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
App::post('/v1/vcs/github/incomingwebhook')
|
||||
->desc('Captures GitHub Webhook Events')
|
||||
->groups(['api', 'vcs'])
|
||||
->label('scope', 'public')
|
||||
->inject('request')
|
||||
->inject('response')
|
||||
->inject('dbForConsole')
|
||||
->inject('getProjectDB')
|
||||
->action(
|
||||
function (Request $request, Response $response, Database $dbForConsole, callable $getProjectDB) use ($createGitDeployments) {
|
||||
$event = $request->getHeader('x-github-event', '');
|
||||
$payload = $request->getRawPayload();
|
||||
$github = new GitHub();
|
||||
$privateKey = App::getEnv('VCS_GITHUB_PRIVATE_KEY');
|
||||
$githubAppId = App::getEnv('VCS_GITHUB_APP_ID');
|
||||
$parsedPayload = $github->parseWebhookEventPayload($event, $payload);
|
||||
|
||||
if ($event == $github::EVENT_PUSH) {
|
||||
$branchName = $parsedPayload["branch"];
|
||||
$repositoryId = $parsedPayload["repositoryId"];
|
||||
$installationId = $parsedPayload["installationId"];
|
||||
$SHA = $parsedPayload["SHA"];
|
||||
$owner = $parsedPayload["owner"];
|
||||
|
||||
//find functionId from functions table
|
||||
$vcsRepos = $dbForConsole->find('vcs_repos', [
|
||||
Query::equal('repositoryId', [$repositoryId]),
|
||||
Query::limit(100),
|
||||
]);
|
||||
|
||||
$createGitDeployments($vcsRepos, $branchName, $SHA, $dbForConsole, $getProjectDB, $request);
|
||||
} elseif ($event == $github::EVENT_INSTALLATION) {
|
||||
if ($parsedPayload["action"] == "deleted") {
|
||||
// TODO: Use worker for this job instead
|
||||
|
@ -284,7 +287,6 @@ App::post('/v1/vcs/github/incomingwebhook')
|
|||
}
|
||||
} elseif ($event == $github::EVENT_PULL_REQUEST) {
|
||||
if ($parsedPayload["action"] == "opened" or $parsedPayload["action"] == "reopened") {
|
||||
$startNewDeployment = false;
|
||||
$branchName = $parsedPayload["branch"];
|
||||
$repositoryId = $parsedPayload["repositoryId"];
|
||||
$installationId = $parsedPayload["installationId"];
|
||||
|
@ -298,10 +300,13 @@ App::post('/v1/vcs/github/incomingwebhook')
|
|||
Query::orderDesc('$createdAt')
|
||||
]);
|
||||
|
||||
if (\count($vcsRepos) === 0) {
|
||||
$createGitDeployments($vcsRepos, $branchName, '', $dbForConsole, $getProjectDB, $request);
|
||||
}
|
||||
|
||||
// TODO: Use for loop instead
|
||||
$vcsRepo = $vcsRepos[0];
|
||||
|
||||
|
||||
$projectId = $vcsRepo->getAttribute('projectId');
|
||||
//TODO: Why is Authorization::skip needed?
|
||||
$project = Authorization::skip(fn () => $dbForConsole->getDocument('projects', $projectId));
|
||||
|
|
Loading…
Reference in a new issue