1
0
Fork 0
mirror of synced 2024-06-01 10:29:48 +12:00

Improve response models for console

This commit is contained in:
Matej Bačo 2023-06-18 16:08:53 +02:00
parent a174562c4e
commit 1b4036078b
12 changed files with 38 additions and 19 deletions

2
.gitmodules vendored
View file

@ -1,4 +1,4 @@
[submodule "app/console"]
path = app/console
url = https://github.com/appwrite/console
branch = feat-git-integration
branch = feat-g4

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1 +1 @@
Subproject commit 86b4fab774af168f032b38d46e610f4a02294196
Subproject commit 4129413f128d356464f935ca466d9c147f72a0a0

View file

@ -47,7 +47,7 @@ use Utopia\Database\Exception\Duplicate as DuplicateException;
include_once __DIR__ . '/../shared/api.php';
$redeployVcsLogic = function (Document $function, Document $project, Document $installation, Document $template, Database $dbForProject) {
$redeployVcsLogic = function (Document $function, Document $project, Document $installation, Database $dbForProject, Document $template) {
$deploymentId = ID::unique();
$entrypoint = $function->getAttribute('entrypoint', '');
$deployment = $dbForProject->createDocument('deployments', new Document([
@ -213,7 +213,7 @@ App::post('/v1/functions')
// Redeploy vcs logic
if (!empty($vcsRepositoryId)) {
$redeployVcsLogic($function, $project, $installation, $template, $dbForProject);
$redeployVcsLogic($function, $project, $installation, $dbForProject, $template);
}
$functionsDomain = App::getEnv('_APP_DOMAIN_FUNCTIONS', 'disabled');
@ -736,7 +736,7 @@ App::put('/v1/functions/:functionId')
// Redeploy logic
if (!$isConnected && !empty($vcsRepositoryId)) {
$redeployVcsLogic($function, $project, $installation, $dbForProject);
$redeployVcsLogic($function, $project, $installation, $dbForProject, new Document());
}
$schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId'));

View file

@ -249,9 +249,11 @@ App::get('/v1/vcs/github/installations/:installationId/repositories')
// Limit the maximum results to 5
$repos = \array_slice($repos, 0, 5);
$repos = \array_map(function ($repo) {
$repos = \array_map(function ($repo) use ($installation) {
$repo['id'] = \strval($repo['id']);
$repo['pushedAt'] = $repo['pushed_at'];
$repo['provider'] = $installation->getAttribute('provider', '');
$repo['organization'] = $installation->getAttribute('organization', '');
return new Document($repo);
}, $repos);
@ -374,6 +376,8 @@ App::get('/v1/vcs/github/installations/:installationId/repositories/:repositoryI
$repository['id'] = \strval($repository['id']);
$repository['pushedAt'] = $repository['pushed_at'];
$repository['organization'] = $installation->getAttribute('organization', '');
$repository['provider'] = $installation->getAttribute('provider', '');
$response->dynamic(new Document($repository), Response::MODEL_REPOSITORY);
});
@ -470,17 +474,20 @@ $createGitDeployments = function (GitHub $github, string $installationId, string
$owner = $github->getOwnerName($installationId);
$repositoryName = $github->getRepositoryName($repositoryId);
$comment = new Comment();
// TODO: Add all builds
$comment->addBuild($project, $function, 'waiting', $deploymentId);
if (empty($latestCommentId)) {
$comment = new Comment();
$comment->addBuild($project, $function, 'waiting', $deploymentId);
$pullRequest = $github->getBranchPullRequest($owner, $repositoryName, $branchName);
if (!empty($pullRequest)) {
$pullRequestNumber = \strval($pullRequest['number']);
$latestCommentId = $github->createComment($owner, $repositoryName, $pullRequestNumber, $comment->generateComment());
}
} else {
$comment = new Comment();
$comment->parseComment($github->getComment($owner, $repositoryName, $latestCommentId));
$comment->addBuild($project, $function, 'waiting', $deploymentId);
$latestCommentId = $github->updateComment($owner, $repositoryName, $latestCommentId, $comment->generateComment());
}
@ -508,8 +515,7 @@ $createGitDeployments = function (GitHub $github, string $installationId, string
'activate' => $activate,
]));
// TODO: Figure out port
$targetUrl = $request->getProtocol() . '://' . $request->getHostname() . ":3000/console/project-$projectId/functions/function-$functionId";
$targetUrl = $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$projectId/functions/function-$functionId";
if (!empty($SHA) && $function->getAttribute('vcsSilentMode', false) === false) {
$functionName = $function->getAttribute('name');

View file

@ -936,7 +936,7 @@ App::setResource('user', function ($mode, $project, $console, $request, $respons
if ($project->isEmpty()) {
$user = new Document(['$id' => ID::custom(''), '$collection' => 'users']);
} else {
if($project->getId() === 'console') {
if ($project->getId() === 'console') {
$user = $dbForConsole->getDocument('users', Auth::$unique);
} else {
$user = $dbForProject->getDocument('users', Auth::$unique);

View file

@ -22,6 +22,19 @@ class Repository extends Model
'default' => '',
'example' => 'appwrite',
])
->addRule('organization', [
'type' => self::TYPE_STRING,
'description' => 'Installation organization.',
'default' => [],
'example' => 'appwrite',
'array' => false,
])
->addRule('provider', [
'type' => self::TYPE_STRING,
'description' => 'Repository Installation Pame.',
'default' => '',
'example' => 'github',
])
->addRule('private', [
'type' => self::TYPE_BOOLEAN,
'description' => 'Is repository private?',