Skip to content

Commit 743b159

Browse files
Merge pull request #928 from appwrite/fix-push-confirmation
Fix: push confirmation
2 parents 4aaa603 + 3a058e9 commit 743b159

File tree

3 files changed

+49
-43
lines changed

3 files changed

+49
-43
lines changed

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

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { Command } = require("commander");
55
const { localConfig, globalConfig, KeysAttributes, KeysFunction, whitelistKeys, KeysTopics, KeysStorage, KeysTeams, } = require("../config");
66
const { Spinner, SPINNER_ARC, SPINNER_DOTS } = require('../spinner');
77
const { paginate } = require('../paginate');
8-
const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionPushChanges, questionsPushMessagingTopics, questionsPushResources } = require("../questions");
8+
const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionPushChanges, questionPushChangesConfirmation, questionsPushMessagingTopics, questionsPushResources } = require("../questions");
99
const { cliConfig, actionRunner, success, warn, log, hint, error, commandDescriptions, drawTable } = require("../parser");
1010
const { proxyListRules } = require('./proxy');
1111
const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsGetDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions');
@@ -340,6 +340,33 @@ const awaitPools = {
340340
},
341341
}
342342

343+
const getConfirmation = async () => {
344+
if (!cliConfig.force) {
345+
async function fixConfirmation() {
346+
const answers = await inquirer.prompt(questionPushChangesConfirmation);
347+
if(answers.changes !== 'YES' && answers.changes !== 'NO') {
348+
return await fixConfirmation();
349+
}
350+
351+
return answers.changes;
352+
}
353+
354+
let answers = await inquirer.prompt(questionPushChanges);
355+
if(answers.changes !== 'YES' && answers.changes !== 'NO') {
356+
answers.changes = await fixConfirmation();
357+
}
358+
359+
if (answers.changes === 'YES') {
360+
return true;
361+
}
362+
363+
warn('Skipping push action. Changes were not applied.');
364+
return false;
365+
}
366+
367+
return true;
368+
};
369+
343370
const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural, skipKeys = []) => {
344371
log('Checking for changes');
345372
const changes = [];
@@ -385,11 +412,8 @@ const approveChanges = async (resource, resourceGetFunction, keys, resourceName,
385412
}
386413

387414
drawTable(changes);
388-
if (!cliConfig.force) {
389-
const answers = await inquirer.prompt(questionPushChanges);
390-
if (answers.changes.toLowerCase() === 'yes') {
391-
return true;
392-
}
415+
if((await getConfirmation()) === true) {
416+
return true;
393417
}
394418

395419
success(`Successfully pushed 0 ${resourcePlural}.`);
@@ -769,9 +793,7 @@ const attributesToCreate = async (remoteAttributes, localAttributes, collection,
769793
log(`Attribute recreation will cause ${chalk.red('loss of data')}`);
770794
}
771795

772-
const answers = await inquirer.prompt(questionPushChanges);
773-
774-
if (answers.changes.toLowerCase() !== 'yes') {
796+
if((await getConfirmation()) !== true) {
775797
return changedAttributes;
776798
}
777799
}
@@ -893,12 +915,9 @@ const pushSettings = async () => {
893915

894916
if (changes.length > 0) {
895917
drawTable(changes);
896-
if (!cliConfig.force) {
897-
const answers = await inquirer.prompt(questionPushChanges);
898-
if (answers.changes.toLowerCase() !== 'yes') {
899-
success(`Successfully pushed 0 project settings.`);
900-
return;
901-
}
918+
if((await getConfirmation()) !== true) {
919+
success(`Successfully pushed 0 project settings.`);
920+
return;
902921
}
903922
}
904923
} catch (e) {
@@ -1391,10 +1410,10 @@ const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false
13911410
throw e;
13921411
}
13931412
numberOfCollections++;
1394-
success(`Pushed ${collection.name} ( ${collection['$id']} )`);
1413+
success(`Successfully pushed ${collection.name} ( ${collection['$id']} )`);
13951414
}
13961415

1397-
success(`Pushed ${numberOfCollections} collections`);
1416+
success(`Successfully pushed ${numberOfCollections} collections`);
13981417
}
13991418

14001419
const pushBucket = async ({ returnOnZero } = { returnOnZero: false }) => {
@@ -1557,7 +1576,6 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) =>
15571576

15581577
let topicsIds = [];
15591578
const configTopics = localConfig.getMessagingTopics();
1560-
let overrideExisting = cliConfig.force;
15611579

15621580
if (cliConfig.all) {
15631581
checkDeployConditions(localConfig);
@@ -1584,13 +1602,6 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) =>
15841602
topics.push(...idTopic);
15851603
}
15861604

1587-
if (!cliConfig.force) {
1588-
const answers = await inquirer.prompt(questionsPushMessagingTopics[1])
1589-
if (answers.override.toLowerCase() === "yes") {
1590-
overrideExisting = true;
1591-
}
1592-
}
1593-
15941605
if (!(await approveChanges(topics, messagingGetTopic, KeysTopics, 'topicId', 'topics'))) {
15951606
return;
15961607
}
@@ -1607,11 +1618,6 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) =>
16071618
})
16081619
log(`Topic ${topic.name} ( ${topic['$id']} ) already exists.`);
16091620

1610-
if (!overrideExisting) {
1611-
log(`Skipping ${topic.name} ( ${topic['$id']} )`);
1612-
continue;
1613-
}
1614-
16151621
await messagingUpdateTopic({
16161622
topicId: topic['$id'],
16171623
name: topic.name,

templates/cli/lib/questions.js.twig

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,6 @@ const questionsPushFunctions = [
631631
return choices;
632632
}
633633
},
634-
{
635-
type: "input",
636-
name: "override",
637-
message: 'Are you sure you want to override this function\'s variables? This can lead to loss of secrets! Type "YES" to confirm.'
638-
},
639634
]
640635

641636
const questionsPushCollections = [
@@ -663,7 +658,15 @@ const questionPushChanges = [
663658
{
664659
type: "input",
665660
name: "changes",
666-
message: `Would you like to apply these changes? Type "YES" to confirm.`
661+
message: `Are you sure you want to apply these changes? (YES/NO)`
662+
}
663+
];
664+
665+
const questionPushChangesFix = [
666+
{
667+
type: "input",
668+
name: "changes",
669+
message: `Please type 'YES' or 'NO':`
667670
}
668671
];
669672

@@ -693,6 +696,7 @@ const questionsPushMessagingTopics = [
693696
type: "checkbox",
694697
name: "topics",
695698
message: "Which messaging topic would you like to push?",
699+
validate: (value) => validateRequired('topics', value),
696700
when: () => localConfig.getMessagingTopics().length > 0,
697701
choices: () => {
698702
let topics = localConfig.getMessagingTopics();
@@ -704,11 +708,6 @@ const questionsPushMessagingTopics = [
704708
}
705709
});
706710
}
707-
},
708-
{
709-
type: "input",
710-
name: "override",
711-
message: 'Would you like to override existing topics? This can lead to loss of data! Type "YES" to confirm.'
712711
}
713712
]
714713

@@ -847,5 +846,6 @@ module.exports = {
847846
questionGetEndpoint,
848847
questionsInitResources,
849848
questionsCreateTeam,
850-
questionPushChanges
849+
questionPushChanges,
850+
questionPushChangesFix
851851
};

tests/Base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function setUp(): void
143143

144144
\exec('
145145
cd ./mock-server && \
146-
docker-compose build && \
146+
docker compose build && \
147147
docker compose up -d --force-recreate
148148
');
149149
}

0 commit comments

Comments
 (0)