Skip to content

Commit 009a6e2

Browse files
committed
feat(cli): Pull last deployment instead of local when available
1 parent 81524aa commit 009a6e2

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

templates/cli/lib/commands/pull.js.twig

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const inquirer = require("inquirer");
66
const { messagingListTopics } = require("./messaging");
77
const { teamsList } = require("./teams");
88
const { projectsGet } = require("./projects");
9-
const { functionsList, functionsDownloadDeployment } = require("./functions");
9+
const { functionsList, functionsDownloadDeployment, functionsListDeployments } = require("./functions");
1010
const { databasesGet, databasesListCollections, databasesList } = require("./databases");
1111
const { storageListBuckets } = require("./storage");
1212
const { localConfig } = require("../config");
@@ -108,10 +108,30 @@ const pullFunctions = async ({ code, withVariables }) => {
108108
if (allowCodePull) {
109109
log("Pulling active deployment's code ...");
110110

111+
let deploymentId = func['deployment'];
112+
113+
try {
114+
const fetchResponse = await functionsListDeployments({
115+
functionId: func['$id'],
116+
queries: [
117+
JSON.stringify({ method: 'limit', values: [1] }),
118+
JSON.stringify({ method: 'orderDesc', values: [''] })
119+
],
120+
parseOutput: false
121+
});
122+
123+
if (fetchResponse['total'] > 0) {
124+
deploymentId = fetchResponse['deployments'][0]['$id'];
125+
}
126+
127+
} catch (e) {
128+
log("Can't get last deployment ID, using local value instead")
129+
}
130+
111131
const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz`
112132
await functionsDownloadDeployment({
113133
functionId: func['$id'],
114-
deploymentId: func['deployment'],
134+
deploymentId,
115135
destination: compressedFileName,
116136
overrideForCli: true,
117137
parseOutput: false

0 commit comments

Comments
 (0)