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

Add urls in deployment details

This commit is contained in:
Khushboo Verma 2023-08-09 23:05:23 +05:30
parent 2856077c04
commit ced6eed6fa
6 changed files with 69 additions and 21 deletions

View file

@ -2341,6 +2341,16 @@ $projectCollections = array_merge([
'required' => false,
'array' => false,
],
[
'$id' => ID::custom('providerCommitAuthorUrl'),
'type' => Database::VAR_STRING,
'signed' => true,
'size' => Database::LENGTH_KEY,
'format' => '',
'filters' => [],
'required' => false,
'array' => false,
],
[
'$id' => ID::custom('providerCommitAuthor'),
'type' => Database::VAR_STRING,
@ -2381,6 +2391,16 @@ $projectCollections = array_merge([
'required' => false,
'array' => false,
],
[
'$id' => ID::custom('providerBranchUrl'),
'type' => Database::VAR_STRING,
'signed' => true,
'size' => Database::LENGTH_KEY,
'format' => '',
'filters' => [],
'required' => false,
'array' => false,
],
[
'$id' => ID::custom('providerRootDirectory'),
'type' => Database::VAR_STRING,

View file

@ -56,12 +56,14 @@ $redeployVcs = function (Request $request, Document $function, Document $project
$providerInstallationId = $installation->getAttribute('providerInstallationId', '');
$privateKey = App::getEnv('_APP_VCS_GITHUB_PRIVATE_KEY');
$githubAppId = App::getEnv('_APP_VCS_GITHUB_APP_ID');
$github->initialiseVariables($providerInstallationId, $privateKey, $githubAppId);
$github->initializeVariables($providerInstallationId, $privateKey, $githubAppId);
$owner = $github->getOwnerName($providerInstallationId);
$providerRepositoryId = $function->getAttribute('providerRepositoryId', '');
$repositoryName = $github->getRepositoryName($providerRepositoryId);
$providerBranch = $function->getAttribute('providerBranch', 'main');
$repositoryUrl = "https://github.com/$owner/$repositoryName/tree/$providerBranch";
$authorUrl = "https://github.com/$owner";
$repositoryUrl = "https://github.com/$owner/$repositoryName";
$branchUrl = "https://github.com/$owner/$repositoryName/tree/$providerBranch";
$commitDetails = $github->getLatestCommit($owner, $repositoryName, $providerBranch);
$deployment = $dbForProject->createDocument('deployments', new Document([
@ -81,10 +83,12 @@ $redeployVcs = function (Request $request, Document $function, Document $project
'providerRepositoryId' => $providerRepositoryId,
'repositoryId' => $function->getAttribute('repositoryId', ''),
'repositoryInternalId' => $function->getAttribute('repositoryInternalId', ''),
'providerBranchUrl' => $branchUrl,
'providerRepositoryName' => $repositoryName,
'providerRepositoryOwner' => $owner,
'providerRepositoryUrl' => $repositoryUrl,
'providerCommitHash' => $commitDetails['commitHash'] ?? '',
'providerCommitAuthorUrl' => $authorUrl,
'providerCommitAuthor' => $commitDetails['commitAuthor'] ?? '',
'providerCommitMessage' => $commitDetails['commitMessage'] ?? '',
'providerCommitUrl' => $commitDetails['commitUrl'] ?? '',
@ -93,6 +97,7 @@ $redeployVcs = function (Request $request, Document $function, Document $project
'search' => implode(' ', [$deploymentId, $entrypoint]),
'activate' => true,
]));
var_dump($deployment);
$projectId = $project->getId();
$functionId = $function->getId();

View file

@ -38,7 +38,7 @@ use Utopia\Validator\Boolean;
use function Swoole\Coroutine\batch;
$createGitDeployments = function (GitHub $github, string $providerInstallationId, array $repositories, string $providerBranch, string $providerRepositoryName, string $providerRepositoryUrl, string $providerRepositoryOwner, string $providerCommitHash, string $providerCommitAuthor, string $providerCommitMessage, string $providerCommitUrl, string $providerPullRequestId, bool $external, Database $dbForConsole, callable $getProjectDB, Request $request) {
$createGitDeployments = function (GitHub $github, string $providerInstallationId, array $repositories, string $providerBranch, string $providerBranchUrl, string $providerRepositoryName, string $providerRepositoryUrl, string $providerRepositoryOwner, string $providerCommitHash, string $providerCommitAuthor, string $providerCommitAuthorUrl, string $providerCommitMessage, string $providerCommitUrl, string $providerPullRequestId, bool $external, Database $dbForConsole, callable $getProjectDB, Request $request) {
foreach ($repositories as $resource) {
$resourceType = $resource->getAttribute('resourceType');
@ -186,10 +186,12 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId
'providerRepositoryId' => $providerRepositoryId,
'repositoryId' => $repositoryId,
'repositoryInternalId' => $repositoryInternalId,
'providerBranchUrl' => $providerBranchUrl,
'providerRepositoryName' => $providerRepositoryName,
'providerRepositoryOwner' => $providerRepositoryOwner,
'providerRepositoryUrl' => $providerRepositoryUrl,
'providerCommitHash' => $providerCommitHash,
'providerCommitAuthorUrl' => $providerCommitAuthorUrl,
'providerCommitAuthor' => $providerCommitAuthor,
'providerCommitMessage' => $providerCommitMessage,
'providerCommitUrl' => $providerCommitUrl,
@ -386,7 +388,7 @@ App::get('/v1/vcs/github/callback')
if (!empty($providerInstallationId)) {
$privateKey = App::getEnv('_APP_VCS_GITHUB_PRIVATE_KEY');
$githubAppId = App::getEnv('_APP_VCS_GITHUB_APP_ID');
$github->initialiseVariables($providerInstallationId, $privateKey, $githubAppId);
$github->initializeVariables($providerInstallationId, $privateKey, $githubAppId);
$owner = $github->getOwnerName($providerInstallationId) ?? '';
$projectInternalId = $project->getInternalId();
@ -472,7 +474,7 @@ App::post('/v1/vcs/github/installations/:installationId/providerRepositories/:pr
$providerInstallationId = $installation->getAttribute('providerInstallationId');
$privateKey = App::getEnv('_APP_VCS_GITHUB_PRIVATE_KEY');
$githubAppId = App::getEnv('_APP_VCS_GITHUB_APP_ID');
$github->initialiseVariables($providerInstallationId, $privateKey, $githubAppId);
$github->initializeVariables($providerInstallationId, $privateKey, $githubAppId);
$owner = $github->getOwnerName($providerInstallationId);
$repositoryName = $github->getRepositoryName($providerRepositoryId);
@ -482,7 +484,7 @@ App::post('/v1/vcs/github/installations/:installationId/providerRepositories/:pr
}
$files = $github->listRepositoryContents($owner, $repositoryName, $providerRootDirectory);
$languages = $github->getRepositoryLanguages($owner, $repositoryName);
$languages = $github->listRepositoryLanguages($owner, $repositoryName);
$detectorFactory = new Detector($files, $languages);
@ -543,13 +545,13 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories')
$providerInstallationId = $installation->getAttribute('providerInstallationId');
$privateKey = App::getEnv('_APP_VCS_GITHUB_PRIVATE_KEY');
$githubAppId = App::getEnv('_APP_VCS_GITHUB_APP_ID');
$github->initialiseVariables($providerInstallationId, $privateKey, $githubAppId);
$github->initializeVariables($providerInstallationId, $privateKey, $githubAppId);
$page = 1;
$perPage = 100;
$loadPage = function ($page) use ($github, $perPage) {
$repos = $github->listRepositoriesForVCSApp($page, $perPage);
$repos = $github->listRepositories($page, $perPage);
return $repos;
};
@ -606,7 +608,7 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories')
return function () use ($repo, $github) {
try {
$files = $github->listRepositoryContents($repo['organization'], $repo['name'], '');
$languages = $github->getRepositoryLanguages($repo['organization'], $repo['name']);
$languages = $github->listRepositoryLanguages($repo['organization'], $repo['name']);
$detectorFactory = new Detector($files, $languages);
@ -716,7 +718,7 @@ App::post('/v1/vcs/github/installations/:installationId/providerRepositories')
$providerInstallationId = $installation->getAttribute('providerInstallationId');
$privateKey = App::getEnv('_APP_VCS_GITHUB_PRIVATE_KEY');
$githubAppId = App::getEnv('_APP_VCS_GITHUB_APP_ID');
$github->initialiseVariables($providerInstallationId, $privateKey, $githubAppId);
$github->initializeVariables($providerInstallationId, $privateKey, $githubAppId);
$owner = $github->getOwnerName($providerInstallationId);
$repository = $github->createRepository($owner, $name, $private);
@ -770,7 +772,7 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories/:pro
$providerInstallationId = $installation->getAttribute('providerInstallationId');
$privateKey = App::getEnv('_APP_VCS_GITHUB_PRIVATE_KEY');
$githubAppId = App::getEnv('_APP_VCS_GITHUB_APP_ID');
$github->initialiseVariables($providerInstallationId, $privateKey, $githubAppId);
$github->initializeVariables($providerInstallationId, $privateKey, $githubAppId);
$owner = $github->getOwnerName($providerInstallationId) ?? '';
$repositoryName = $github->getRepositoryName($providerRepositoryId) ?? '';
@ -817,7 +819,7 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories/:pro
$providerInstallationId = $installation->getAttribute('providerInstallationId');
$privateKey = App::getEnv('_APP_VCS_GITHUB_PRIVATE_KEY');
$githubAppId = App::getEnv('_APP_VCS_GITHUB_APP_ID');
$github->initialiseVariables($providerInstallationId, $privateKey, $githubAppId);
$github->initializeVariables($providerInstallationId, $privateKey, $githubAppId);
$owner = $github->getOwnerName($providerInstallationId) ?? '';
$repositoryName = $github->getRepositoryName($providerRepositoryId) ?? '';
@ -865,6 +867,7 @@ App::post('/v1/vcs/github/events')
if ($event == $github::EVENT_PUSH) {
$providerBranchCreated = $parsedPayload["created"] ?? false;
$providerBranch = $parsedPayload["branch"] ?? '';
$providerBranchUrl = $parsedPayload["branchUrl"] ?? '';
$providerRepositoryId = $parsedPayload["repositoryId"] ?? '';
$providerRepositoryName = $parsedPayload["repositoryName"] ?? '';
$providerInstallationId = $parsedPayload["installationId"] ?? '';
@ -872,10 +875,11 @@ App::post('/v1/vcs/github/events')
$providerCommitHash = $parsedPayload["commitHash"] ?? '';
$providerRepositoryOwner = $parsedPayload["owner"] ?? '';
$providerCommitAuthor = $parsedPayload["headCommitAuthor"] ?? '';
$providerCommitAuthorUrl = $parsedPayload["authorUrl"] ?? '';
$providerCommitMessage = $parsedPayload["headCommitMessage"] ?? '';
$providerCommitUrl = $parsedPayload["headCommitUrl"] ?? '';
$github->initialiseVariables($providerInstallationId, $privateKey, $githubAppId);
$github->initializeVariables($providerInstallationId, $privateKey, $githubAppId);
//find functionId from functions table
$repositories = $dbForConsole->find('repositories', [
@ -885,7 +889,7 @@ App::post('/v1/vcs/github/events')
// create new deployment only on push and not when branch is created
if (!$providerBranchCreated) {
$createGitDeployments($github, $providerInstallationId, $repositories, $providerBranch, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthor, $providerCommitMessage, $providerCommitUrl, '', false, $dbForConsole, $getProjectDB, $request);
$createGitDeployments($github, $providerInstallationId, $repositories, $providerBranch, $providerBranchUrl, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthor, $providerCommitAuthorUrl, $providerCommitMessage, $providerCommitUrl, '', false, $dbForConsole, $getProjectDB, $request);
}
} elseif ($event == $github::EVENT_INSTALLATION) {
if ($parsedPayload["action"] == "deleted") {
@ -913,6 +917,7 @@ App::post('/v1/vcs/github/events')
} elseif ($event == $github::EVENT_PULL_REQUEST) {
if ($parsedPayload["action"] == "opened" || $parsedPayload["action"] == "reopened" || $parsedPayload["action"] == "synchronize") {
$providerBranch = $parsedPayload["branch"] ?? '';
$providerBranchUrl = $parsedPayload["branchUrl"] ?? '';
$providerRepositoryId = $parsedPayload["repositoryId"] ?? '';
$providerRepositoryName = $parsedPayload["repositoryName"] ?? '';
$providerInstallationId = $parsedPayload["installationId"] ?? '';
@ -922,13 +927,14 @@ App::post('/v1/vcs/github/events')
$providerRepositoryOwner = $parsedPayload["owner"] ?? '';
$external = $parsedPayload["external"] ?? true;
$providerCommitUrl = $parsedPayload["headCommitUrl"] ?? '';
$providerCommitAuthorUrl = $parsedPayload["authorUrl"] ?? '';
// Ignore sync for non-external. We handle it in push webhook
if (!$external && $parsedPayload["action"] == "synchronize") {
return $response->json($parsedPayload);
}
$github->initialiseVariables($providerInstallationId, $privateKey, $githubAppId);
$github->initializeVariables($providerInstallationId, $privateKey, $githubAppId);
$commitDetails = $github->getCommit($providerRepositoryOwner, $providerRepositoryName, $providerCommitHash);
$providerCommitAuthor = $commitDetails["commitAuthor"] ?? '';
@ -939,7 +945,7 @@ App::post('/v1/vcs/github/events')
Query::orderDesc('$createdAt')
]);
$createGitDeployments($github, $providerInstallationId, $repositories, $providerBranch, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthor, $providerCommitMessage, $providerCommitUrl, $providerPullRequestId, $external, $dbForConsole, $getProjectDB, $request);
$createGitDeployments($github, $providerInstallationId, $repositories, $providerBranch, $providerBranchUrl, $providerRepositoryName, $providerRepositoryUrl, $providerRepositoryOwner, $providerCommitHash, $providerCommitAuthor, $providerCommitAuthorUrl, $providerCommitMessage, $providerCommitUrl, $providerPullRequestId, $external, $dbForConsole, $getProjectDB, $request);
} elseif ($parsedPayload["action"] == "closed") {
// Allowed external contributions cleanup
@ -1135,7 +1141,7 @@ App::patch('/v1/vcs/github/installations/:installationId/repositories/:repositor
$privateKey = App::getEnv('_APP_VCS_GITHUB_PRIVATE_KEY');
$githubAppId = App::getEnv('_APP_VCS_GITHUB_APP_ID');
$providerInstallationId = $installation->getAttribute('providerInstallationId');
$github->initialiseVariables($providerInstallationId, $privateKey, $githubAppId);
$github->initializeVariables($providerInstallationId, $privateKey, $githubAppId);
$repositories = [$repository];
$providerRepositoryId = $repository->getAttribute('providerRepositoryId');

View file

@ -171,7 +171,7 @@ class BuildsV1 extends Worker
$rootDirectory = \ltrim($rootDirectory, '.');
$rootDirectory = \ltrim($rootDirectory, '/');
$github->initialiseVariables($providerInstallationId, $privateKey, $githubAppId);
$github->initializeVariables($providerInstallationId, $privateKey, $githubAppId);
$owner = $github->getOwnerName($providerInstallationId);
$repositoryName = $github->getRepositoryName($providerRepositoryId);

4
composer.lock generated
View file

@ -2463,7 +2463,7 @@
"source": {
"type": "git",
"url": "https://github.com/utopia-php/vcs.git",
"reference": "6ee80b55a3cef5a8d29ab6a9b2af2db278789e38"
"reference": "9f1665cb7818a05adf77c17972e560c2e43b7974"
},
"require": {
"adhocore/jwt": "^1.1",
@ -2512,7 +2512,7 @@
"utopia",
"vcs"
],
"time": "2023-08-09T15:07:12+00:00"
"time": "2023-08-09T17:22:48+00:00"
},
{
"name": "utopia-php/websocket",

View file

@ -106,6 +106,12 @@ class Deployment extends Model
'default' => '',
'example' => '7c3f25d',
])
->addRule('providerCommitAuthorUrl', [
'type' => self::TYPE_STRING,
'description' => 'The url of vcs commit author',
'default' => '',
'example' => 'https://github.com/vermakhushboo',
])
->addRule('providerCommitAuthor', [
'type' => self::TYPE_STRING,
'description' => 'The name of vcs commit author',
@ -124,7 +130,18 @@ class Deployment extends Model
'default' => '',
'example' => 'https://github.com/vermakhushboo/g4-node-function/commit/60c0416257a9cbcdd96b2d370c38d8f8d150ccfb',
])
;
->addRule('providerBranch', [
'type' => self::TYPE_STRING,
'description' => 'The branch of the vcs repository',
'default' => '',
'example' => '0.7.x',
])
->addRule('providerBranchUrl', [
'type' => self::TYPE_STRING,
'description' => 'The branch of the vcs repository',
'default' => '',
'example' => 'https://github.com/vermakhushboo/appwrite/tree/0.7.x',
]);
}
/**