From 6e16340f16c7388e3e2fdfe1c73659052d392c11 Mon Sep 17 00:00:00 2001 From: Atharva Deosthale Date: Sat, 13 Sep 2025 17:56:19 +0530 Subject: [PATCH 01/13] feat: add branch deployments to appwrite --- .../specs/open-api3-latest-console.json | 151 ++++++++++-- app/config/specs/open-api3-latest-server.json | 126 ++++++++-- app/config/specs/swagger2-latest-console.json | 159 ++++++++++-- app/config/specs/swagger2-latest-server.json | 134 ++++++++-- .../Modules/Functions/Workers/Builds.php | 12 +- .../Sites/Http/Deployments/Direct/Create.php | 231 ++++++++++++++++++ .../Platform/Modules/Sites/Services/Http.php | 2 + 7 files changed, 731 insertions(+), 84 deletions(-) create mode 100644 src/Appwrite/Platform/Modules/Sites/Http/Deployments/Direct/Create.php diff --git a/app/config/specs/open-api3-latest-console.json b/app/config/specs/open-api3-latest-console.json index 02d97fffc7..0de652e3fb 100644 --- a/app/config/specs/open-api3-latest-console.json +++ b/app/config/specs/open-api3-latest-console.json @@ -4888,7 +4888,7 @@ "x-appwrite": { "method": "getResource", "group": null, - "weight": 496, + "weight": 497, "cookies": false, "type": "", "demo": "console\/get-resource.md", @@ -28209,7 +28209,7 @@ "x-appwrite": { "method": "listRules", "group": null, - "weight": 502, + "weight": 503, "cookies": false, "type": "", "demo": "proxy\/list-rules.md", @@ -28283,7 +28283,7 @@ "x-appwrite": { "method": "createAPIRule", "group": null, - "weight": 497, + "weight": 498, "cookies": false, "type": "", "demo": "proxy\/create-api-rule.md", @@ -28350,7 +28350,7 @@ "x-appwrite": { "method": "createFunctionRule", "group": null, - "weight": 499, + "weight": 500, "cookies": false, "type": "", "demo": "proxy\/create-function-rule.md", @@ -28428,7 +28428,7 @@ "x-appwrite": { "method": "createRedirectRule", "group": null, - "weight": 500, + "weight": 501, "cookies": false, "type": "", "demo": "proxy\/create-redirect-rule.md", @@ -28541,7 +28541,7 @@ "x-appwrite": { "method": "createSiteRule", "group": null, - "weight": 498, + "weight": 499, "cookies": false, "type": "", "demo": "proxy\/create-site-rule.md", @@ -28619,7 +28619,7 @@ "x-appwrite": { "method": "getRule", "group": null, - "weight": 501, + "weight": 502, "cookies": false, "type": "", "demo": "proxy\/get-rule.md", @@ -28670,7 +28670,7 @@ "x-appwrite": { "method": "deleteRule", "group": null, - "weight": 503, + "weight": 504, "cookies": false, "type": "", "demo": "proxy\/delete-rule.md", @@ -28730,7 +28730,7 @@ "x-appwrite": { "method": "updateRuleVerification", "group": null, - "weight": 504, + "weight": 505, "cookies": false, "type": "", "demo": "proxy\/update-rule-verification.md", @@ -29085,6 +29085,103 @@ } } }, + "\/sites\/direct": { + "post": { + "summary": "Create direct deployment", + "operationId": "sitesCreateDirectDeployment", + "tags": [ + "sites" + ], + "description": "Create a deployment directly from a repository branch.", + "responses": { + "202": { + "description": "Deployment", + "content": { + "application\/json": { + "schema": { + "$ref": "#\/components\/schemas\/deployment" + } + } + } + } + }, + "deprecated": false, + "x-appwrite": { + "method": "createDirectDeployment", + "group": "deployments", + "weight": 483, + "cookies": false, + "type": "", + "demo": "sites\/create-direct-deployment.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterCreate a deployment directly from a repository branch.", + "rate-limit": 0, + "rate-time": 3600, + "rate-key": "url:{url},ip:{ip}", + "scope": "sites.write", + "platforms": [ + "server" + ], + "packaging": false, + "auth": { + "Project": [] + } + }, + "security": [ + { + "Project": [], + "Key": [] + } + ], + "requestBody": { + "content": { + "application\/json": { + "schema": { + "type": "object", + "properties": { + "siteId": { + "type": "string", + "description": "Site ID.", + "x-example": "" + }, + "repository": { + "type": "string", + "description": "Repository name of the template.", + "x-example": "" + }, + "owner": { + "type": "string", + "description": "The name of the owner of the template.", + "x-example": "" + }, + "rootDirectory": { + "type": "string", + "description": "Path to site code in the template repo.", + "x-example": "" + }, + "branch": { + "type": "string", + "description": "Branch to create deployment from.", + "x-example": "" + }, + "activate": { + "type": "boolean", + "description": "Automatically activate the deployment when it is finished building.", + "x-example": false + } + }, + "required": [ + "siteId", + "repository", + "owner", + "rootDirectory", + "branch" + ] + } + } + } + } + } + }, "\/sites\/frameworks": { "get": { "summary": "List frameworks", @@ -29158,7 +29255,7 @@ "x-appwrite": { "method": "listSpecifications", "group": "frameworks", - "weight": 495, + "weight": 496, "cookies": false, "type": "", "demo": "sites\/list-specifications.md", @@ -29208,7 +29305,7 @@ "x-appwrite": { "method": "listTemplates", "group": "templates", - "weight": 491, + "weight": 492, "cookies": false, "type": "", "demo": "sites\/list-templates.md", @@ -29308,7 +29405,7 @@ "x-appwrite": { "method": "getTemplate", "group": "templates", - "weight": 492, + "weight": 493, "cookies": false, "type": "", "demo": "sites\/get-template.md", @@ -29368,7 +29465,7 @@ "x-appwrite": { "method": "listUsage", "group": null, - "weight": 493, + "weight": 494, "cookies": false, "type": "", "demo": "sites\/list-usage.md", @@ -30637,7 +30734,7 @@ "x-appwrite": { "method": "listLogs", "group": "logs", - "weight": 484, + "weight": 485, "cookies": false, "type": "", "demo": "sites\/list-logs.md", @@ -30708,7 +30805,7 @@ "x-appwrite": { "method": "getLog", "group": "logs", - "weight": 483, + "weight": 484, "cookies": false, "type": "", "demo": "sites\/get-log.md", @@ -30770,7 +30867,7 @@ "x-appwrite": { "method": "deleteLog", "group": "logs", - "weight": 485, + "weight": 486, "cookies": false, "type": "", "demo": "sites\/delete-log.md", @@ -30841,7 +30938,7 @@ "x-appwrite": { "method": "getUsage", "group": null, - "weight": 494, + "weight": 495, "cookies": false, "type": "", "demo": "sites\/get-usage.md", @@ -30923,7 +31020,7 @@ "x-appwrite": { "method": "listVariables", "group": "variables", - "weight": 488, + "weight": 489, "cookies": false, "type": "", "demo": "sites\/list-variables.md", @@ -30982,7 +31079,7 @@ "x-appwrite": { "method": "createVariable", "group": "variables", - "weight": 486, + "weight": 487, "cookies": false, "type": "", "demo": "sites\/create-variable.md", @@ -31073,7 +31170,7 @@ "x-appwrite": { "method": "getVariable", "group": "variables", - "weight": 487, + "weight": 488, "cookies": false, "type": "", "demo": "sites\/get-variable.md", @@ -31142,7 +31239,7 @@ "x-appwrite": { "method": "updateVariable", "group": "variables", - "weight": 489, + "weight": 490, "cookies": false, "type": "", "demo": "sites\/update-variable.md", @@ -31233,7 +31330,7 @@ "x-appwrite": { "method": "deleteVariable", "group": "variables", - "weight": 490, + "weight": 491, "cookies": false, "type": "", "demo": "sites\/delete-variable.md", @@ -39984,7 +40081,7 @@ "x-appwrite": { "method": "list", "group": "files", - "weight": 507, + "weight": 508, "cookies": false, "type": "", "demo": "tokens\/list.md", @@ -40064,7 +40161,7 @@ "x-appwrite": { "method": "createFileToken", "group": "files", - "weight": 505, + "weight": 506, "cookies": false, "type": "", "demo": "tokens\/create-file-token.md", @@ -40153,7 +40250,7 @@ "x-appwrite": { "method": "get", "group": "tokens", - "weight": 506, + "weight": 507, "cookies": false, "type": "", "demo": "tokens\/get.md", @@ -40213,7 +40310,7 @@ "x-appwrite": { "method": "update", "group": "tokens", - "weight": 508, + "weight": 509, "cookies": false, "type": "", "demo": "tokens\/update.md", @@ -40283,7 +40380,7 @@ "x-appwrite": { "method": "delete", "group": "tokens", - "weight": 509, + "weight": 510, "cookies": false, "type": "", "demo": "tokens\/delete.md", diff --git a/app/config/specs/open-api3-latest-server.json b/app/config/specs/open-api3-latest-server.json index 09d53dbdf0..d8d7178eb2 100644 --- a/app/config/specs/open-api3-latest-server.json +++ b/app/config/specs/open-api3-latest-server.json @@ -20014,6 +20014,104 @@ } } }, + "\/sites\/direct": { + "post": { + "summary": "Create direct deployment", + "operationId": "sitesCreateDirectDeployment", + "tags": [ + "sites" + ], + "description": "Create a deployment directly from a repository branch.", + "responses": { + "202": { + "description": "Deployment", + "content": { + "application\/json": { + "schema": { + "$ref": "#\/components\/schemas\/deployment" + } + } + } + } + }, + "deprecated": false, + "x-appwrite": { + "method": "createDirectDeployment", + "group": "deployments", + "weight": 483, + "cookies": false, + "type": "", + "demo": "sites\/create-direct-deployment.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterCreate a deployment directly from a repository branch.", + "rate-limit": 0, + "rate-time": 3600, + "rate-key": "url:{url},ip:{ip}", + "scope": "sites.write", + "platforms": [ + "server" + ], + "packaging": false, + "auth": { + "Project": [], + "Key": [] + } + }, + "security": [ + { + "Project": [], + "Key": [] + } + ], + "requestBody": { + "content": { + "application\/json": { + "schema": { + "type": "object", + "properties": { + "siteId": { + "type": "string", + "description": "Site ID.", + "x-example": "" + }, + "repository": { + "type": "string", + "description": "Repository name of the template.", + "x-example": "" + }, + "owner": { + "type": "string", + "description": "The name of the owner of the template.", + "x-example": "" + }, + "rootDirectory": { + "type": "string", + "description": "Path to site code in the template repo.", + "x-example": "" + }, + "branch": { + "type": "string", + "description": "Branch to create deployment from.", + "x-example": "" + }, + "activate": { + "type": "boolean", + "description": "Automatically activate the deployment when it is finished building.", + "x-example": false + } + }, + "required": [ + "siteId", + "repository", + "owner", + "rootDirectory", + "branch" + ] + } + } + } + } + } + }, "\/sites\/frameworks": { "get": { "summary": "List frameworks", @@ -20088,7 +20186,7 @@ "x-appwrite": { "method": "listSpecifications", "group": "frameworks", - "weight": 495, + "weight": 496, "cookies": false, "type": "", "demo": "sites\/list-specifications.md", @@ -21349,7 +21447,7 @@ "x-appwrite": { "method": "listLogs", "group": "logs", - "weight": 484, + "weight": 485, "cookies": false, "type": "", "demo": "sites\/list-logs.md", @@ -21421,7 +21519,7 @@ "x-appwrite": { "method": "getLog", "group": "logs", - "weight": 483, + "weight": 484, "cookies": false, "type": "", "demo": "sites\/get-log.md", @@ -21484,7 +21582,7 @@ "x-appwrite": { "method": "deleteLog", "group": "logs", - "weight": 485, + "weight": 486, "cookies": false, "type": "", "demo": "sites\/delete-log.md", @@ -21556,7 +21654,7 @@ "x-appwrite": { "method": "listVariables", "group": "variables", - "weight": 488, + "weight": 489, "cookies": false, "type": "", "demo": "sites\/list-variables.md", @@ -21616,7 +21714,7 @@ "x-appwrite": { "method": "createVariable", "group": "variables", - "weight": 486, + "weight": 487, "cookies": false, "type": "", "demo": "sites\/create-variable.md", @@ -21708,7 +21806,7 @@ "x-appwrite": { "method": "getVariable", "group": "variables", - "weight": 487, + "weight": 488, "cookies": false, "type": "", "demo": "sites\/get-variable.md", @@ -21778,7 +21876,7 @@ "x-appwrite": { "method": "updateVariable", "group": "variables", - "weight": 489, + "weight": 490, "cookies": false, "type": "", "demo": "sites\/update-variable.md", @@ -21870,7 +21968,7 @@ "x-appwrite": { "method": "deleteVariable", "group": "variables", - "weight": 490, + "weight": 491, "cookies": false, "type": "", "demo": "sites\/delete-variable.md", @@ -30024,7 +30122,7 @@ "x-appwrite": { "method": "list", "group": "files", - "weight": 507, + "weight": 508, "cookies": false, "type": "", "demo": "tokens\/list.md", @@ -30105,7 +30203,7 @@ "x-appwrite": { "method": "createFileToken", "group": "files", - "weight": 505, + "weight": 506, "cookies": false, "type": "", "demo": "tokens\/create-file-token.md", @@ -30195,7 +30293,7 @@ "x-appwrite": { "method": "get", "group": "tokens", - "weight": 506, + "weight": 507, "cookies": false, "type": "", "demo": "tokens\/get.md", @@ -30256,7 +30354,7 @@ "x-appwrite": { "method": "update", "group": "tokens", - "weight": 508, + "weight": 509, "cookies": false, "type": "", "demo": "tokens\/update.md", @@ -30327,7 +30425,7 @@ "x-appwrite": { "method": "delete", "group": "tokens", - "weight": 509, + "weight": 510, "cookies": false, "type": "", "demo": "tokens\/delete.md", diff --git a/app/config/specs/swagger2-latest-console.json b/app/config/specs/swagger2-latest-console.json index 6d5721c73b..22823cd40e 100644 --- a/app/config/specs/swagger2-latest-console.json +++ b/app/config/specs/swagger2-latest-console.json @@ -5052,7 +5052,7 @@ "x-appwrite": { "method": "getResource", "group": null, - "weight": 496, + "weight": 497, "cookies": false, "type": "", "demo": "console\/get-resource.md", @@ -28351,7 +28351,7 @@ "x-appwrite": { "method": "listRules", "group": null, - "weight": 502, + "weight": 503, "cookies": false, "type": "", "demo": "proxy\/list-rules.md", @@ -28424,7 +28424,7 @@ "x-appwrite": { "method": "createAPIRule", "group": null, - "weight": 497, + "weight": 498, "cookies": false, "type": "", "demo": "proxy\/create-api-rule.md", @@ -28494,7 +28494,7 @@ "x-appwrite": { "method": "createFunctionRule", "group": null, - "weight": 499, + "weight": 500, "cookies": false, "type": "", "demo": "proxy\/create-function-rule.md", @@ -28577,7 +28577,7 @@ "x-appwrite": { "method": "createRedirectRule", "group": null, - "weight": 500, + "weight": 501, "cookies": false, "type": "", "demo": "proxy\/create-redirect-rule.md", @@ -28697,7 +28697,7 @@ "x-appwrite": { "method": "createSiteRule", "group": null, - "weight": 498, + "weight": 499, "cookies": false, "type": "", "demo": "proxy\/create-site-rule.md", @@ -28778,7 +28778,7 @@ "x-appwrite": { "method": "getRule", "group": null, - "weight": 501, + "weight": 502, "cookies": false, "type": "", "demo": "proxy\/get-rule.md", @@ -28831,7 +28831,7 @@ "x-appwrite": { "method": "deleteRule", "group": null, - "weight": 503, + "weight": 504, "cookies": false, "type": "", "demo": "proxy\/delete-rule.md", @@ -28891,7 +28891,7 @@ "x-appwrite": { "method": "updateRuleVerification", "group": null, - "weight": 504, + "weight": 505, "cookies": false, "type": "", "demo": "proxy\/update-rule-verification.md", @@ -29264,6 +29264,111 @@ ] } }, + "\/sites\/direct": { + "post": { + "summary": "Create direct deployment", + "operationId": "sitesCreateDirectDeployment", + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "sites" + ], + "description": "Create a deployment directly from a repository branch.", + "responses": { + "202": { + "description": "Deployment", + "schema": { + "$ref": "#\/definitions\/deployment" + } + } + }, + "deprecated": false, + "x-appwrite": { + "method": "createDirectDeployment", + "group": "deployments", + "weight": 483, + "cookies": false, + "type": "", + "demo": "sites\/create-direct-deployment.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterCreate a deployment directly from a repository branch.", + "rate-limit": 0, + "rate-time": 3600, + "rate-key": "url:{url},ip:{ip}", + "scope": "sites.write", + "platforms": [ + "server" + ], + "packaging": false, + "auth": { + "Project": [] + } + }, + "security": [ + { + "Project": [], + "Key": [] + } + ], + "parameters": [ + { + "name": "payload", + "in": "body", + "schema": { + "type": "object", + "properties": { + "siteId": { + "type": "string", + "description": "Site ID.", + "default": null, + "x-example": "" + }, + "repository": { + "type": "string", + "description": "Repository name of the template.", + "default": null, + "x-example": "" + }, + "owner": { + "type": "string", + "description": "The name of the owner of the template.", + "default": null, + "x-example": "" + }, + "rootDirectory": { + "type": "string", + "description": "Path to site code in the template repo.", + "default": null, + "x-example": "" + }, + "branch": { + "type": "string", + "description": "Branch to create deployment from.", + "default": null, + "x-example": "" + }, + "activate": { + "type": "boolean", + "description": "Automatically activate the deployment when it is finished building.", + "default": true, + "x-example": false + } + }, + "required": [ + "siteId", + "repository", + "owner", + "rootDirectory", + "branch" + ] + } + } + ] + } + }, "\/sites\/frameworks": { "get": { "summary": "List frameworks", @@ -29337,7 +29442,7 @@ "x-appwrite": { "method": "listSpecifications", "group": "frameworks", - "weight": 495, + "weight": 496, "cookies": false, "type": "", "demo": "sites\/list-specifications.md", @@ -29387,7 +29492,7 @@ "x-appwrite": { "method": "listTemplates", "group": "templates", - "weight": 491, + "weight": 492, "cookies": false, "type": "", "demo": "sites\/list-templates.md", @@ -29481,7 +29586,7 @@ "x-appwrite": { "method": "getTemplate", "group": "templates", - "weight": 492, + "weight": 493, "cookies": false, "type": "", "demo": "sites\/get-template.md", @@ -29539,7 +29644,7 @@ "x-appwrite": { "method": "listUsage", "group": null, - "weight": 493, + "weight": 494, "cookies": false, "type": "", "demo": "sites\/list-usage.md", @@ -30811,7 +30916,7 @@ "x-appwrite": { "method": "listLogs", "group": "logs", - "weight": 484, + "weight": 485, "cookies": false, "type": "", "demo": "sites\/list-logs.md", @@ -30882,7 +30987,7 @@ "x-appwrite": { "method": "getLog", "group": "logs", - "weight": 483, + "weight": 484, "cookies": false, "type": "", "demo": "sites\/get-log.md", @@ -30946,7 +31051,7 @@ "x-appwrite": { "method": "deleteLog", "group": "logs", - "weight": 485, + "weight": 486, "cookies": false, "type": "", "demo": "sites\/delete-log.md", @@ -31013,7 +31118,7 @@ "x-appwrite": { "method": "getUsage", "group": null, - "weight": 494, + "weight": 495, "cookies": false, "type": "", "demo": "sites\/get-usage.md", @@ -31091,7 +31196,7 @@ "x-appwrite": { "method": "listVariables", "group": "variables", - "weight": 488, + "weight": 489, "cookies": false, "type": "", "demo": "sites\/list-variables.md", @@ -31150,7 +31255,7 @@ "x-appwrite": { "method": "createVariable", "group": "variables", - "weight": 486, + "weight": 487, "cookies": false, "type": "", "demo": "sites\/create-variable.md", @@ -31240,7 +31345,7 @@ "x-appwrite": { "method": "getVariable", "group": "variables", - "weight": 487, + "weight": 488, "cookies": false, "type": "", "demo": "sites\/get-variable.md", @@ -31307,7 +31412,7 @@ "x-appwrite": { "method": "updateVariable", "group": "variables", - "weight": 489, + "weight": 490, "cookies": false, "type": "", "demo": "sites\/update-variable.md", @@ -31399,7 +31504,7 @@ "x-appwrite": { "method": "deleteVariable", "group": "variables", - "weight": 490, + "weight": 491, "cookies": false, "type": "", "demo": "sites\/delete-variable.md", @@ -39916,7 +40021,7 @@ "x-appwrite": { "method": "list", "group": "files", - "weight": 507, + "weight": 508, "cookies": false, "type": "", "demo": "tokens\/list.md", @@ -39996,7 +40101,7 @@ "x-appwrite": { "method": "createFileToken", "group": "files", - "weight": 505, + "weight": 506, "cookies": false, "type": "", "demo": "tokens\/create-file-token.md", @@ -40080,7 +40185,7 @@ "x-appwrite": { "method": "get", "group": "tokens", - "weight": 506, + "weight": 507, "cookies": false, "type": "", "demo": "tokens\/get.md", @@ -40140,7 +40245,7 @@ "x-appwrite": { "method": "update", "group": "tokens", - "weight": 508, + "weight": 509, "cookies": false, "type": "", "demo": "tokens\/update.md", @@ -40211,7 +40316,7 @@ "x-appwrite": { "method": "delete", "group": "tokens", - "weight": 509, + "weight": 510, "cookies": false, "type": "", "demo": "tokens\/delete.md", diff --git a/app/config/specs/swagger2-latest-server.json b/app/config/specs/swagger2-latest-server.json index 98077f1050..c7a5a20c24 100644 --- a/app/config/specs/swagger2-latest-server.json +++ b/app/config/specs/swagger2-latest-server.json @@ -20226,6 +20226,112 @@ ] } }, + "\/sites\/direct": { + "post": { + "summary": "Create direct deployment", + "operationId": "sitesCreateDirectDeployment", + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "sites" + ], + "description": "Create a deployment directly from a repository branch.", + "responses": { + "202": { + "description": "Deployment", + "schema": { + "$ref": "#\/definitions\/deployment" + } + } + }, + "deprecated": false, + "x-appwrite": { + "method": "createDirectDeployment", + "group": "deployments", + "weight": 483, + "cookies": false, + "type": "", + "demo": "sites\/create-direct-deployment.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterCreate a deployment directly from a repository branch.", + "rate-limit": 0, + "rate-time": 3600, + "rate-key": "url:{url},ip:{ip}", + "scope": "sites.write", + "platforms": [ + "server" + ], + "packaging": false, + "auth": { + "Project": [], + "Key": [] + } + }, + "security": [ + { + "Project": [], + "Key": [] + } + ], + "parameters": [ + { + "name": "payload", + "in": "body", + "schema": { + "type": "object", + "properties": { + "siteId": { + "type": "string", + "description": "Site ID.", + "default": null, + "x-example": "" + }, + "repository": { + "type": "string", + "description": "Repository name of the template.", + "default": null, + "x-example": "" + }, + "owner": { + "type": "string", + "description": "The name of the owner of the template.", + "default": null, + "x-example": "" + }, + "rootDirectory": { + "type": "string", + "description": "Path to site code in the template repo.", + "default": null, + "x-example": "" + }, + "branch": { + "type": "string", + "description": "Branch to create deployment from.", + "default": null, + "x-example": "" + }, + "activate": { + "type": "boolean", + "description": "Automatically activate the deployment when it is finished building.", + "default": true, + "x-example": false + } + }, + "required": [ + "siteId", + "repository", + "owner", + "rootDirectory", + "branch" + ] + } + } + ] + } + }, "\/sites\/frameworks": { "get": { "summary": "List frameworks", @@ -20300,7 +20406,7 @@ "x-appwrite": { "method": "listSpecifications", "group": "frameworks", - "weight": 495, + "weight": 496, "cookies": false, "type": "", "demo": "sites\/list-specifications.md", @@ -21566,7 +21672,7 @@ "x-appwrite": { "method": "listLogs", "group": "logs", - "weight": 484, + "weight": 485, "cookies": false, "type": "", "demo": "sites\/list-logs.md", @@ -21638,7 +21744,7 @@ "x-appwrite": { "method": "getLog", "group": "logs", - "weight": 483, + "weight": 484, "cookies": false, "type": "", "demo": "sites\/get-log.md", @@ -21703,7 +21809,7 @@ "x-appwrite": { "method": "deleteLog", "group": "logs", - "weight": 485, + "weight": 486, "cookies": false, "type": "", "demo": "sites\/delete-log.md", @@ -21771,7 +21877,7 @@ "x-appwrite": { "method": "listVariables", "group": "variables", - "weight": 488, + "weight": 489, "cookies": false, "type": "", "demo": "sites\/list-variables.md", @@ -21831,7 +21937,7 @@ "x-appwrite": { "method": "createVariable", "group": "variables", - "weight": 486, + "weight": 487, "cookies": false, "type": "", "demo": "sites\/create-variable.md", @@ -21922,7 +22028,7 @@ "x-appwrite": { "method": "getVariable", "group": "variables", - "weight": 487, + "weight": 488, "cookies": false, "type": "", "demo": "sites\/get-variable.md", @@ -21990,7 +22096,7 @@ "x-appwrite": { "method": "updateVariable", "group": "variables", - "weight": 489, + "weight": 490, "cookies": false, "type": "", "demo": "sites\/update-variable.md", @@ -22083,7 +22189,7 @@ "x-appwrite": { "method": "deleteVariable", "group": "variables", - "weight": 490, + "weight": 491, "cookies": false, "type": "", "demo": "sites\/delete-variable.md", @@ -30036,7 +30142,7 @@ "x-appwrite": { "method": "list", "group": "files", - "weight": 507, + "weight": 508, "cookies": false, "type": "", "demo": "tokens\/list.md", @@ -30117,7 +30223,7 @@ "x-appwrite": { "method": "createFileToken", "group": "files", - "weight": 505, + "weight": 506, "cookies": false, "type": "", "demo": "tokens\/create-file-token.md", @@ -30202,7 +30308,7 @@ "x-appwrite": { "method": "get", "group": "tokens", - "weight": 506, + "weight": 507, "cookies": false, "type": "", "demo": "tokens\/get.md", @@ -30263,7 +30369,7 @@ "x-appwrite": { "method": "update", "group": "tokens", - "weight": 508, + "weight": 509, "cookies": false, "type": "", "demo": "tokens\/update.md", @@ -30335,7 +30441,7 @@ "x-appwrite": { "method": "delete", "group": "tokens", - "weight": 509, + "weight": 510, "cookies": false, "type": "", "demo": "tokens\/delete.md", diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 9547a752ef..2ac05eae77 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -311,19 +311,27 @@ class Builds extends Action $templateRepositoryName = $template->getAttribute('repositoryName', ''); $templateOwnerName = $template->getAttribute('ownerName', ''); $templateVersion = $template->getAttribute('version', ''); + $templateBranch = $template->getAttribute('branch', ''); $templateRootDirectory = $template->getAttribute('rootDirectory', ''); $templateRootDirectory = \rtrim($templateRootDirectory, '/'); $templateRootDirectory = \ltrim($templateRootDirectory, '.'); $templateRootDirectory = \ltrim($templateRootDirectory, '/'); - if (!empty($templateRepositoryName) && !empty($templateOwnerName) && !empty($templateVersion)) { + if (!empty($templateRepositoryName) && !empty($templateOwnerName) && (!empty($templateVersion) || !empty($templateBranch))) { $stdout = ''; $stderr = ''; // Clone template repo $tmpTemplateDirectory = '/tmp/builds/' . $deploymentId . '-template'; - $gitCloneCommandForTemplate = $github->generateCloneCommand($templateOwnerName, $templateRepositoryName, $templateVersion, GitHub::CLONE_TYPE_TAG, $tmpTemplateDirectory, $templateRootDirectory); + + if(empty($templateVersion)) { + $gitCloneCommandForTemplate = $github->generateCloneCommand($templateOwnerName, $templateRepositoryName, $templateBranch, GitHub::CLONE_TYPE_BRANCH, $tmpTemplateDirectory, $templateRootDirectory); + } else { + // True template + $gitCloneCommandForTemplate = $github->generateCloneCommand($templateOwnerName, $templateRepositoryName, $templateVersion, GitHub::CLONE_TYPE_TAG, $tmpTemplateDirectory, $templateRootDirectory); + } + $exit = Console::execute($gitCloneCommandForTemplate, '', $stdout, $stderr); if ($exit !== 0) { diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Direct/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Direct/Create.php new file mode 100644 index 0000000000..092a7702df --- /dev/null +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Direct/Create.php @@ -0,0 +1,231 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_POST) + ->setHttpPath('/v1/sites/direct') + ->desc('Create direct deployment') + ->groups(['api', 'sites']) + ->label('scope', 'sites.write') + ->label('resourceType', RESOURCE_TYPE_SITES) + ->label('event', 'sites.[siteId].deployments.[deploymentId].create') + ->label('audits.event', 'deployment.create') + ->label('audits.resource', 'site/{request.siteId}') + ->label('sdk', new Method( + namespace: 'sites', + group: 'deployments', + name: 'createDirectDeployment', + description: <<param('siteId', '', new UID(), 'Site ID.') + ->param('repository', '', new Text(128, 0), 'Repository name of the template.') + ->param('owner', '', new Text(128, 0), 'The name of the owner of the template.') + ->param('rootDirectory', '', new Text(128, 0), 'Path to site code in the template repo.') + ->param('branch', '', new Text(128, 0), 'Branch to create deployment from.') + ->param('activate', true, new Boolean(), 'Automatically activate the deployment when it is finished building.', true) + ->inject('request') + ->inject('response') + ->inject('dbForProject') + ->inject('dbForPlatform') + ->inject('project') + ->inject('queueForEvents') + ->inject('queueForBuilds') + ->inject('gitHub') + ->callback($this->action(...)); + } + + public function action( + string $siteId, + string $repository, + string $owner, + string $rootDirectory, + string $branch, + bool $activate, + Request $request, + Response $response, + Database $dbForProject, + Database $dbForPlatform, + Document $project, + Event $queueForEvents, + Build $queueForBuilds, + GitHub $github + ) { + $site = $dbForProject->getDocument('sites', $siteId); + + if ($site->isEmpty()) { + throw new Exception(Exception::SITE_NOT_FOUND); + } + + $template = new Document([ + 'repositoryName' => $repository, + 'ownerName' => $owner, + 'rootDirectory' => $rootDirectory, + 'branch' => $branch + ]); + + + if (!empty($site->getAttribute('providerRepositoryId'))) { + $installation = $dbForPlatform->getDocument('installations', $site->getAttribute('installationId')); + + $deployment = $this->redeployVcsSite( + request: $request, + site: $site, + project: $project, + installation: $installation, + dbForProject: $dbForProject, + dbForPlatform: $dbForPlatform, + queueForBuilds: $queueForBuilds, + template: $template, + github: $github, + activate: $activate, + ); + + $queueForEvents + ->setParam('siteId', $site->getId()) + ->setParam('deploymentId', $deployment->getId()); + + $response + ->setStatusCode(Response::STATUS_CODE_ACCEPTED) + ->dynamic($deployment, Response::MODEL_DEPLOYMENT); + + return; + } + + $branchUrl = "https://github.com/$owner/$repository/tree/$branch"; + $repositoryUrl = "https://github.com/$owner/$repository"; + + try { + $commitDetails = $github->getLatestCommit($owner, $repository, $branch); + } catch (\Throwable $error) { + // Ignore; deployment can continue + } + + $commands = []; + if (!empty($site->getAttribute('installCommand', ''))) { + $commands[] = $site->getAttribute('installCommand', ''); + } + if (!empty($site->getAttribute('buildCommand', ''))) { + $commands[] = $site->getAttribute('buildCommand', ''); + } + + $deploymentId = ID::unique(); + $deployment = $dbForProject->createDocument('deployments', new Document([ + '$id' => $deploymentId, + '$permissions' => [ + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + 'resourceId' => $site->getId(), + 'resourceInternalId' => $site->getSequence(), + 'resourceType' => 'sites', + 'buildCommands' => \implode(' && ', $commands), + 'buildOutput' => $site->getAttribute('outputDirectory', ''), + 'adapter' => $site->getAttribute('adapter', ''), + 'fallbackFile' => $site->getAttribute('fallbackFile', ''), + 'providerRepositoryName' => $repository, + 'providerRepositoryOwner' => $owner, + 'providerRepositoryUrl' => $repositoryUrl, + 'providerBranchUrl' => $branchUrl, + 'providerBranch' => $branch, + 'providerCommitHash' => $commitDetails['commitHash'] ?? '', + 'providerCommitAuthorUrl' => $commitDetails['commitAuthorUrl'] ?? '', + 'providerCommitAuthor' => $commitDetails['commitAuthor'] ?? '', + 'providerCommitMessage' => mb_strimwidth($commitDetails['commitMessage'] ?? '', 0, 255, '...'), + 'providerCommitUrl' => $commitDetails['commitUrl'] ?? '', + 'type' => 'vcs', + 'activate' => $activate, + ])); + + $site = $site + ->setAttribute('latestDeploymentId', $deployment->getId()) + ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) + ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) + ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); + $dbForProject->updateDocument('sites', $site->getId(), $site); + + $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', ''); + $domain = ID::unique() . "." . $sitesDomain; + + // TODO: @christyjacob remove once we migrate the rules in 1.7.x + $ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain) : ID::unique(); + + Authorization::skip( + fn () => $dbForPlatform->createDocument('rules', new Document([ + '$id' => $ruleId, + 'projectId' => $project->getId(), + 'projectInternalId' => $project->getSequence(), + 'domain' => $domain, + 'type' => 'deployment', + 'trigger' => 'deployment', + 'deploymentId' => $deployment->isEmpty() ? '' : $deployment->getId(), + 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getSequence(), + 'deploymentResourceType' => 'site', + 'deploymentResourceId' => $site->getId(), + 'deploymentResourceInternalId' => $site->getSequence(), + 'status' => 'verified', + 'certificateId' => '', + 'owner' => 'Appwrite', + 'region' => $project->getAttribute('region') + ])) + ); + + $queueForBuilds + ->setType(BUILD_TYPE_DEPLOYMENT) + ->setResource($site) + ->setDeployment($deployment) + ->setTemplate($template); + + $queueForEvents + ->setParam('siteId', $site->getId()) + ->setParam('deploymentId', $deployment->getId()); + + $response + ->setStatusCode(Response::STATUS_CODE_ACCEPTED) + ->dynamic($deployment, Response::MODEL_DEPLOYMENT); + } +} diff --git a/src/Appwrite/Platform/Modules/Sites/Services/Http.php b/src/Appwrite/Platform/Modules/Sites/Services/Http.php index 6bd151f97e..f19b9b6d71 100644 --- a/src/Appwrite/Platform/Modules/Sites/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Sites/Services/Http.php @@ -6,6 +6,7 @@ use Appwrite\Platform\Modules\Sites\Http\Deployments\Create as CreateDeployment; use Appwrite\Platform\Modules\Sites\Http\Deployments\Delete as DeleteDeployment; use Appwrite\Platform\Modules\Sites\Http\Deployments\Download\Get as DownloadDeployment; use Appwrite\Platform\Modules\Sites\Http\Deployments\Duplicate\Create as CreateDuplicateDeployment; +use Appwrite\Platform\Modules\Sites\Http\Deployments\Direct\Create as CreateDirectDeployment; use Appwrite\Platform\Modules\Sites\Http\Deployments\Get as GetDeployment; use Appwrite\Platform\Modules\Sites\Http\Deployments\Status\Update as UpdateDeploymentStatus; use Appwrite\Platform\Modules\Sites\Http\Deployments\Template\Create as CreateTemplateDeployment; @@ -60,6 +61,7 @@ class Http extends Service $this->addAction(DownloadDeployment::getName(), new DownloadDeployment()); $this->addAction(CreateDuplicateDeployment::getName(), new CreateDuplicateDeployment()); $this->addAction(UpdateDeploymentStatus::getName(), new UpdateDeploymentStatus()); + $this->addAction(CreateDirectDeployment::getName(), new CreateDirectDeployment()); // Logs $this->addAction(GetLog::getName(), new GetLog()); From 4858317891faa2a5a0bdcaf4ea3f976d223ae125 Mon Sep 17 00:00:00 2001 From: Atharva Deosthale Date: Sat, 13 Sep 2025 18:02:13 +0530 Subject: [PATCH 02/13] fix: format, lints --- .../Platform/Modules/Functions/Workers/Builds.php | 4 ++-- .../Modules/Sites/Http/Deployments/Direct/Create.php | 8 ++++---- src/Appwrite/Platform/Modules/Sites/Services/Http.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 2ac05eae77..62ee96da47 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -324,8 +324,8 @@ class Builds extends Action // Clone template repo $tmpTemplateDirectory = '/tmp/builds/' . $deploymentId . '-template'; - - if(empty($templateVersion)) { + + if (empty($templateVersion)) { $gitCloneCommandForTemplate = $github->generateCloneCommand($templateOwnerName, $templateRepositoryName, $templateBranch, GitHub::CLONE_TYPE_BRANCH, $tmpTemplateDirectory, $templateRootDirectory); } else { // True template diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Direct/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Direct/Create.php index 092a7702df..d1df994149 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Direct/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Direct/Create.php @@ -106,7 +106,7 @@ class Create extends Base 'rootDirectory' => $rootDirectory, 'branch' => $branch ]); - + if (!empty($site->getAttribute('providerRepositoryId'))) { $installation = $dbForPlatform->getDocument('installations', $site->getAttribute('installationId')); @@ -137,11 +137,11 @@ class Create extends Base $branchUrl = "https://github.com/$owner/$repository/tree/$branch"; $repositoryUrl = "https://github.com/$owner/$repository"; - + try { - $commitDetails = $github->getLatestCommit($owner, $repository, $branch); + $commitDetails = $github->getLatestCommit($owner, $repository, $branch); } catch (\Throwable $error) { - // Ignore; deployment can continue + // Ignore; deployment can continue } $commands = []; diff --git a/src/Appwrite/Platform/Modules/Sites/Services/Http.php b/src/Appwrite/Platform/Modules/Sites/Services/Http.php index f19b9b6d71..437356d4e2 100644 --- a/src/Appwrite/Platform/Modules/Sites/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Sites/Services/Http.php @@ -4,9 +4,9 @@ namespace Appwrite\Platform\Modules\Sites\Services; use Appwrite\Platform\Modules\Sites\Http\Deployments\Create as CreateDeployment; use Appwrite\Platform\Modules\Sites\Http\Deployments\Delete as DeleteDeployment; +use Appwrite\Platform\Modules\Sites\Http\Deployments\Direct\Create as CreateDirectDeployment; use Appwrite\Platform\Modules\Sites\Http\Deployments\Download\Get as DownloadDeployment; use Appwrite\Platform\Modules\Sites\Http\Deployments\Duplicate\Create as CreateDuplicateDeployment; -use Appwrite\Platform\Modules\Sites\Http\Deployments\Direct\Create as CreateDirectDeployment; use Appwrite\Platform\Modules\Sites\Http\Deployments\Get as GetDeployment; use Appwrite\Platform\Modules\Sites\Http\Deployments\Status\Update as UpdateDeploymentStatus; use Appwrite\Platform\Modules\Sites\Http\Deployments\Template\Create as CreateTemplateDeployment; From 2b1e3bd9477941431f3f5055ea118b1fe62e9067 Mon Sep 17 00:00:00 2001 From: Atharva Deosthale Date: Sun, 14 Sep 2025 15:15:44 +0530 Subject: [PATCH 03/13] delete the new route and just do it in template route --- .../Http/Deployments/Template/Create.php | 26 ++++++++++++++++--- .../Modules/Functions/Workers/Builds.php | 13 +++------- .../Http/Deployments/Template/Create.php | 26 ++++++++++++++++--- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php index 4d93c8e8cd..885e23bfa1 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php @@ -65,7 +65,9 @@ class Create extends Base ->param('repository', '', new Text(128, 0), 'Repository name of the template.') ->param('owner', '', new Text(128, 0), 'The name of the owner of the template.') ->param('rootDirectory', '', new Text(128, 0), 'Path to function code in the template repo.') - ->param('version', '', new Text(128, 0), 'Version (tag) for the repo linked to the function template.') + ->param('version', '', new Text(128, 0), 'Version (tag) for the repo linked to the function template.', true) + ->param('type', '', new Text(128, 0), 'Type for the reference provided. Can be commit, branch, or version', true) + ->param('reference', '', new Text(128, 0), 'Reference value, can be a commit hash, branch name, or release tag', true) ->param('activate', false, new Boolean(), 'Automatically activate the deployment when it is finished building.', true) ->inject('request') ->inject('response') @@ -84,6 +86,8 @@ class Create extends Base string $owner, string $rootDirectory, string $version, + string $type, + string $reference, bool $activate, Request $request, Response $response, @@ -100,11 +104,22 @@ class Create extends Base throw new Exception(Exception::FUNCTION_NOT_FOUND); } + if (empty($version) && empty($type) && empty($reference)) { + throw new Exception("Either version or type & reference must be provided"); + } + + $referenceType = !empty($version) ? GitHub::CLONE_TYPE_TAG : $type; + $referenceValue = !empty($version) ? $version : $reference; + + $branchUrl = $type == GitHub::CLONE_TYPE_BRANCH ? "https://github.com/$owner/$repository/tree/$referenceValue" : ""; + $repositoryUrl = "https://github.com/$owner/$repository"; + $template = new Document([ 'repositoryName' => $repository, 'ownerName' => $owner, 'rootDirectory' => $rootDirectory, - 'version' => $version + 'referenceType' => $referenceType, + 'referenceValue' => $referenceValue, ]); if (!empty($function->getAttribute('providerRepositoryId'))) { @@ -146,7 +161,12 @@ class Create extends Base 'resourceType' => 'functions', 'entrypoint' => $function->getAttribute('entrypoint', ''), 'buildCommands' => $function->getAttribute('commands', ''), - 'type' => 'manual', + 'providerRepositoryName' => $repository, + 'providerRepositoryOwner' => $owner, + 'providerRepositoryUrl' => $repositoryUrl, + 'providerBranchUrl' => $branchUrl, + 'providerBranch' => $type == GitHub::CLONE_TYPE_BRANCH ? $referenceValue : '', + 'type' => 'vcs', 'activate' => $activate, ])); diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 62ee96da47..4bb49a42c8 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -310,27 +310,22 @@ class Builds extends Action // Non-VCS + Template $templateRepositoryName = $template->getAttribute('repositoryName', ''); $templateOwnerName = $template->getAttribute('ownerName', ''); - $templateVersion = $template->getAttribute('version', ''); - $templateBranch = $template->getAttribute('branch', ''); + $templateReferenceType = $template->getAttribute('referenceType', ''); + $templateReferenceValue = $template->getAttribute('referenceValue', ''); $templateRootDirectory = $template->getAttribute('rootDirectory', ''); $templateRootDirectory = \rtrim($templateRootDirectory, '/'); $templateRootDirectory = \ltrim($templateRootDirectory, '.'); $templateRootDirectory = \ltrim($templateRootDirectory, '/'); - if (!empty($templateRepositoryName) && !empty($templateOwnerName) && (!empty($templateVersion) || !empty($templateBranch))) { + if (!empty($templateRepositoryName) && !empty($templateOwnerName) && !empty($templateReferenceType) && !empty($templateReferenceValue)) { $stdout = ''; $stderr = ''; // Clone template repo $tmpTemplateDirectory = '/tmp/builds/' . $deploymentId . '-template'; - if (empty($templateVersion)) { - $gitCloneCommandForTemplate = $github->generateCloneCommand($templateOwnerName, $templateRepositoryName, $templateBranch, GitHub::CLONE_TYPE_BRANCH, $tmpTemplateDirectory, $templateRootDirectory); - } else { - // True template - $gitCloneCommandForTemplate = $github->generateCloneCommand($templateOwnerName, $templateRepositoryName, $templateVersion, GitHub::CLONE_TYPE_TAG, $tmpTemplateDirectory, $templateRootDirectory); - } + $gitCloneCommandForTemplate = $github->generateCloneCommand($templateOwnerName, $templateRepositoryName, $templateReferenceValue, $templateReferenceType, $tmpTemplateDirectory, $templateRootDirectory); $exit = Console::execute($gitCloneCommandForTemplate, '', $stdout, $stderr); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php index a2040d830b..0799e0b51f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php @@ -67,7 +67,9 @@ class Create extends Base ->param('repository', '', new Text(128, 0), 'Repository name of the template.') ->param('owner', '', new Text(128, 0), 'The name of the owner of the template.') ->param('rootDirectory', '', new Text(128, 0), 'Path to site code in the template repo.') - ->param('version', '', new Text(128, 0), 'Version (tag) for the repo linked to the site template.') + ->param('version', '', new Text(128, 0), 'Version (tag) for the repo linked to the function template.', true) + ->param('type', '', new Text(128, 0), 'Type for the reference provided. Can be commit, branch, or version', true) + ->param('reference', '', new Text(128, 0), 'Reference value, can be a commit hash, branch name, or release tag', true) ->param('activate', false, new Boolean(), 'Automatically activate the deployment when it is finished building.', true) ->inject('request') ->inject('response') @@ -86,6 +88,8 @@ class Create extends Base string $owner, string $rootDirectory, string $version, + string $type, + string $reference, bool $activate, Request $request, Response $response, @@ -102,11 +106,22 @@ class Create extends Base throw new Exception(Exception::SITE_NOT_FOUND); } + if (empty($version) && empty($type) && empty($reference)) { + throw new Exception("Either version or type & reference must be provided"); + } + + $referenceType = !empty($version) ? GitHub::CLONE_TYPE_TAG : $type; + $referenceValue = !empty($version) ? $version : $reference; + + $branchUrl = $type == GitHub::CLONE_TYPE_BRANCH ? "https://github.com/$owner/$repository/tree/$referenceValue" : ""; + $repositoryUrl = "https://github.com/$owner/$repository"; + $template = new Document([ 'repositoryName' => $repository, 'ownerName' => $owner, 'rootDirectory' => $rootDirectory, - 'version' => $version + 'referenceType' => $referenceType, + 'referenceValue' => $referenceValue ]); if (!empty($site->getAttribute('providerRepositoryId'))) { @@ -157,9 +172,14 @@ class Create extends Base 'resourceType' => 'sites', 'buildCommands' => \implode(' && ', $commands), 'buildOutput' => $site->getAttribute('outputDirectory', ''), + 'providerRepositoryName' => $repository, + 'providerRepositoryOwner' => $owner, + 'providerRepositoryUrl' => $repositoryUrl, + 'providerBranchUrl' => $branchUrl, + 'providerBranch' => $type == GitHub::CLONE_TYPE_BRANCH ? $referenceValue : '', 'adapter' => $site->getAttribute('adapter', ''), 'fallbackFile' => $site->getAttribute('fallbackFile', ''), - 'type' => 'manual', + 'type' => 'vcs', 'activate' => $activate, ])); From cb03bfe74ccd1ac43737053113b27a82e8bd3cbd Mon Sep 17 00:00:00 2001 From: Atharva Deosthale Date: Sun, 14 Sep 2025 15:22:51 +0530 Subject: [PATCH 04/13] specs and sdk --- .../specs/open-api3-latest-console.json | 179 ++++---------- app/config/specs/open-api3-latest-server.json | 154 +++--------- app/config/specs/swagger2-latest-console.json | 195 +++++---------- app/config/specs/swagger2-latest-server.json | 170 ++++--------- .../Sites/Http/Deployments/Direct/Create.php | 231 ------------------ .../Platform/Modules/Sites/Services/Http.php | 2 - 6 files changed, 186 insertions(+), 745 deletions(-) delete mode 100644 src/Appwrite/Platform/Modules/Sites/Http/Deployments/Direct/Create.php diff --git a/app/config/specs/open-api3-latest-console.json b/app/config/specs/open-api3-latest-console.json index 0de652e3fb..96cec5c5a6 100644 --- a/app/config/specs/open-api3-latest-console.json +++ b/app/config/specs/open-api3-latest-console.json @@ -4888,7 +4888,7 @@ "x-appwrite": { "method": "getResource", "group": null, - "weight": 497, + "weight": 496, "cookies": false, "type": "", "demo": "console\/get-resource.md", @@ -12932,6 +12932,16 @@ "description": "Version (tag) for the repo linked to the function template.", "x-example": "" }, + "type": { + "type": "string", + "description": "Type for the reference provided. Can be commit, branch, or version", + "x-example": "" + }, + "reference": { + "type": "string", + "description": "Reference value, can be a commit hash, branch name, or release tag", + "x-example": "" + }, "activate": { "type": "boolean", "description": "Automatically activate the deployment when it is finished building.", @@ -12941,8 +12951,7 @@ "required": [ "repository", "owner", - "rootDirectory", - "version" + "rootDirectory" ] } } @@ -28209,7 +28218,7 @@ "x-appwrite": { "method": "listRules", "group": null, - "weight": 503, + "weight": 502, "cookies": false, "type": "", "demo": "proxy\/list-rules.md", @@ -28283,7 +28292,7 @@ "x-appwrite": { "method": "createAPIRule", "group": null, - "weight": 498, + "weight": 497, "cookies": false, "type": "", "demo": "proxy\/create-api-rule.md", @@ -28350,7 +28359,7 @@ "x-appwrite": { "method": "createFunctionRule", "group": null, - "weight": 500, + "weight": 499, "cookies": false, "type": "", "demo": "proxy\/create-function-rule.md", @@ -28428,7 +28437,7 @@ "x-appwrite": { "method": "createRedirectRule", "group": null, - "weight": 501, + "weight": 500, "cookies": false, "type": "", "demo": "proxy\/create-redirect-rule.md", @@ -28541,7 +28550,7 @@ "x-appwrite": { "method": "createSiteRule", "group": null, - "weight": 499, + "weight": 498, "cookies": false, "type": "", "demo": "proxy\/create-site-rule.md", @@ -28619,7 +28628,7 @@ "x-appwrite": { "method": "getRule", "group": null, - "weight": 502, + "weight": 501, "cookies": false, "type": "", "demo": "proxy\/get-rule.md", @@ -28670,7 +28679,7 @@ "x-appwrite": { "method": "deleteRule", "group": null, - "weight": 504, + "weight": 503, "cookies": false, "type": "", "demo": "proxy\/delete-rule.md", @@ -28730,7 +28739,7 @@ "x-appwrite": { "method": "updateRuleVerification", "group": null, - "weight": 505, + "weight": 504, "cookies": false, "type": "", "demo": "proxy\/update-rule-verification.md", @@ -29085,103 +29094,6 @@ } } }, - "\/sites\/direct": { - "post": { - "summary": "Create direct deployment", - "operationId": "sitesCreateDirectDeployment", - "tags": [ - "sites" - ], - "description": "Create a deployment directly from a repository branch.", - "responses": { - "202": { - "description": "Deployment", - "content": { - "application\/json": { - "schema": { - "$ref": "#\/components\/schemas\/deployment" - } - } - } - } - }, - "deprecated": false, - "x-appwrite": { - "method": "createDirectDeployment", - "group": "deployments", - "weight": 483, - "cookies": false, - "type": "", - "demo": "sites\/create-direct-deployment.md", - "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterCreate a deployment directly from a repository branch.", - "rate-limit": 0, - "rate-time": 3600, - "rate-key": "url:{url},ip:{ip}", - "scope": "sites.write", - "platforms": [ - "server" - ], - "packaging": false, - "auth": { - "Project": [] - } - }, - "security": [ - { - "Project": [], - "Key": [] - } - ], - "requestBody": { - "content": { - "application\/json": { - "schema": { - "type": "object", - "properties": { - "siteId": { - "type": "string", - "description": "Site ID.", - "x-example": "" - }, - "repository": { - "type": "string", - "description": "Repository name of the template.", - "x-example": "" - }, - "owner": { - "type": "string", - "description": "The name of the owner of the template.", - "x-example": "" - }, - "rootDirectory": { - "type": "string", - "description": "Path to site code in the template repo.", - "x-example": "" - }, - "branch": { - "type": "string", - "description": "Branch to create deployment from.", - "x-example": "" - }, - "activate": { - "type": "boolean", - "description": "Automatically activate the deployment when it is finished building.", - "x-example": false - } - }, - "required": [ - "siteId", - "repository", - "owner", - "rootDirectory", - "branch" - ] - } - } - } - } - } - }, "\/sites\/frameworks": { "get": { "summary": "List frameworks", @@ -29255,7 +29167,7 @@ "x-appwrite": { "method": "listSpecifications", "group": "frameworks", - "weight": 496, + "weight": 495, "cookies": false, "type": "", "demo": "sites\/list-specifications.md", @@ -29305,7 +29217,7 @@ "x-appwrite": { "method": "listTemplates", "group": "templates", - "weight": 492, + "weight": 491, "cookies": false, "type": "", "demo": "sites\/list-templates.md", @@ -29405,7 +29317,7 @@ "x-appwrite": { "method": "getTemplate", "group": "templates", - "weight": 493, + "weight": 492, "cookies": false, "type": "", "demo": "sites\/get-template.md", @@ -29465,7 +29377,7 @@ "x-appwrite": { "method": "listUsage", "group": null, - "weight": 494, + "weight": 493, "cookies": false, "type": "", "demo": "sites\/list-usage.md", @@ -30304,9 +30216,19 @@ }, "version": { "type": "string", - "description": "Version (tag) for the repo linked to the site template.", + "description": "Version (tag) for the repo linked to the function template.", "x-example": "" }, + "type": { + "type": "string", + "description": "Type for the reference provided. Can be commit, branch, or version", + "x-example": "" + }, + "reference": { + "type": "string", + "description": "Reference value, can be a commit hash, branch name, or release tag", + "x-example": "" + }, "activate": { "type": "boolean", "description": "Automatically activate the deployment when it is finished building.", @@ -30316,8 +30238,7 @@ "required": [ "repository", "owner", - "rootDirectory", - "version" + "rootDirectory" ] } } @@ -30734,7 +30655,7 @@ "x-appwrite": { "method": "listLogs", "group": "logs", - "weight": 485, + "weight": 484, "cookies": false, "type": "", "demo": "sites\/list-logs.md", @@ -30805,7 +30726,7 @@ "x-appwrite": { "method": "getLog", "group": "logs", - "weight": 484, + "weight": 483, "cookies": false, "type": "", "demo": "sites\/get-log.md", @@ -30867,7 +30788,7 @@ "x-appwrite": { "method": "deleteLog", "group": "logs", - "weight": 486, + "weight": 485, "cookies": false, "type": "", "demo": "sites\/delete-log.md", @@ -30938,7 +30859,7 @@ "x-appwrite": { "method": "getUsage", "group": null, - "weight": 495, + "weight": 494, "cookies": false, "type": "", "demo": "sites\/get-usage.md", @@ -31020,7 +30941,7 @@ "x-appwrite": { "method": "listVariables", "group": "variables", - "weight": 489, + "weight": 488, "cookies": false, "type": "", "demo": "sites\/list-variables.md", @@ -31079,7 +31000,7 @@ "x-appwrite": { "method": "createVariable", "group": "variables", - "weight": 487, + "weight": 486, "cookies": false, "type": "", "demo": "sites\/create-variable.md", @@ -31170,7 +31091,7 @@ "x-appwrite": { "method": "getVariable", "group": "variables", - "weight": 488, + "weight": 487, "cookies": false, "type": "", "demo": "sites\/get-variable.md", @@ -31239,7 +31160,7 @@ "x-appwrite": { "method": "updateVariable", "group": "variables", - "weight": 490, + "weight": 489, "cookies": false, "type": "", "demo": "sites\/update-variable.md", @@ -31330,7 +31251,7 @@ "x-appwrite": { "method": "deleteVariable", "group": "variables", - "weight": 491, + "weight": 490, "cookies": false, "type": "", "demo": "sites\/delete-variable.md", @@ -40081,7 +40002,7 @@ "x-appwrite": { "method": "list", "group": "files", - "weight": 508, + "weight": 507, "cookies": false, "type": "", "demo": "tokens\/list.md", @@ -40161,7 +40082,7 @@ "x-appwrite": { "method": "createFileToken", "group": "files", - "weight": 506, + "weight": 505, "cookies": false, "type": "", "demo": "tokens\/create-file-token.md", @@ -40250,7 +40171,7 @@ "x-appwrite": { "method": "get", "group": "tokens", - "weight": 507, + "weight": 506, "cookies": false, "type": "", "demo": "tokens\/get.md", @@ -40310,7 +40231,7 @@ "x-appwrite": { "method": "update", "group": "tokens", - "weight": 509, + "weight": 508, "cookies": false, "type": "", "demo": "tokens\/update.md", @@ -40380,7 +40301,7 @@ "x-appwrite": { "method": "delete", "group": "tokens", - "weight": 510, + "weight": 509, "cookies": false, "type": "", "demo": "tokens\/delete.md", diff --git a/app/config/specs/open-api3-latest-server.json b/app/config/specs/open-api3-latest-server.json index d8d7178eb2..3a1afab16b 100644 --- a/app/config/specs/open-api3-latest-server.json +++ b/app/config/specs/open-api3-latest-server.json @@ -11714,6 +11714,16 @@ "description": "Version (tag) for the repo linked to the function template.", "x-example": "" }, + "type": { + "type": "string", + "description": "Type for the reference provided. Can be commit, branch, or version", + "x-example": "" + }, + "reference": { + "type": "string", + "description": "Reference value, can be a commit hash, branch name, or release tag", + "x-example": "" + }, "activate": { "type": "boolean", "description": "Automatically activate the deployment when it is finished building.", @@ -11723,8 +11733,7 @@ "required": [ "repository", "owner", - "rootDirectory", - "version" + "rootDirectory" ] } } @@ -20014,104 +20023,6 @@ } } }, - "\/sites\/direct": { - "post": { - "summary": "Create direct deployment", - "operationId": "sitesCreateDirectDeployment", - "tags": [ - "sites" - ], - "description": "Create a deployment directly from a repository branch.", - "responses": { - "202": { - "description": "Deployment", - "content": { - "application\/json": { - "schema": { - "$ref": "#\/components\/schemas\/deployment" - } - } - } - } - }, - "deprecated": false, - "x-appwrite": { - "method": "createDirectDeployment", - "group": "deployments", - "weight": 483, - "cookies": false, - "type": "", - "demo": "sites\/create-direct-deployment.md", - "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterCreate a deployment directly from a repository branch.", - "rate-limit": 0, - "rate-time": 3600, - "rate-key": "url:{url},ip:{ip}", - "scope": "sites.write", - "platforms": [ - "server" - ], - "packaging": false, - "auth": { - "Project": [], - "Key": [] - } - }, - "security": [ - { - "Project": [], - "Key": [] - } - ], - "requestBody": { - "content": { - "application\/json": { - "schema": { - "type": "object", - "properties": { - "siteId": { - "type": "string", - "description": "Site ID.", - "x-example": "" - }, - "repository": { - "type": "string", - "description": "Repository name of the template.", - "x-example": "" - }, - "owner": { - "type": "string", - "description": "The name of the owner of the template.", - "x-example": "" - }, - "rootDirectory": { - "type": "string", - "description": "Path to site code in the template repo.", - "x-example": "" - }, - "branch": { - "type": "string", - "description": "Branch to create deployment from.", - "x-example": "" - }, - "activate": { - "type": "boolean", - "description": "Automatically activate the deployment when it is finished building.", - "x-example": false - } - }, - "required": [ - "siteId", - "repository", - "owner", - "rootDirectory", - "branch" - ] - } - } - } - } - } - }, "\/sites\/frameworks": { "get": { "summary": "List frameworks", @@ -20186,7 +20097,7 @@ "x-appwrite": { "method": "listSpecifications", "group": "frameworks", - "weight": 496, + "weight": 495, "cookies": false, "type": "", "demo": "sites\/list-specifications.md", @@ -21012,9 +20923,19 @@ }, "version": { "type": "string", - "description": "Version (tag) for the repo linked to the site template.", + "description": "Version (tag) for the repo linked to the function template.", "x-example": "" }, + "type": { + "type": "string", + "description": "Type for the reference provided. Can be commit, branch, or version", + "x-example": "" + }, + "reference": { + "type": "string", + "description": "Reference value, can be a commit hash, branch name, or release tag", + "x-example": "" + }, "activate": { "type": "boolean", "description": "Automatically activate the deployment when it is finished building.", @@ -21024,8 +20945,7 @@ "required": [ "repository", "owner", - "rootDirectory", - "version" + "rootDirectory" ] } } @@ -21447,7 +21367,7 @@ "x-appwrite": { "method": "listLogs", "group": "logs", - "weight": 485, + "weight": 484, "cookies": false, "type": "", "demo": "sites\/list-logs.md", @@ -21519,7 +21439,7 @@ "x-appwrite": { "method": "getLog", "group": "logs", - "weight": 484, + "weight": 483, "cookies": false, "type": "", "demo": "sites\/get-log.md", @@ -21582,7 +21502,7 @@ "x-appwrite": { "method": "deleteLog", "group": "logs", - "weight": 486, + "weight": 485, "cookies": false, "type": "", "demo": "sites\/delete-log.md", @@ -21654,7 +21574,7 @@ "x-appwrite": { "method": "listVariables", "group": "variables", - "weight": 489, + "weight": 488, "cookies": false, "type": "", "demo": "sites\/list-variables.md", @@ -21714,7 +21634,7 @@ "x-appwrite": { "method": "createVariable", "group": "variables", - "weight": 487, + "weight": 486, "cookies": false, "type": "", "demo": "sites\/create-variable.md", @@ -21806,7 +21726,7 @@ "x-appwrite": { "method": "getVariable", "group": "variables", - "weight": 488, + "weight": 487, "cookies": false, "type": "", "demo": "sites\/get-variable.md", @@ -21876,7 +21796,7 @@ "x-appwrite": { "method": "updateVariable", "group": "variables", - "weight": 490, + "weight": 489, "cookies": false, "type": "", "demo": "sites\/update-variable.md", @@ -21968,7 +21888,7 @@ "x-appwrite": { "method": "deleteVariable", "group": "variables", - "weight": 491, + "weight": 490, "cookies": false, "type": "", "demo": "sites\/delete-variable.md", @@ -30122,7 +30042,7 @@ "x-appwrite": { "method": "list", "group": "files", - "weight": 508, + "weight": 507, "cookies": false, "type": "", "demo": "tokens\/list.md", @@ -30203,7 +30123,7 @@ "x-appwrite": { "method": "createFileToken", "group": "files", - "weight": 506, + "weight": 505, "cookies": false, "type": "", "demo": "tokens\/create-file-token.md", @@ -30293,7 +30213,7 @@ "x-appwrite": { "method": "get", "group": "tokens", - "weight": 507, + "weight": 506, "cookies": false, "type": "", "demo": "tokens\/get.md", @@ -30354,7 +30274,7 @@ "x-appwrite": { "method": "update", "group": "tokens", - "weight": 509, + "weight": 508, "cookies": false, "type": "", "demo": "tokens\/update.md", @@ -30425,7 +30345,7 @@ "x-appwrite": { "method": "delete", "group": "tokens", - "weight": 510, + "weight": 509, "cookies": false, "type": "", "demo": "tokens\/delete.md", diff --git a/app/config/specs/swagger2-latest-console.json b/app/config/specs/swagger2-latest-console.json index 22823cd40e..27604767b9 100644 --- a/app/config/specs/swagger2-latest-console.json +++ b/app/config/specs/swagger2-latest-console.json @@ -5052,7 +5052,7 @@ "x-appwrite": { "method": "getResource", "group": null, - "weight": 497, + "weight": 496, "cookies": false, "type": "", "demo": "console\/get-resource.md", @@ -12928,9 +12928,21 @@ "version": { "type": "string", "description": "Version (tag) for the repo linked to the function template.", - "default": null, + "default": "", "x-example": "" }, + "type": { + "type": "string", + "description": "Type for the reference provided. Can be commit, branch, or version", + "default": "", + "x-example": "" + }, + "reference": { + "type": "string", + "description": "Reference value, can be a commit hash, branch name, or release tag", + "default": "", + "x-example": "" + }, "activate": { "type": "boolean", "description": "Automatically activate the deployment when it is finished building.", @@ -12941,8 +12953,7 @@ "required": [ "repository", "owner", - "rootDirectory", - "version" + "rootDirectory" ] } } @@ -28351,7 +28362,7 @@ "x-appwrite": { "method": "listRules", "group": null, - "weight": 503, + "weight": 502, "cookies": false, "type": "", "demo": "proxy\/list-rules.md", @@ -28424,7 +28435,7 @@ "x-appwrite": { "method": "createAPIRule", "group": null, - "weight": 498, + "weight": 497, "cookies": false, "type": "", "demo": "proxy\/create-api-rule.md", @@ -28494,7 +28505,7 @@ "x-appwrite": { "method": "createFunctionRule", "group": null, - "weight": 500, + "weight": 499, "cookies": false, "type": "", "demo": "proxy\/create-function-rule.md", @@ -28577,7 +28588,7 @@ "x-appwrite": { "method": "createRedirectRule", "group": null, - "weight": 501, + "weight": 500, "cookies": false, "type": "", "demo": "proxy\/create-redirect-rule.md", @@ -28697,7 +28708,7 @@ "x-appwrite": { "method": "createSiteRule", "group": null, - "weight": 499, + "weight": 498, "cookies": false, "type": "", "demo": "proxy\/create-site-rule.md", @@ -28778,7 +28789,7 @@ "x-appwrite": { "method": "getRule", "group": null, - "weight": 502, + "weight": 501, "cookies": false, "type": "", "demo": "proxy\/get-rule.md", @@ -28831,7 +28842,7 @@ "x-appwrite": { "method": "deleteRule", "group": null, - "weight": 504, + "weight": 503, "cookies": false, "type": "", "demo": "proxy\/delete-rule.md", @@ -28891,7 +28902,7 @@ "x-appwrite": { "method": "updateRuleVerification", "group": null, - "weight": 505, + "weight": 504, "cookies": false, "type": "", "demo": "proxy\/update-rule-verification.md", @@ -29264,111 +29275,6 @@ ] } }, - "\/sites\/direct": { - "post": { - "summary": "Create direct deployment", - "operationId": "sitesCreateDirectDeployment", - "consumes": [ - "application\/json" - ], - "produces": [ - "application\/json" - ], - "tags": [ - "sites" - ], - "description": "Create a deployment directly from a repository branch.", - "responses": { - "202": { - "description": "Deployment", - "schema": { - "$ref": "#\/definitions\/deployment" - } - } - }, - "deprecated": false, - "x-appwrite": { - "method": "createDirectDeployment", - "group": "deployments", - "weight": 483, - "cookies": false, - "type": "", - "demo": "sites\/create-direct-deployment.md", - "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterCreate a deployment directly from a repository branch.", - "rate-limit": 0, - "rate-time": 3600, - "rate-key": "url:{url},ip:{ip}", - "scope": "sites.write", - "platforms": [ - "server" - ], - "packaging": false, - "auth": { - "Project": [] - } - }, - "security": [ - { - "Project": [], - "Key": [] - } - ], - "parameters": [ - { - "name": "payload", - "in": "body", - "schema": { - "type": "object", - "properties": { - "siteId": { - "type": "string", - "description": "Site ID.", - "default": null, - "x-example": "" - }, - "repository": { - "type": "string", - "description": "Repository name of the template.", - "default": null, - "x-example": "" - }, - "owner": { - "type": "string", - "description": "The name of the owner of the template.", - "default": null, - "x-example": "" - }, - "rootDirectory": { - "type": "string", - "description": "Path to site code in the template repo.", - "default": null, - "x-example": "" - }, - "branch": { - "type": "string", - "description": "Branch to create deployment from.", - "default": null, - "x-example": "" - }, - "activate": { - "type": "boolean", - "description": "Automatically activate the deployment when it is finished building.", - "default": true, - "x-example": false - } - }, - "required": [ - "siteId", - "repository", - "owner", - "rootDirectory", - "branch" - ] - } - } - ] - } - }, "\/sites\/frameworks": { "get": { "summary": "List frameworks", @@ -29442,7 +29348,7 @@ "x-appwrite": { "method": "listSpecifications", "group": "frameworks", - "weight": 496, + "weight": 495, "cookies": false, "type": "", "demo": "sites\/list-specifications.md", @@ -29492,7 +29398,7 @@ "x-appwrite": { "method": "listTemplates", "group": "templates", - "weight": 492, + "weight": 491, "cookies": false, "type": "", "demo": "sites\/list-templates.md", @@ -29586,7 +29492,7 @@ "x-appwrite": { "method": "getTemplate", "group": "templates", - "weight": 493, + "weight": 492, "cookies": false, "type": "", "demo": "sites\/get-template.md", @@ -29644,7 +29550,7 @@ "x-appwrite": { "method": "listUsage", "group": null, - "weight": 494, + "weight": 493, "cookies": false, "type": "", "demo": "sites\/list-usage.md", @@ -30490,10 +30396,22 @@ }, "version": { "type": "string", - "description": "Version (tag) for the repo linked to the site template.", - "default": null, + "description": "Version (tag) for the repo linked to the function template.", + "default": "", "x-example": "" }, + "type": { + "type": "string", + "description": "Type for the reference provided. Can be commit, branch, or version", + "default": "", + "x-example": "" + }, + "reference": { + "type": "string", + "description": "Reference value, can be a commit hash, branch name, or release tag", + "default": "", + "x-example": "" + }, "activate": { "type": "boolean", "description": "Automatically activate the deployment when it is finished building.", @@ -30504,8 +30422,7 @@ "required": [ "repository", "owner", - "rootDirectory", - "version" + "rootDirectory" ] } } @@ -30916,7 +30833,7 @@ "x-appwrite": { "method": "listLogs", "group": "logs", - "weight": 485, + "weight": 484, "cookies": false, "type": "", "demo": "sites\/list-logs.md", @@ -30987,7 +30904,7 @@ "x-appwrite": { "method": "getLog", "group": "logs", - "weight": 484, + "weight": 483, "cookies": false, "type": "", "demo": "sites\/get-log.md", @@ -31051,7 +30968,7 @@ "x-appwrite": { "method": "deleteLog", "group": "logs", - "weight": 486, + "weight": 485, "cookies": false, "type": "", "demo": "sites\/delete-log.md", @@ -31118,7 +31035,7 @@ "x-appwrite": { "method": "getUsage", "group": null, - "weight": 495, + "weight": 494, "cookies": false, "type": "", "demo": "sites\/get-usage.md", @@ -31196,7 +31113,7 @@ "x-appwrite": { "method": "listVariables", "group": "variables", - "weight": 489, + "weight": 488, "cookies": false, "type": "", "demo": "sites\/list-variables.md", @@ -31255,7 +31172,7 @@ "x-appwrite": { "method": "createVariable", "group": "variables", - "weight": 487, + "weight": 486, "cookies": false, "type": "", "demo": "sites\/create-variable.md", @@ -31345,7 +31262,7 @@ "x-appwrite": { "method": "getVariable", "group": "variables", - "weight": 488, + "weight": 487, "cookies": false, "type": "", "demo": "sites\/get-variable.md", @@ -31412,7 +31329,7 @@ "x-appwrite": { "method": "updateVariable", "group": "variables", - "weight": 490, + "weight": 489, "cookies": false, "type": "", "demo": "sites\/update-variable.md", @@ -31504,7 +31421,7 @@ "x-appwrite": { "method": "deleteVariable", "group": "variables", - "weight": 491, + "weight": 490, "cookies": false, "type": "", "demo": "sites\/delete-variable.md", @@ -40021,7 +39938,7 @@ "x-appwrite": { "method": "list", "group": "files", - "weight": 508, + "weight": 507, "cookies": false, "type": "", "demo": "tokens\/list.md", @@ -40101,7 +40018,7 @@ "x-appwrite": { "method": "createFileToken", "group": "files", - "weight": 506, + "weight": 505, "cookies": false, "type": "", "demo": "tokens\/create-file-token.md", @@ -40185,7 +40102,7 @@ "x-appwrite": { "method": "get", "group": "tokens", - "weight": 507, + "weight": 506, "cookies": false, "type": "", "demo": "tokens\/get.md", @@ -40245,7 +40162,7 @@ "x-appwrite": { "method": "update", "group": "tokens", - "weight": 509, + "weight": 508, "cookies": false, "type": "", "demo": "tokens\/update.md", @@ -40316,7 +40233,7 @@ "x-appwrite": { "method": "delete", "group": "tokens", - "weight": 510, + "weight": 509, "cookies": false, "type": "", "demo": "tokens\/delete.md", diff --git a/app/config/specs/swagger2-latest-server.json b/app/config/specs/swagger2-latest-server.json index c7a5a20c24..a13c8324a4 100644 --- a/app/config/specs/swagger2-latest-server.json +++ b/app/config/specs/swagger2-latest-server.json @@ -11735,9 +11735,21 @@ "version": { "type": "string", "description": "Version (tag) for the repo linked to the function template.", - "default": null, + "default": "", "x-example": "" }, + "type": { + "type": "string", + "description": "Type for the reference provided. Can be commit, branch, or version", + "default": "", + "x-example": "" + }, + "reference": { + "type": "string", + "description": "Reference value, can be a commit hash, branch name, or release tag", + "default": "", + "x-example": "" + }, "activate": { "type": "boolean", "description": "Automatically activate the deployment when it is finished building.", @@ -11748,8 +11760,7 @@ "required": [ "repository", "owner", - "rootDirectory", - "version" + "rootDirectory" ] } } @@ -20226,112 +20237,6 @@ ] } }, - "\/sites\/direct": { - "post": { - "summary": "Create direct deployment", - "operationId": "sitesCreateDirectDeployment", - "consumes": [ - "application\/json" - ], - "produces": [ - "application\/json" - ], - "tags": [ - "sites" - ], - "description": "Create a deployment directly from a repository branch.", - "responses": { - "202": { - "description": "Deployment", - "schema": { - "$ref": "#\/definitions\/deployment" - } - } - }, - "deprecated": false, - "x-appwrite": { - "method": "createDirectDeployment", - "group": "deployments", - "weight": 483, - "cookies": false, - "type": "", - "demo": "sites\/create-direct-deployment.md", - "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterCreate a deployment directly from a repository branch.", - "rate-limit": 0, - "rate-time": 3600, - "rate-key": "url:{url},ip:{ip}", - "scope": "sites.write", - "platforms": [ - "server" - ], - "packaging": false, - "auth": { - "Project": [], - "Key": [] - } - }, - "security": [ - { - "Project": [], - "Key": [] - } - ], - "parameters": [ - { - "name": "payload", - "in": "body", - "schema": { - "type": "object", - "properties": { - "siteId": { - "type": "string", - "description": "Site ID.", - "default": null, - "x-example": "" - }, - "repository": { - "type": "string", - "description": "Repository name of the template.", - "default": null, - "x-example": "" - }, - "owner": { - "type": "string", - "description": "The name of the owner of the template.", - "default": null, - "x-example": "" - }, - "rootDirectory": { - "type": "string", - "description": "Path to site code in the template repo.", - "default": null, - "x-example": "" - }, - "branch": { - "type": "string", - "description": "Branch to create deployment from.", - "default": null, - "x-example": "" - }, - "activate": { - "type": "boolean", - "description": "Automatically activate the deployment when it is finished building.", - "default": true, - "x-example": false - } - }, - "required": [ - "siteId", - "repository", - "owner", - "rootDirectory", - "branch" - ] - } - } - ] - } - }, "\/sites\/frameworks": { "get": { "summary": "List frameworks", @@ -20406,7 +20311,7 @@ "x-appwrite": { "method": "listSpecifications", "group": "frameworks", - "weight": 496, + "weight": 495, "cookies": false, "type": "", "demo": "sites\/list-specifications.md", @@ -21241,10 +21146,22 @@ }, "version": { "type": "string", - "description": "Version (tag) for the repo linked to the site template.", - "default": null, + "description": "Version (tag) for the repo linked to the function template.", + "default": "", "x-example": "" }, + "type": { + "type": "string", + "description": "Type for the reference provided. Can be commit, branch, or version", + "default": "", + "x-example": "" + }, + "reference": { + "type": "string", + "description": "Reference value, can be a commit hash, branch name, or release tag", + "default": "", + "x-example": "" + }, "activate": { "type": "boolean", "description": "Automatically activate the deployment when it is finished building.", @@ -21255,8 +21172,7 @@ "required": [ "repository", "owner", - "rootDirectory", - "version" + "rootDirectory" ] } } @@ -21672,7 +21588,7 @@ "x-appwrite": { "method": "listLogs", "group": "logs", - "weight": 485, + "weight": 484, "cookies": false, "type": "", "demo": "sites\/list-logs.md", @@ -21744,7 +21660,7 @@ "x-appwrite": { "method": "getLog", "group": "logs", - "weight": 484, + "weight": 483, "cookies": false, "type": "", "demo": "sites\/get-log.md", @@ -21809,7 +21725,7 @@ "x-appwrite": { "method": "deleteLog", "group": "logs", - "weight": 486, + "weight": 485, "cookies": false, "type": "", "demo": "sites\/delete-log.md", @@ -21877,7 +21793,7 @@ "x-appwrite": { "method": "listVariables", "group": "variables", - "weight": 489, + "weight": 488, "cookies": false, "type": "", "demo": "sites\/list-variables.md", @@ -21937,7 +21853,7 @@ "x-appwrite": { "method": "createVariable", "group": "variables", - "weight": 487, + "weight": 486, "cookies": false, "type": "", "demo": "sites\/create-variable.md", @@ -22028,7 +21944,7 @@ "x-appwrite": { "method": "getVariable", "group": "variables", - "weight": 488, + "weight": 487, "cookies": false, "type": "", "demo": "sites\/get-variable.md", @@ -22096,7 +22012,7 @@ "x-appwrite": { "method": "updateVariable", "group": "variables", - "weight": 490, + "weight": 489, "cookies": false, "type": "", "demo": "sites\/update-variable.md", @@ -22189,7 +22105,7 @@ "x-appwrite": { "method": "deleteVariable", "group": "variables", - "weight": 491, + "weight": 490, "cookies": false, "type": "", "demo": "sites\/delete-variable.md", @@ -30142,7 +30058,7 @@ "x-appwrite": { "method": "list", "group": "files", - "weight": 508, + "weight": 507, "cookies": false, "type": "", "demo": "tokens\/list.md", @@ -30223,7 +30139,7 @@ "x-appwrite": { "method": "createFileToken", "group": "files", - "weight": 506, + "weight": 505, "cookies": false, "type": "", "demo": "tokens\/create-file-token.md", @@ -30308,7 +30224,7 @@ "x-appwrite": { "method": "get", "group": "tokens", - "weight": 507, + "weight": 506, "cookies": false, "type": "", "demo": "tokens\/get.md", @@ -30369,7 +30285,7 @@ "x-appwrite": { "method": "update", "group": "tokens", - "weight": 509, + "weight": 508, "cookies": false, "type": "", "demo": "tokens\/update.md", @@ -30441,7 +30357,7 @@ "x-appwrite": { "method": "delete", "group": "tokens", - "weight": 510, + "weight": 509, "cookies": false, "type": "", "demo": "tokens\/delete.md", diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Direct/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Direct/Create.php deleted file mode 100644 index d1df994149..0000000000 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Direct/Create.php +++ /dev/null @@ -1,231 +0,0 @@ -setHttpMethod(Action::HTTP_REQUEST_METHOD_POST) - ->setHttpPath('/v1/sites/direct') - ->desc('Create direct deployment') - ->groups(['api', 'sites']) - ->label('scope', 'sites.write') - ->label('resourceType', RESOURCE_TYPE_SITES) - ->label('event', 'sites.[siteId].deployments.[deploymentId].create') - ->label('audits.event', 'deployment.create') - ->label('audits.resource', 'site/{request.siteId}') - ->label('sdk', new Method( - namespace: 'sites', - group: 'deployments', - name: 'createDirectDeployment', - description: <<param('siteId', '', new UID(), 'Site ID.') - ->param('repository', '', new Text(128, 0), 'Repository name of the template.') - ->param('owner', '', new Text(128, 0), 'The name of the owner of the template.') - ->param('rootDirectory', '', new Text(128, 0), 'Path to site code in the template repo.') - ->param('branch', '', new Text(128, 0), 'Branch to create deployment from.') - ->param('activate', true, new Boolean(), 'Automatically activate the deployment when it is finished building.', true) - ->inject('request') - ->inject('response') - ->inject('dbForProject') - ->inject('dbForPlatform') - ->inject('project') - ->inject('queueForEvents') - ->inject('queueForBuilds') - ->inject('gitHub') - ->callback($this->action(...)); - } - - public function action( - string $siteId, - string $repository, - string $owner, - string $rootDirectory, - string $branch, - bool $activate, - Request $request, - Response $response, - Database $dbForProject, - Database $dbForPlatform, - Document $project, - Event $queueForEvents, - Build $queueForBuilds, - GitHub $github - ) { - $site = $dbForProject->getDocument('sites', $siteId); - - if ($site->isEmpty()) { - throw new Exception(Exception::SITE_NOT_FOUND); - } - - $template = new Document([ - 'repositoryName' => $repository, - 'ownerName' => $owner, - 'rootDirectory' => $rootDirectory, - 'branch' => $branch - ]); - - - if (!empty($site->getAttribute('providerRepositoryId'))) { - $installation = $dbForPlatform->getDocument('installations', $site->getAttribute('installationId')); - - $deployment = $this->redeployVcsSite( - request: $request, - site: $site, - project: $project, - installation: $installation, - dbForProject: $dbForProject, - dbForPlatform: $dbForPlatform, - queueForBuilds: $queueForBuilds, - template: $template, - github: $github, - activate: $activate, - ); - - $queueForEvents - ->setParam('siteId', $site->getId()) - ->setParam('deploymentId', $deployment->getId()); - - $response - ->setStatusCode(Response::STATUS_CODE_ACCEPTED) - ->dynamic($deployment, Response::MODEL_DEPLOYMENT); - - return; - } - - $branchUrl = "https://github.com/$owner/$repository/tree/$branch"; - $repositoryUrl = "https://github.com/$owner/$repository"; - - try { - $commitDetails = $github->getLatestCommit($owner, $repository, $branch); - } catch (\Throwable $error) { - // Ignore; deployment can continue - } - - $commands = []; - if (!empty($site->getAttribute('installCommand', ''))) { - $commands[] = $site->getAttribute('installCommand', ''); - } - if (!empty($site->getAttribute('buildCommand', ''))) { - $commands[] = $site->getAttribute('buildCommand', ''); - } - - $deploymentId = ID::unique(); - $deployment = $dbForProject->createDocument('deployments', new Document([ - '$id' => $deploymentId, - '$permissions' => [ - Permission::read(Role::any()), - Permission::update(Role::any()), - Permission::delete(Role::any()), - ], - 'resourceId' => $site->getId(), - 'resourceInternalId' => $site->getSequence(), - 'resourceType' => 'sites', - 'buildCommands' => \implode(' && ', $commands), - 'buildOutput' => $site->getAttribute('outputDirectory', ''), - 'adapter' => $site->getAttribute('adapter', ''), - 'fallbackFile' => $site->getAttribute('fallbackFile', ''), - 'providerRepositoryName' => $repository, - 'providerRepositoryOwner' => $owner, - 'providerRepositoryUrl' => $repositoryUrl, - 'providerBranchUrl' => $branchUrl, - 'providerBranch' => $branch, - 'providerCommitHash' => $commitDetails['commitHash'] ?? '', - 'providerCommitAuthorUrl' => $commitDetails['commitAuthorUrl'] ?? '', - 'providerCommitAuthor' => $commitDetails['commitAuthor'] ?? '', - 'providerCommitMessage' => mb_strimwidth($commitDetails['commitMessage'] ?? '', 0, 255, '...'), - 'providerCommitUrl' => $commitDetails['commitUrl'] ?? '', - 'type' => 'vcs', - 'activate' => $activate, - ])); - - $site = $site - ->setAttribute('latestDeploymentId', $deployment->getId()) - ->setAttribute('latestDeploymentInternalId', $deployment->getSequence()) - ->setAttribute('latestDeploymentCreatedAt', $deployment->getCreatedAt()) - ->setAttribute('latestDeploymentStatus', $deployment->getAttribute('status', '')); - $dbForProject->updateDocument('sites', $site->getId(), $site); - - $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', ''); - $domain = ID::unique() . "." . $sitesDomain; - - // TODO: @christyjacob remove once we migrate the rules in 1.7.x - $ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain) : ID::unique(); - - Authorization::skip( - fn () => $dbForPlatform->createDocument('rules', new Document([ - '$id' => $ruleId, - 'projectId' => $project->getId(), - 'projectInternalId' => $project->getSequence(), - 'domain' => $domain, - 'type' => 'deployment', - 'trigger' => 'deployment', - 'deploymentId' => $deployment->isEmpty() ? '' : $deployment->getId(), - 'deploymentInternalId' => $deployment->isEmpty() ? '' : $deployment->getSequence(), - 'deploymentResourceType' => 'site', - 'deploymentResourceId' => $site->getId(), - 'deploymentResourceInternalId' => $site->getSequence(), - 'status' => 'verified', - 'certificateId' => '', - 'owner' => 'Appwrite', - 'region' => $project->getAttribute('region') - ])) - ); - - $queueForBuilds - ->setType(BUILD_TYPE_DEPLOYMENT) - ->setResource($site) - ->setDeployment($deployment) - ->setTemplate($template); - - $queueForEvents - ->setParam('siteId', $site->getId()) - ->setParam('deploymentId', $deployment->getId()); - - $response - ->setStatusCode(Response::STATUS_CODE_ACCEPTED) - ->dynamic($deployment, Response::MODEL_DEPLOYMENT); - } -} diff --git a/src/Appwrite/Platform/Modules/Sites/Services/Http.php b/src/Appwrite/Platform/Modules/Sites/Services/Http.php index 437356d4e2..6bd151f97e 100644 --- a/src/Appwrite/Platform/Modules/Sites/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Sites/Services/Http.php @@ -4,7 +4,6 @@ namespace Appwrite\Platform\Modules\Sites\Services; use Appwrite\Platform\Modules\Sites\Http\Deployments\Create as CreateDeployment; use Appwrite\Platform\Modules\Sites\Http\Deployments\Delete as DeleteDeployment; -use Appwrite\Platform\Modules\Sites\Http\Deployments\Direct\Create as CreateDirectDeployment; use Appwrite\Platform\Modules\Sites\Http\Deployments\Download\Get as DownloadDeployment; use Appwrite\Platform\Modules\Sites\Http\Deployments\Duplicate\Create as CreateDuplicateDeployment; use Appwrite\Platform\Modules\Sites\Http\Deployments\Get as GetDeployment; @@ -61,7 +60,6 @@ class Http extends Service $this->addAction(DownloadDeployment::getName(), new DownloadDeployment()); $this->addAction(CreateDuplicateDeployment::getName(), new CreateDuplicateDeployment()); $this->addAction(UpdateDeploymentStatus::getName(), new UpdateDeploymentStatus()); - $this->addAction(CreateDirectDeployment::getName(), new CreateDirectDeployment()); // Logs $this->addAction(GetLog::getName(), new GetLog()); From fca27279660b7f13ca652a0f7ae9a417fe087cf6 Mon Sep 17 00:00:00 2001 From: Atharva Deosthale Date: Sun, 14 Sep 2025 15:28:25 +0530 Subject: [PATCH 05/13] add validation for type --- .../Modules/Functions/Http/Deployments/Template/Create.php | 3 ++- .../Modules/Sites/Http/Deployments/Template/Create.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php index 885e23bfa1..6312c24d86 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php @@ -21,6 +21,7 @@ use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Request; use Utopia\Validator\Boolean; use Utopia\Validator\Text; +use Utopia\Validator\WhiteList; use Utopia\VCS\Adapter\Git\GitHub; class Create extends Base @@ -66,7 +67,7 @@ class Create extends Base ->param('owner', '', new Text(128, 0), 'The name of the owner of the template.') ->param('rootDirectory', '', new Text(128, 0), 'Path to function code in the template repo.') ->param('version', '', new Text(128, 0), 'Version (tag) for the repo linked to the function template.', true) - ->param('type', '', new Text(128, 0), 'Type for the reference provided. Can be commit, branch, or version', true) + ->param('type', '', new WhiteList(['commit', 'branch', 'tag']), 'Type for the reference provided. Can be commit, branch, or version', true) ->param('reference', '', new Text(128, 0), 'Reference value, can be a commit hash, branch name, or release tag', true) ->param('activate', false, new Boolean(), 'Automatically activate the deployment when it is finished building.', true) ->inject('request') diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php index 0799e0b51f..3721740e7f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php @@ -23,6 +23,7 @@ use Utopia\Swoole\Request; use Utopia\System\System; use Utopia\Validator\Boolean; use Utopia\Validator\Text; +use Utopia\Validator\WhiteList; use Utopia\VCS\Adapter\Git\GitHub; class Create extends Base @@ -68,7 +69,7 @@ class Create extends Base ->param('owner', '', new Text(128, 0), 'The name of the owner of the template.') ->param('rootDirectory', '', new Text(128, 0), 'Path to site code in the template repo.') ->param('version', '', new Text(128, 0), 'Version (tag) for the repo linked to the function template.', true) - ->param('type', '', new Text(128, 0), 'Type for the reference provided. Can be commit, branch, or version', true) + ->param('type', '', new WhiteList(['branch', 'commit', 'tag']), 'Type for the reference provided. Can be commit, branch, or version', true) ->param('reference', '', new Text(128, 0), 'Reference value, can be a commit hash, branch name, or release tag', true) ->param('activate', false, new Boolean(), 'Automatically activate the deployment when it is finished building.', true) ->inject('request') From de8538b6222ec78e87dc9eaa81aa5d40b0b7e4cc Mon Sep 17 00:00:00 2001 From: Atharva Deosthale Date: Thu, 18 Sep 2025 12:27:24 +0530 Subject: [PATCH 06/13] use request filters for 1.8.0 to convert into and --- app/controllers/general.php | 4 +++ .../Http/Deployments/Template/Create.php | 21 ++++-------- .../Http/Deployments/Template/Create.php | 21 ++++-------- src/Appwrite/Utopia/Request/Filters/V21.php | 34 +++++++++++++++++++ 4 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 src/Appwrite/Utopia/Request/Filters/V21.php diff --git a/app/controllers/general.php b/app/controllers/general.php index 8abca96742..c663091677 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -23,6 +23,7 @@ use Appwrite\Utopia\Request\Filters\V17 as RequestV17; use Appwrite\Utopia\Request\Filters\V18 as RequestV18; use Appwrite\Utopia\Request\Filters\V19 as RequestV19; use Appwrite\Utopia\Request\Filters\V20 as RequestV20; +use Appwrite\Utopia\Request\Filters\V21 as RequestV21; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response\Filters\V16 as ResponseV16; use Appwrite\Utopia\Response\Filters\V17 as ResponseV17; @@ -906,6 +907,9 @@ App::init() $dbForProject = $getProjectDB($project); $request->addFilter(new RequestV20($dbForProject, $route->getPathValues($request))); } + if (version_compare($requestFormat, '1.8.1', '<')) { + $request->addFilter(new RequestV21()); + } } $domain = $request->getHostname(); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php index 6312c24d86..5e0266a09e 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php @@ -66,9 +66,8 @@ class Create extends Base ->param('repository', '', new Text(128, 0), 'Repository name of the template.') ->param('owner', '', new Text(128, 0), 'The name of the owner of the template.') ->param('rootDirectory', '', new Text(128, 0), 'Path to function code in the template repo.') - ->param('version', '', new Text(128, 0), 'Version (tag) for the repo linked to the function template.', true) - ->param('type', '', new WhiteList(['commit', 'branch', 'tag']), 'Type for the reference provided. Can be commit, branch, or version', true) - ->param('reference', '', new Text(128, 0), 'Reference value, can be a commit hash, branch name, or release tag', true) + ->param('type', '', new WhiteList(['commit', 'branch', 'tag']), 'Type for the reference provided. Can be commit, branch, or tag') + ->param('reference', '', new Text(128, 0), 'Reference value, can be a commit hash, branch name, or release tag') ->param('activate', false, new Boolean(), 'Automatically activate the deployment when it is finished building.', true) ->inject('request') ->inject('response') @@ -86,7 +85,6 @@ class Create extends Base string $repository, string $owner, string $rootDirectory, - string $version, string $type, string $reference, bool $activate, @@ -105,22 +103,15 @@ class Create extends Base throw new Exception(Exception::FUNCTION_NOT_FOUND); } - if (empty($version) && empty($type) && empty($reference)) { - throw new Exception("Either version or type & reference must be provided"); - } - - $referenceType = !empty($version) ? GitHub::CLONE_TYPE_TAG : $type; - $referenceValue = !empty($version) ? $version : $reference; - - $branchUrl = $type == GitHub::CLONE_TYPE_BRANCH ? "https://github.com/$owner/$repository/tree/$referenceValue" : ""; + $branchUrl = $type == GitHub::CLONE_TYPE_BRANCH ? "https://github.com/$owner/$repository/tree/$reference" : ""; $repositoryUrl = "https://github.com/$owner/$repository"; $template = new Document([ 'repositoryName' => $repository, 'ownerName' => $owner, 'rootDirectory' => $rootDirectory, - 'referenceType' => $referenceType, - 'referenceValue' => $referenceValue, + 'referenceType' => $type, + 'referenceValue' => $reference, ]); if (!empty($function->getAttribute('providerRepositoryId'))) { @@ -166,7 +157,7 @@ class Create extends Base 'providerRepositoryOwner' => $owner, 'providerRepositoryUrl' => $repositoryUrl, 'providerBranchUrl' => $branchUrl, - 'providerBranch' => $type == GitHub::CLONE_TYPE_BRANCH ? $referenceValue : '', + 'providerBranch' => $type == GitHub::CLONE_TYPE_BRANCH ? $reference : '', 'type' => 'vcs', 'activate' => $activate, ])); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php index 3721740e7f..d7196eb3d5 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php @@ -68,9 +68,8 @@ class Create extends Base ->param('repository', '', new Text(128, 0), 'Repository name of the template.') ->param('owner', '', new Text(128, 0), 'The name of the owner of the template.') ->param('rootDirectory', '', new Text(128, 0), 'Path to site code in the template repo.') - ->param('version', '', new Text(128, 0), 'Version (tag) for the repo linked to the function template.', true) - ->param('type', '', new WhiteList(['branch', 'commit', 'tag']), 'Type for the reference provided. Can be commit, branch, or version', true) - ->param('reference', '', new Text(128, 0), 'Reference value, can be a commit hash, branch name, or release tag', true) + ->param('type', '', new WhiteList(['branch', 'commit', 'tag']), 'Type for the reference provided. Can be commit, branch, or tag') + ->param('reference', '', new Text(128, 0), 'Reference value, can be a commit hash, branch name, or release tag') ->param('activate', false, new Boolean(), 'Automatically activate the deployment when it is finished building.', true) ->inject('request') ->inject('response') @@ -88,7 +87,6 @@ class Create extends Base string $repository, string $owner, string $rootDirectory, - string $version, string $type, string $reference, bool $activate, @@ -107,22 +105,15 @@ class Create extends Base throw new Exception(Exception::SITE_NOT_FOUND); } - if (empty($version) && empty($type) && empty($reference)) { - throw new Exception("Either version or type & reference must be provided"); - } - - $referenceType = !empty($version) ? GitHub::CLONE_TYPE_TAG : $type; - $referenceValue = !empty($version) ? $version : $reference; - - $branchUrl = $type == GitHub::CLONE_TYPE_BRANCH ? "https://github.com/$owner/$repository/tree/$referenceValue" : ""; + $branchUrl = $type == GitHub::CLONE_TYPE_BRANCH ? "https://github.com/$owner/$repository/tree/$reference" : ""; $repositoryUrl = "https://github.com/$owner/$repository"; $template = new Document([ 'repositoryName' => $repository, 'ownerName' => $owner, 'rootDirectory' => $rootDirectory, - 'referenceType' => $referenceType, - 'referenceValue' => $referenceValue + 'referenceType' => $type, + 'referenceValue' => $reference ]); if (!empty($site->getAttribute('providerRepositoryId'))) { @@ -177,7 +168,7 @@ class Create extends Base 'providerRepositoryOwner' => $owner, 'providerRepositoryUrl' => $repositoryUrl, 'providerBranchUrl' => $branchUrl, - 'providerBranch' => $type == GitHub::CLONE_TYPE_BRANCH ? $referenceValue : '', + 'providerBranch' => $type == GitHub::CLONE_TYPE_BRANCH ? $reference : '', 'adapter' => $site->getAttribute('adapter', ''), 'fallbackFile' => $site->getAttribute('fallbackFile', ''), 'type' => 'vcs', diff --git a/src/Appwrite/Utopia/Request/Filters/V21.php b/src/Appwrite/Utopia/Request/Filters/V21.php new file mode 100644 index 0000000000..3ef0becf1d --- /dev/null +++ b/src/Appwrite/Utopia/Request/Filters/V21.php @@ -0,0 +1,34 @@ +convertVersionToTypeAndReference($content); + break; + } + return $content; + } + + /** + * Convert version parameter to type and reference for backwards compatibility + * with 1.8.0 template deployment endpoints + */ + protected function convertVersionToTypeAndReference(array $content): array + { + if (!empty($content['version'])) { + $content['type'] = 'tag'; + $content['reference'] = $content['version']; + unset($content['version']); + } + return $content; + } +} From 8e32fb05d1361778e64b583f468e2cd6d7de77f1 Mon Sep 17 00:00:00 2001 From: Atharva Deosthale Date: Thu, 18 Sep 2025 12:28:08 +0530 Subject: [PATCH 07/13] specs --- .../specs/open-api3-latest-console.json | 40 +++++++++------ app/config/specs/open-api3-latest-server.json | 40 +++++++++------ app/config/specs/swagger2-latest-console.json | 50 +++++++++++-------- app/config/specs/swagger2-latest-server.json | 50 +++++++++++-------- 4 files changed, 104 insertions(+), 76 deletions(-) diff --git a/app/config/specs/open-api3-latest-console.json b/app/config/specs/open-api3-latest-console.json index 96cec5c5a6..e052f542c9 100644 --- a/app/config/specs/open-api3-latest-console.json +++ b/app/config/specs/open-api3-latest-console.json @@ -12927,15 +12927,17 @@ "description": "Path to function code in the template repo.", "x-example": "" }, - "version": { - "type": "string", - "description": "Version (tag) for the repo linked to the function template.", - "x-example": "" - }, "type": { "type": "string", - "description": "Type for the reference provided. Can be commit, branch, or version", - "x-example": "" + "description": "Type for the reference provided. Can be commit, branch, or tag", + "x-example": "commit", + "enum": [ + "commit", + "branch", + "tag" + ], + "x-enum-name": null, + "x-enum-keys": [] }, "reference": { "type": "string", @@ -12951,7 +12953,9 @@ "required": [ "repository", "owner", - "rootDirectory" + "rootDirectory", + "type", + "reference" ] } } @@ -30214,15 +30218,17 @@ "description": "Path to site code in the template repo.", "x-example": "" }, - "version": { - "type": "string", - "description": "Version (tag) for the repo linked to the function template.", - "x-example": "" - }, "type": { "type": "string", - "description": "Type for the reference provided. Can be commit, branch, or version", - "x-example": "" + "description": "Type for the reference provided. Can be commit, branch, or tag", + "x-example": "branch", + "enum": [ + "branch", + "commit", + "tag" + ], + "x-enum-name": null, + "x-enum-keys": [] }, "reference": { "type": "string", @@ -30238,7 +30244,9 @@ "required": [ "repository", "owner", - "rootDirectory" + "rootDirectory", + "type", + "reference" ] } } diff --git a/app/config/specs/open-api3-latest-server.json b/app/config/specs/open-api3-latest-server.json index 3a1afab16b..b111f8e3e8 100644 --- a/app/config/specs/open-api3-latest-server.json +++ b/app/config/specs/open-api3-latest-server.json @@ -11709,15 +11709,17 @@ "description": "Path to function code in the template repo.", "x-example": "" }, - "version": { - "type": "string", - "description": "Version (tag) for the repo linked to the function template.", - "x-example": "" - }, "type": { "type": "string", - "description": "Type for the reference provided. Can be commit, branch, or version", - "x-example": "" + "description": "Type for the reference provided. Can be commit, branch, or tag", + "x-example": "commit", + "enum": [ + "commit", + "branch", + "tag" + ], + "x-enum-name": null, + "x-enum-keys": [] }, "reference": { "type": "string", @@ -11733,7 +11735,9 @@ "required": [ "repository", "owner", - "rootDirectory" + "rootDirectory", + "type", + "reference" ] } } @@ -20921,15 +20925,17 @@ "description": "Path to site code in the template repo.", "x-example": "" }, - "version": { - "type": "string", - "description": "Version (tag) for the repo linked to the function template.", - "x-example": "" - }, "type": { "type": "string", - "description": "Type for the reference provided. Can be commit, branch, or version", - "x-example": "" + "description": "Type for the reference provided. Can be commit, branch, or tag", + "x-example": "branch", + "enum": [ + "branch", + "commit", + "tag" + ], + "x-enum-name": null, + "x-enum-keys": [] }, "reference": { "type": "string", @@ -20945,7 +20951,9 @@ "required": [ "repository", "owner", - "rootDirectory" + "rootDirectory", + "type", + "reference" ] } } diff --git a/app/config/specs/swagger2-latest-console.json b/app/config/specs/swagger2-latest-console.json index 27604767b9..b359eaf310 100644 --- a/app/config/specs/swagger2-latest-console.json +++ b/app/config/specs/swagger2-latest-console.json @@ -12925,22 +12925,23 @@ "default": null, "x-example": "" }, - "version": { - "type": "string", - "description": "Version (tag) for the repo linked to the function template.", - "default": "", - "x-example": "" - }, "type": { "type": "string", - "description": "Type for the reference provided. Can be commit, branch, or version", - "default": "", - "x-example": "" + "description": "Type for the reference provided. Can be commit, branch, or tag", + "default": null, + "x-example": "commit", + "enum": [ + "commit", + "branch", + "tag" + ], + "x-enum-name": null, + "x-enum-keys": [] }, "reference": { "type": "string", "description": "Reference value, can be a commit hash, branch name, or release tag", - "default": "", + "default": null, "x-example": "" }, "activate": { @@ -12953,7 +12954,9 @@ "required": [ "repository", "owner", - "rootDirectory" + "rootDirectory", + "type", + "reference" ] } } @@ -30394,22 +30397,23 @@ "default": null, "x-example": "" }, - "version": { - "type": "string", - "description": "Version (tag) for the repo linked to the function template.", - "default": "", - "x-example": "" - }, "type": { "type": "string", - "description": "Type for the reference provided. Can be commit, branch, or version", - "default": "", - "x-example": "" + "description": "Type for the reference provided. Can be commit, branch, or tag", + "default": null, + "x-example": "branch", + "enum": [ + "branch", + "commit", + "tag" + ], + "x-enum-name": null, + "x-enum-keys": [] }, "reference": { "type": "string", "description": "Reference value, can be a commit hash, branch name, or release tag", - "default": "", + "default": null, "x-example": "" }, "activate": { @@ -30422,7 +30426,9 @@ "required": [ "repository", "owner", - "rootDirectory" + "rootDirectory", + "type", + "reference" ] } } diff --git a/app/config/specs/swagger2-latest-server.json b/app/config/specs/swagger2-latest-server.json index a13c8324a4..b806a9e6c7 100644 --- a/app/config/specs/swagger2-latest-server.json +++ b/app/config/specs/swagger2-latest-server.json @@ -11732,22 +11732,23 @@ "default": null, "x-example": "" }, - "version": { - "type": "string", - "description": "Version (tag) for the repo linked to the function template.", - "default": "", - "x-example": "" - }, "type": { "type": "string", - "description": "Type for the reference provided. Can be commit, branch, or version", - "default": "", - "x-example": "" + "description": "Type for the reference provided. Can be commit, branch, or tag", + "default": null, + "x-example": "commit", + "enum": [ + "commit", + "branch", + "tag" + ], + "x-enum-name": null, + "x-enum-keys": [] }, "reference": { "type": "string", "description": "Reference value, can be a commit hash, branch name, or release tag", - "default": "", + "default": null, "x-example": "" }, "activate": { @@ -11760,7 +11761,9 @@ "required": [ "repository", "owner", - "rootDirectory" + "rootDirectory", + "type", + "reference" ] } } @@ -21144,22 +21147,23 @@ "default": null, "x-example": "" }, - "version": { - "type": "string", - "description": "Version (tag) for the repo linked to the function template.", - "default": "", - "x-example": "" - }, "type": { "type": "string", - "description": "Type for the reference provided. Can be commit, branch, or version", - "default": "", - "x-example": "" + "description": "Type for the reference provided. Can be commit, branch, or tag", + "default": null, + "x-example": "branch", + "enum": [ + "branch", + "commit", + "tag" + ], + "x-enum-name": null, + "x-enum-keys": [] }, "reference": { "type": "string", "description": "Reference value, can be a commit hash, branch name, or release tag", - "default": "", + "default": null, "x-example": "" }, "activate": { @@ -21172,7 +21176,9 @@ "required": [ "repository", "owner", - "rootDirectory" + "rootDirectory", + "type", + "reference" ] } } From 9fe3e94a669240e3a8669d9da28cdea51561358a Mon Sep 17 00:00:00 2001 From: Atharva Deosthale Date: Thu, 18 Sep 2025 13:12:46 +0530 Subject: [PATCH 08/13] e2e tests --- .../e2e/Services/Functions/FunctionsBase.php | 28 ++++ .../Functions/FunctionsCustomServerTest.php | 117 +++++++++++++- tests/e2e/Services/Sites/SitesBase.php | 29 ++++ .../Services/Sites/SitesCustomServerTest.php | 149 +++++++++++++++++- 4 files changed, 321 insertions(+), 2 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsBase.php b/tests/e2e/Services/Functions/FunctionsBase.php index 27b67d851d..4eb31c08ac 100644 --- a/tests/e2e/Services/Functions/FunctionsBase.php +++ b/tests/e2e/Services/Functions/FunctionsBase.php @@ -268,6 +268,34 @@ trait FunctionsBase 'x-appwrite-project' => $this->getProject()['$id'], ])); + // Fetch latest commit from GitHub API if template has provider info + if ( + isset($template['body']['providerOwner']) && + isset($template['body']['providerRepositoryId']) + ) { + $owner = $template['body']['providerOwner']; + $repo = $template['body']['providerRepositoryId']; + + // GitHub API to get latest commit from main branch + $ch = curl_init("https://api.github.com/repos/{$owner}/{$repo}/commits/main"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'User-Agent: Appwrite', + 'Accept: application/vnd.github.v3+json' + ]); + + $response = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + if ($httpCode === 200) { + $commitData = json_decode($response, true); + if (isset($commitData['sha'])) { + $template['body']['latestCommit'] = $commitData['sha']; + } + } + } + return $template; } diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 0d63791151..8a774ed8bb 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -400,7 +400,8 @@ class FunctionsCustomServerTest extends Scope 'repository' => $starterTemplate['body']['providerRepositoryId'], 'owner' => $starterTemplate['body']['providerOwner'], 'rootDirectory' => $phpRuntime['providerRootDirectory'], - 'version' => $starterTemplate['body']['providerVersion'], + 'type' => 'tag', + 'reference' => $starterTemplate['body']['providerVersion'], ] ); @@ -502,6 +503,120 @@ class FunctionsCustomServerTest extends Scope $function = $this->cleanupFunction($functionId); } + public function testCreateFunctionAndDeploymentFromTemplateBranch() + { + $starterTemplate = $this->getTemplate('starter'); + $this->assertEquals(200, $starterTemplate['headers']['status-code']); + + $phpRuntime = array_values(array_filter($starterTemplate['body']['runtimes'], function ($runtime) { + return $runtime['name'] === 'node-22'; + }))[0]; + + // If this fails, the template has variables, and this test needs to be updated + $this->assertEmpty($starterTemplate['body']['variables']); + + $function = $this->createFunction( + [ + 'functionId' => ID::unique(), + 'name' => $starterTemplate['body']['name'] . ' - Branch Test', + 'runtime' => 'node-22', + 'execute' => $starterTemplate['body']['permissions'], + 'entrypoint' => $phpRuntime['entrypoint'], + 'events' => $starterTemplate['body']['events'], + 'schedule' => $starterTemplate['body']['cron'], + 'timeout' => $starterTemplate['body']['timeout'], + 'commands' => $phpRuntime['commands'], + 'scopes' => $starterTemplate['body']['scopes'], + ] + ); + + $this->assertEquals(201, $function['headers']['status-code']); + $this->assertNotEmpty($function['body']['$id']); + + $functionId = $function['body']['$id'] ?? ''; + + // Deploy using branch + $deployment = $this->createTemplateDeployment( + $functionId, + [ + 'resourceId' => ID::unique(), + 'activate' => true, + 'repository' => $starterTemplate['body']['providerRepositoryId'], + 'owner' => $starterTemplate['body']['providerOwner'], + 'rootDirectory' => $phpRuntime['providerRootDirectory'], + 'type' => 'branch', + 'reference' => 'main', + ] + ); + + $this->assertEquals(202, $deployment['headers']['status-code']); + $this->assertNotEmpty($deployment['body']['$id']); + + $deployment = $this->getDeployment($functionId, $deployment['body']['$id']); + $this->assertEquals(200, $deployment['headers']['status-code']); + + $function = $this->cleanupFunction($functionId); + } + + public function testCreateFunctionAndDeploymentFromTemplateCommit() + { + $starterTemplate = $this->getTemplate('starter'); + $this->assertEquals(200, $starterTemplate['headers']['status-code']); + + // Ensure we have the latest commit + $this->assertArrayHasKey('latestCommit', $starterTemplate['body']); + $latestCommit = $starterTemplate['body']['latestCommit']; + + $phpRuntime = array_values(array_filter($starterTemplate['body']['runtimes'], function ($runtime) { + return $runtime['name'] === 'node-22'; + }))[0]; + + // If this fails, the template has variables, and this test needs to be updated + $this->assertEmpty($starterTemplate['body']['variables']); + + $function = $this->createFunction( + [ + 'functionId' => ID::unique(), + 'name' => $starterTemplate['body']['name'] . ' - Commit Test', + 'runtime' => 'node-22', + 'execute' => $starterTemplate['body']['permissions'], + 'entrypoint' => $phpRuntime['entrypoint'], + 'events' => $starterTemplate['body']['events'], + 'schedule' => $starterTemplate['body']['cron'], + 'timeout' => $starterTemplate['body']['timeout'], + 'commands' => $phpRuntime['commands'], + 'scopes' => $starterTemplate['body']['scopes'], + ] + ); + + $this->assertEquals(201, $function['headers']['status-code']); + $this->assertNotEmpty($function['body']['$id']); + + $functionId = $function['body']['$id'] ?? ''; + + // Deploy using commit + $deployment = $this->createTemplateDeployment( + $functionId, + [ + 'resourceId' => ID::unique(), + 'activate' => true, + 'repository' => $starterTemplate['body']['providerRepositoryId'], + 'owner' => $starterTemplate['body']['providerOwner'], + 'rootDirectory' => $phpRuntime['providerRootDirectory'], + 'type' => 'commit', + 'reference' => $latestCommit, + ] + ); + + $this->assertEquals(202, $deployment['headers']['status-code']); + $this->assertNotEmpty($deployment['body']['$id']); + + $deployment = $this->getDeployment($functionId, $deployment['body']['$id']); + $this->assertEquals(200, $deployment['headers']['status-code']); + + $function = $this->cleanupFunction($functionId); + } + /** * @depends testUpdateFunction */ diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index 93c55b82b7..004032452b 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -329,6 +329,35 @@ trait SitesBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]); + + // Fetch latest commit from GitHub API if template has provider info + if ( + isset($template['body']['providerOwner']) && + isset($template['body']['providerRepositoryId']) + ) { + $owner = $template['body']['providerOwner']; + $repo = $template['body']['providerRepositoryId']; + + // GitHub API to get latest commit from main branch + $ch = curl_init("https://api.github.com/repos/{$owner}/{$repo}/commits/main"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'User-Agent: Appwrite', + 'Accept: application/vnd.github.v3+json' + ]); + + $response = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + if ($httpCode === 200) { + $commitData = json_decode($response, true); + if (isset($commitData['sha'])) { + $template['body']['latestCommit'] = $commitData['sha']; + } + } + } + return $template; } diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index c8301b9428..524e8a09f3 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1563,7 +1563,154 @@ class SitesCustomServerTest extends Scope 'repository' => $template['providerRepositoryId'], 'owner' => $template['providerOwner'], 'rootDirectory' => $template['frameworks'][0]['providerRootDirectory'], - 'version' => $template['providerVersion'], + 'type' => 'tag', + 'reference' => $template['providerVersion'], + 'activate' => true + ]); + + $this->assertEquals(202, $deployment['headers']['status-code']); + $this->assertNotEmpty($deployment['body']['$id']); + + $deployment = $this->getDeployment($siteId, $deployment['body']['$id']); + $this->assertEquals(200, $deployment['headers']['status-code']); + $this->assertEquals(0, $deployment['body']['sourceSize']); + $this->assertEquals(0, $deployment['body']['buildSize']); + $this->assertEquals(0, $deployment['body']['totalSize']); + + $this->assertEventually(function () use ($siteId) { + $site = $this->getSite($siteId); + $this->assertNotEmpty($site['body']['deploymentId']); + }, 50000, 500); + + $domain = $this->setupSiteDomain($siteId); + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://' . $domain); + + $response = $proxyClient->call(Client::METHOD_GET, '/'); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertStringContainsString("Astro Blog", $response['body']); + $this->assertStringContainsString("Hello, Astronaut!", $response['body']); + + $response = $proxyClient->call(Client::METHOD_GET, '/about'); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertStringContainsString("Astro Blog", $response['body']); + $this->assertStringContainsString("About Me", $response['body']); + + $deployment = $this->getDeployment($siteId, $deployment['body']['$id']); + $this->assertEquals(200, $deployment['headers']['status-code']); + $this->assertGreaterThan(0, $deployment['body']['sourceSize']); + $this->assertGreaterThan(0, $deployment['body']['buildSize']); + $totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize']; + $this->assertEquals($totalSize, $deployment['body']['totalSize']); + + $this->cleanupSite($siteId); + } + + public function testCreateSiteFromTemplateBranch() + { + $template = $this->getTemplate('playground-for-astro'); + $this->assertEquals(200, $template['headers']['status-code']); + + $template = $template['body']; + + $siteId = $this->setupSite([ + 'siteId' => ID::unique(), + 'name' => 'Astro Blog - Branch Test', + 'framework' => $template['frameworks'][0]['key'], + 'adapter' => $template['frameworks'][0]['adapter'], + 'buildRuntime' => $template['frameworks'][0]['buildRuntime'], + 'outputDirectory' => $template['frameworks'][0]['outputDirectory'], + 'buildCommand' => $template['frameworks'][0]['buildCommand'], + 'installCommand' => $template['frameworks'][0]['installCommand'], + 'fallbackFile' => $template['frameworks'][0]['fallbackFile'], + ]); + + $this->assertNotEmpty($siteId); + + // Deploy using branch + $deployment = $this->createTemplateDeployment($siteId, [ + 'repository' => $template['providerRepositoryId'], + 'owner' => $template['providerOwner'], + 'rootDirectory' => $template['frameworks'][0]['providerRootDirectory'], + 'type' => 'branch', + 'reference' => 'main', + 'activate' => true + ]); + + $this->assertEquals(202, $deployment['headers']['status-code']); + $this->assertNotEmpty($deployment['body']['$id']); + + $deployment = $this->getDeployment($siteId, $deployment['body']['$id']); + $this->assertEquals(200, $deployment['headers']['status-code']); + $this->assertEquals(0, $deployment['body']['sourceSize']); + $this->assertEquals(0, $deployment['body']['buildSize']); + $this->assertEquals(0, $deployment['body']['totalSize']); + + $this->assertEventually(function () use ($siteId) { + $site = $this->getSite($siteId); + $this->assertNotEmpty($site['body']['deploymentId']); + }, 50000, 500); + + $domain = $this->setupSiteDomain($siteId); + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://' . $domain); + + $response = $proxyClient->call(Client::METHOD_GET, '/'); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertStringContainsString("Astro Blog", $response['body']); + $this->assertStringContainsString("Hello, Astronaut!", $response['body']); + + $response = $proxyClient->call(Client::METHOD_GET, '/about'); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertStringContainsString("Astro Blog", $response['body']); + $this->assertStringContainsString("About Me", $response['body']); + + $deployment = $this->getDeployment($siteId, $deployment['body']['$id']); + $this->assertEquals(200, $deployment['headers']['status-code']); + $this->assertGreaterThan(0, $deployment['body']['sourceSize']); + $this->assertGreaterThan(0, $deployment['body']['buildSize']); + $totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize']; + $this->assertEquals($totalSize, $deployment['body']['totalSize']); + + $this->cleanupSite($siteId); + } + + public function testCreateSiteFromTemplateCommit() + { + $template = $this->getTemplate('playground-for-astro'); + $this->assertEquals(200, $template['headers']['status-code']); + + // Ensure we have the latest commit + $this->assertArrayHasKey('latestCommit', $template['body']); + $latestCommit = $template['body']['latestCommit']; + + $template = $template['body']; + + $siteId = $this->setupSite([ + 'siteId' => ID::unique(), + 'name' => 'Astro Blog - Commit Test', + 'framework' => $template['frameworks'][0]['key'], + 'adapter' => $template['frameworks'][0]['adapter'], + 'buildRuntime' => $template['frameworks'][0]['buildRuntime'], + 'outputDirectory' => $template['frameworks'][0]['outputDirectory'], + 'buildCommand' => $template['frameworks'][0]['buildCommand'], + 'installCommand' => $template['frameworks'][0]['installCommand'], + 'fallbackFile' => $template['frameworks'][0]['fallbackFile'], + ]); + + $this->assertNotEmpty($siteId); + + // Deploy using commit + $deployment = $this->createTemplateDeployment($siteId, [ + 'repository' => $template['providerRepositoryId'], + 'owner' => $template['providerOwner'], + 'rootDirectory' => $template['frameworks'][0]['providerRootDirectory'], + 'type' => 'commit', + 'reference' => $latestCommit, 'activate' => true ]); From 2a145bc284d1edff27014187b316493af85448b6 Mon Sep 17 00:00:00 2001 From: Atharva Deosthale Date: Fri, 19 Sep 2025 18:18:44 +0530 Subject: [PATCH 09/13] address reviews regarding tests --- .../e2e/Services/Functions/FunctionsBase.php | 41 ++++----- .../Functions/FunctionsCustomServerTest.php | 87 ++++++++++++------- tests/e2e/Services/Sites/SitesBase.php | 41 ++++----- .../Services/Sites/SitesCustomServerTest.php | 9 +- 4 files changed, 97 insertions(+), 81 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsBase.php b/tests/e2e/Services/Functions/FunctionsBase.php index 4eb31c08ac..7403b23a73 100644 --- a/tests/e2e/Services/Functions/FunctionsBase.php +++ b/tests/e2e/Services/Functions/FunctionsBase.php @@ -268,35 +268,30 @@ trait FunctionsBase 'x-appwrite-project' => $this->getProject()['$id'], ])); - // Fetch latest commit from GitHub API if template has provider info - if ( - isset($template['body']['providerOwner']) && - isset($template['body']['providerRepositoryId']) - ) { - $owner = $template['body']['providerOwner']; - $repo = $template['body']['providerRepositoryId']; + return $template; + } - // GitHub API to get latest commit from main branch - $ch = curl_init("https://api.github.com/repos/{$owner}/{$repo}/commits/main"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, [ - 'User-Agent: Appwrite', - 'Accept: application/vnd.github.v3+json' - ]); + protected function helperGetLatestCommit(string $owner, string $repository): ?string + { + $ch = curl_init("https://api.github.com/repos/{$owner}/{$repository}/commits/main"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'User-Agent: Appwrite', + 'Accept: application/vnd.github.v3+json' + ]); - $response = curl_exec($ch); - $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - curl_close($ch); + $response = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); - if ($httpCode === 200) { - $commitData = json_decode($response, true); - if (isset($commitData['sha'])) { - $template['body']['latestCommit'] = $commitData['sha']; - } + if ($httpCode === 200) { + $commitData = json_decode($response, true); + if (isset($commitData['sha'])) { + return $commitData['sha']; } } - return $template; + return null; } protected function createExecution(string $functionId, mixed $params = []): mixed diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 8a774ed8bb..5672bd9817 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -361,7 +361,7 @@ class FunctionsCustomServerTest extends Scope $starterTemplate = $this->getTemplate('starter'); $this->assertEquals(200, $starterTemplate['headers']['status-code']); - $phpRuntime = array_values(array_filter($starterTemplate['body']['runtimes'], function ($runtime) { + $runtime = array_values(array_filter($starterTemplate['body']['runtimes'], function ($runtime) { return $runtime['name'] === 'node-22'; }))[0]; @@ -374,15 +374,15 @@ class FunctionsCustomServerTest extends Scope 'name' => $starterTemplate['body']['name'], 'runtime' => 'node-22', 'execute' => $starterTemplate['body']['permissions'], - 'entrypoint' => $phpRuntime['entrypoint'], + 'entrypoint' => $runtime['entrypoint'], 'events' => $starterTemplate['body']['events'], 'schedule' => $starterTemplate['body']['cron'], 'timeout' => $starterTemplate['body']['timeout'], - 'commands' => $phpRuntime['commands'], + 'commands' => $runtime['commands'], 'scopes' => $starterTemplate['body']['scopes'], 'templateRepository' => $starterTemplate['body']['providerRepositoryId'], 'templateOwner' => $starterTemplate['body']['providerOwner'], - 'templateRootDirectory' => $phpRuntime['providerRootDirectory'], + 'templateRootDirectory' => $runtime['providerRootDirectory'], 'templateVersion' => $starterTemplate['body']['providerVersion'], ] ); @@ -399,7 +399,7 @@ class FunctionsCustomServerTest extends Scope 'activate' => true, 'repository' => $starterTemplate['body']['providerRepositoryId'], 'owner' => $starterTemplate['body']['providerOwner'], - 'rootDirectory' => $phpRuntime['providerRootDirectory'], + 'rootDirectory' => $runtime['providerRootDirectory'], 'type' => 'tag', 'reference' => $starterTemplate['body']['providerVersion'], ] @@ -408,11 +408,20 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(202, $deployment['headers']['status-code']); $this->assertNotEmpty($deployment['body']['$id']); - $deployment = $this->getDeployment($functionId, $deployment['body']['$id']); + // Wait for deployment to be ready + $deploymentId = $deployment['body']['$id']; + $this->assertEventually(function () use ($functionId, $deploymentId) { + $deployment = $this->getDeployment($functionId, $deploymentId); + $this->assertEquals('ready', $deployment['body']['status']); + }, 50000, 500); + + // Verify deployment sizes + $deployment = $this->getDeployment($functionId, $deploymentId); $this->assertEquals(200, $deployment['headers']['status-code']); - $this->assertEquals(0, $deployment['body']['sourceSize']); - $this->assertEquals(0, $deployment['body']['buildSize']); - $this->assertEquals(0, $deployment['body']['totalSize']); + $this->assertGreaterThan(0, $deployment['body']['sourceSize']); + $this->assertGreaterThan(0, $deployment['body']['buildSize']); + $totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize']; + $this->assertEquals($totalSize, $deployment['body']['totalSize']); $deployments = $this->listDeployments($functionId); @@ -422,16 +431,7 @@ class FunctionsCustomServerTest extends Scope $lastDeployment = $deployments['body']['deployments'][0]; $this->assertNotEmpty($lastDeployment['$id']); - $this->assertEquals(0, $lastDeployment['sourceSize']); - - $deploymentId = $lastDeployment['$id']; - - $this->assertEventually(function () use ($functionId, $deploymentId) { - $deployment = $this->getDeployment($functionId, $deploymentId); - - $this->assertEquals(200, $deployment['headers']['status-code']); - $this->assertEquals('ready', $deployment['body']['status']); - }, 50000, 1000); + $this->assertGreaterThan(0, $lastDeployment['sourceSize']); $function = $this->getFunction($functionId); @@ -508,7 +508,7 @@ class FunctionsCustomServerTest extends Scope $starterTemplate = $this->getTemplate('starter'); $this->assertEquals(200, $starterTemplate['headers']['status-code']); - $phpRuntime = array_values(array_filter($starterTemplate['body']['runtimes'], function ($runtime) { + $runtime = array_values(array_filter($starterTemplate['body']['runtimes'], function ($runtime) { return $runtime['name'] === 'node-22'; }))[0]; @@ -521,11 +521,11 @@ class FunctionsCustomServerTest extends Scope 'name' => $starterTemplate['body']['name'] . ' - Branch Test', 'runtime' => 'node-22', 'execute' => $starterTemplate['body']['permissions'], - 'entrypoint' => $phpRuntime['entrypoint'], + 'entrypoint' => $runtime['entrypoint'], 'events' => $starterTemplate['body']['events'], 'schedule' => $starterTemplate['body']['cron'], 'timeout' => $starterTemplate['body']['timeout'], - 'commands' => $phpRuntime['commands'], + 'commands' => $runtime['commands'], 'scopes' => $starterTemplate['body']['scopes'], ] ); @@ -543,7 +543,7 @@ class FunctionsCustomServerTest extends Scope 'activate' => true, 'repository' => $starterTemplate['body']['providerRepositoryId'], 'owner' => $starterTemplate['body']['providerOwner'], - 'rootDirectory' => $phpRuntime['providerRootDirectory'], + 'rootDirectory' => $runtime['providerRootDirectory'], 'type' => 'branch', 'reference' => 'main', ] @@ -552,8 +552,18 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(202, $deployment['headers']['status-code']); $this->assertNotEmpty($deployment['body']['$id']); - $deployment = $this->getDeployment($functionId, $deployment['body']['$id']); + $deploymentId = $deployment['body']['$id']; + $this->assertEventually(function () use ($functionId, $deploymentId) { + $deployment = $this->getDeployment($functionId, $deploymentId); + $this->assertEquals('ready', $deployment['body']['status']); + }, 50000, 500); + + $deployment = $this->getDeployment($functionId, $deploymentId); $this->assertEquals(200, $deployment['headers']['status-code']); + $this->assertGreaterThan(0, $deployment['body']['sourceSize']); + $this->assertGreaterThan(0, $deployment['body']['buildSize']); + $totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize']; + $this->assertEquals($totalSize, $deployment['body']['totalSize']); $function = $this->cleanupFunction($functionId); } @@ -563,11 +573,14 @@ class FunctionsCustomServerTest extends Scope $starterTemplate = $this->getTemplate('starter'); $this->assertEquals(200, $starterTemplate['headers']['status-code']); - // Ensure we have the latest commit - $this->assertArrayHasKey('latestCommit', $starterTemplate['body']); - $latestCommit = $starterTemplate['body']['latestCommit']; + // Get latest commit using helper function + $latestCommit = $this->helperGetLatestCommit( + $starterTemplate['body']['providerOwner'], + $starterTemplate['body']['providerRepositoryId'] + ); + $this->assertNotNull($latestCommit); - $phpRuntime = array_values(array_filter($starterTemplate['body']['runtimes'], function ($runtime) { + $runtime = array_values(array_filter($starterTemplate['body']['runtimes'], function ($runtime) { return $runtime['name'] === 'node-22'; }))[0]; @@ -580,11 +593,11 @@ class FunctionsCustomServerTest extends Scope 'name' => $starterTemplate['body']['name'] . ' - Commit Test', 'runtime' => 'node-22', 'execute' => $starterTemplate['body']['permissions'], - 'entrypoint' => $phpRuntime['entrypoint'], + 'entrypoint' => $runtime['entrypoint'], 'events' => $starterTemplate['body']['events'], 'schedule' => $starterTemplate['body']['cron'], 'timeout' => $starterTemplate['body']['timeout'], - 'commands' => $phpRuntime['commands'], + 'commands' => $runtime['commands'], 'scopes' => $starterTemplate['body']['scopes'], ] ); @@ -602,7 +615,7 @@ class FunctionsCustomServerTest extends Scope 'activate' => true, 'repository' => $starterTemplate['body']['providerRepositoryId'], 'owner' => $starterTemplate['body']['providerOwner'], - 'rootDirectory' => $phpRuntime['providerRootDirectory'], + 'rootDirectory' => $runtime['providerRootDirectory'], 'type' => 'commit', 'reference' => $latestCommit, ] @@ -611,8 +624,18 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(202, $deployment['headers']['status-code']); $this->assertNotEmpty($deployment['body']['$id']); - $deployment = $this->getDeployment($functionId, $deployment['body']['$id']); + $deploymentId = $deployment['body']['$id']; + $this->assertEventually(function () use ($functionId, $deploymentId) { + $deployment = $this->getDeployment($functionId, $deploymentId); + $this->assertEquals('ready', $deployment['body']['status']); + }, 50000, 500); + + $deployment = $this->getDeployment($functionId, $deploymentId); $this->assertEquals(200, $deployment['headers']['status-code']); + $this->assertGreaterThan(0, $deployment['body']['sourceSize']); + $this->assertGreaterThan(0, $deployment['body']['buildSize']); + $totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize']; + $this->assertEquals($totalSize, $deployment['body']['totalSize']); $function = $this->cleanupFunction($functionId); } diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index 004032452b..7eb5d9699c 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -330,35 +330,30 @@ trait SitesBase 'x-appwrite-project' => $this->getProject()['$id'], ]); - // Fetch latest commit from GitHub API if template has provider info - if ( - isset($template['body']['providerOwner']) && - isset($template['body']['providerRepositoryId']) - ) { - $owner = $template['body']['providerOwner']; - $repo = $template['body']['providerRepositoryId']; + return $template; + } - // GitHub API to get latest commit from main branch - $ch = curl_init("https://api.github.com/repos/{$owner}/{$repo}/commits/main"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, [ - 'User-Agent: Appwrite', - 'Accept: application/vnd.github.v3+json' - ]); + protected function helperGetLatestCommit(string $owner, string $repository): ?string + { + $ch = curl_init("https://api.github.com/repos/{$owner}/{$repository}/commits/main"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'User-Agent: Appwrite', + 'Accept: application/vnd.github.v3+json' + ]); - $response = curl_exec($ch); - $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - curl_close($ch); + $response = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); - if ($httpCode === 200) { - $commitData = json_decode($response, true); - if (isset($commitData['sha'])) { - $template['body']['latestCommit'] = $commitData['sha']; - } + if ($httpCode === 200) { + $commitData = json_decode($response, true); + if (isset($commitData['sha'])) { + return $commitData['sha']; } } - return $template; + return null; } protected function deleteSite(string $siteId): mixed diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 524e8a09f3..f7015ccb48 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1684,9 +1684,12 @@ class SitesCustomServerTest extends Scope $template = $this->getTemplate('playground-for-astro'); $this->assertEquals(200, $template['headers']['status-code']); - // Ensure we have the latest commit - $this->assertArrayHasKey('latestCommit', $template['body']); - $latestCommit = $template['body']['latestCommit']; + // Get latest commit using helper function + $latestCommit = $this->helperGetLatestCommit( + $template['body']['providerOwner'], + $template['body']['providerRepositoryId'] + ); + $this->assertNotNull($latestCommit); $template = $template['body']; From 1a19e01d69d563aff5942ea836cfdb8b484875ee Mon Sep 17 00:00:00 2001 From: Atharva Deosthale Date: Fri, 19 Sep 2025 18:30:42 +0530 Subject: [PATCH 10/13] attempt to fix tests --- tests/e2e/General/UsageTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index 8f5477331a..dc49d27aea 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -28,6 +28,7 @@ class UsageTest extends Scope FunctionsBase::createVariable insteadof SitesBase; FunctionsBase::getVariable insteadof SitesBase; FunctionsBase::listVariables insteadof SitesBase; + FunctionsBase::helperGetLatestCommit insteadof SitesBase; FunctionsBase::updateVariable insteadof SitesBase; FunctionsBase::deleteVariable insteadof SitesBase; FunctionsBase::getDeployment insteadof SitesBase; From 7d4486b9e691789bed9a68e62df2f455e18d57ce Mon Sep 17 00:00:00 2001 From: Atharva Deosthale Date: Fri, 19 Sep 2025 18:42:25 +0530 Subject: [PATCH 11/13] more fixes to tests --- tests/e2e/Services/Functions/FunctionsCustomServerTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 5672bd9817..a3f8768676 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -500,7 +500,7 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals($deployment['body']['$id'], $function['body']['deploymentId']); $this->assertEquals($deployment['body']['$createdAt'], $function['body']['deploymentCreatedAt']); - $function = $this->cleanupFunction($functionId); + $this->cleanupFunction($functionId); } public function testCreateFunctionAndDeploymentFromTemplateBranch() @@ -565,7 +565,7 @@ class FunctionsCustomServerTest extends Scope $totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize']; $this->assertEquals($totalSize, $deployment['body']['totalSize']); - $function = $this->cleanupFunction($functionId); + $this->cleanupFunction($functionId); } public function testCreateFunctionAndDeploymentFromTemplateCommit() @@ -637,7 +637,7 @@ class FunctionsCustomServerTest extends Scope $totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize']; $this->assertEquals($totalSize, $deployment['body']['totalSize']); - $function = $this->cleanupFunction($functionId); + $this->cleanupFunction($functionId); } /** From 5963b2baf799d99c5bcb7610595b5ed70fc4ef48 Mon Sep 17 00:00:00 2001 From: Atharva Deosthale Date: Tue, 23 Sep 2025 18:00:14 +0530 Subject: [PATCH 12/13] change request filter to versions below 1.9.0 --- app/controllers/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index c663091677..f0294e9274 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -907,7 +907,7 @@ App::init() $dbForProject = $getProjectDB($project); $request->addFilter(new RequestV20($dbForProject, $route->getPathValues($request))); } - if (version_compare($requestFormat, '1.8.1', '<')) { + if (version_compare($requestFormat, '1.9.0', '<')) { $request->addFilter(new RequestV21()); } } From d411b741b32c810b02999ffc7a3c60833c49ab9f Mon Sep 17 00:00:00 2001 From: Atharva Deosthale Date: Wed, 12 Nov 2025 23:06:18 +0530 Subject: [PATCH 13/13] address comments --- .../Modules/Functions/Http/Deployments/Template/Create.php | 3 ++- .../Modules/Sites/Http/Deployments/Template/Create.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php index 5e0266a09e..2f150dbe18 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/Template/Create.php @@ -103,7 +103,8 @@ class Create extends Base throw new Exception(Exception::FUNCTION_NOT_FOUND); } - $branchUrl = $type == GitHub::CLONE_TYPE_BRANCH ? "https://github.com/$owner/$repository/tree/$reference" : ""; + $branchUrl = "https://github.com/$owner/$repository/blob/$reference"; + $repositoryUrl = "https://github.com/$owner/$repository"; $template = new Document([ diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php index d7196eb3d5..d55d09584d 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Template/Create.php @@ -105,7 +105,7 @@ class Create extends Base throw new Exception(Exception::SITE_NOT_FOUND); } - $branchUrl = $type == GitHub::CLONE_TYPE_BRANCH ? "https://github.com/$owner/$repository/tree/$reference" : ""; + $branchUrl = "https://github.com/$owner/$repository/blob/$reference"; $repositoryUrl = "https://github.com/$owner/$repository"; $template = new Document([