-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SALTO-218: apply changes from state to bps post deploy #343
Conversation
f568d82
to
fd69192
Compare
getConfigFromUser, | ||
shouldDeploy({ stdout: this.stdout, stderr: this.stderr }), | ||
(action: PlanItem) => this.updateCurrentAction(action), this.force) | ||
this.endCurrentAction() | ||
return CliExitCode.Success | ||
if (result.changes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's sync tomorrow about how this works with my changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 👍
packages/cli/src/callbacks.ts
Outdated
return getApprovedChanges(changes, formatFetchChangeForApproval, isConflict) | ||
} | ||
|
||
export const getApprovedDetailedChanges = async ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe getApprovedDeployChanges
for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
packages/cli/src/callbacks.ts
Outdated
message: formatFetchChangeForApproval(change, idx, changes.length), | ||
when: answers => isConflict(change) || !shouldDeployAll(answers), | ||
message: message(change, idx, changes.length), | ||
when: answers => (when ? when(change) : false) || !shouldDeployAll(answers), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not related to this PR but shouldDeployAll
should not be called deploy
, should probably be called shouldApproveAll
Also, allowing the function when
to come from an external source can cause confusion IMO because its decision is sometimes overridden by logic that is internal to this function.
Generally I think there is no reason to have different behavior for changes originating from apply and changes originating from fetch, IMO they can use the same types and the same flow and I think that would make the code much simpler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how we can do it, in fetch flow we have FetchChange and in deploy flow we have diff between state and workspace which is only DetailedChange. Do you suggest to build in deploy flow fake FetchChange
?
packages/cli/src/commands/deploy.ts
Outdated
getConfigFromUser, | ||
shouldDeploy({ stdout: this.stdout, stderr: this.stderr }), | ||
(action: PlanItem) => this.updateCurrentAction(action), this.force) | ||
this.endCurrentAction() | ||
return CliExitCode.Success | ||
if (result.changes) { | ||
const changes = wu(result.changes).toArray() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style nit: no need to use wu
when just filling an array, can be written as [...result.changes]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
packages/cli/src/formatter.ts
Outdated
header(Prompts.FETCH_CHANGE_HEADER(idx + 1, totalChanges)), | ||
body(formatDetailedChanges([[change]])), | ||
header(Prompts.FETCH_SHOULD_APPROVE_CHANGE), | ||
].join('\n')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a change with no conflict behaves exactly the same (and we really want to the be exactly the same for UX consistency) so this code duplication is not a good idea IMO
export const importFromCsvFile = async (): Promise<void> => {} | ||
export const deleteFromCsvFile = async (): Promise<void> => {} | ||
export const importFromCsvFile = async (): Promise<void> => { } | ||
export const deleteFromCsvFile = async (): Promise<void> => { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why add the space here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄 vscode added it
@@ -105,13 +105,12 @@ export const deployCommand = async ( | |||
} | |||
|
|||
try { | |||
deployProcess = deploy( | |||
await deploy( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cli and vscode should behave consistently, if the cli command updates the workspace, so should vscode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you right opened: SALTO-296
packages/salto/src/api.ts
Outdated
export const preview = async ( | ||
workspace: Workspace, | ||
): Promise<Plan> => { | ||
const state = new State(workspace.config.stateLocation) | ||
return getPlan(await state.get(), workspace.elements) | ||
} | ||
|
||
export interface DeployResult { | ||
sucesses: boolean | ||
changes?: Iterable<DetailedChange> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should prefer returning an empty list to having changes optional here. optional fields are annoying to handle in the code and when using lists it means there are actually two different ways for express no changes (undefined and empty list)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the optional is for the case of success=false
not sure what's better..
packages/salto/src/api.ts
Outdated
@@ -56,8 +57,12 @@ export const deploy = async ( | |||
reportProgress, | |||
(action, element) => deployActionOnState(state, action, element) | |||
) | |||
return { | |||
sucesses: true, | |||
changes: getDetailedChanges(workspace.elements, await state.get()) || undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need || undefined
here? doesn't really make sense given that getDetailedChanges
should always return an iterable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure how this is going to behave - you probably right and I will remove it
packages/cli/src/callbacks.ts
Outdated
changes: ReadonlyArray<FetchChange>, | ||
): Promise<ReadonlyArray<FetchChange>> => { | ||
const isConflict = (change: FetchChange): boolean => change.pendingChange !== undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please revert this one so we can avoid conflict
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
packages/cli/test/mocks.ts
Outdated
action: 'remove', | ||
data: { before: 'asd' }, | ||
}, | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is already here we can use the detailedChange
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
packages/salto/src/api.ts
Outdated
@@ -56,8 +57,15 @@ export const deploy = async ( | |||
reportProgress, | |||
(action, element) => deployActionOnState(state, action, element) | |||
) | |||
|
|||
const changes = wu(getDetailedChanges(workspace.elements, await state.get())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably better not to state.get()
again here, instead I would suggest storing the state elements and leaving a comment saying they are mutated during deploy and we rely on this
* Added settings filter * End help message with EOL (#340) * removed extension readme badges (#345) * fixes command title (#339) * added event listener to file changes in extension (#338) * added error severity in extension (#344) * added error severity in extension * changed event filter out non-bp file changes (#341) * added wrapper to run aggr set function (fixes SALTO-264) (#342) * try #1 to fix Capriza failure: "TypeError: Cannot read property 'lookupFilter' of undefined" (#346) * SALTO-218: apply changes from state to bps post deploy (#343) * Replaced async-file package (#347) * upgraded inquirer.js to fix hang in Windows 10 * moved accesses to fs module to centralized file module * using tmp-promise instead of tmp * change default fetch behavior to auto approve incoming changes (#350) * Added settings filter * Hadar CR * Consistent list order (#348) List ordering for specific ObjectTypes and records (InstanceElements) * missing await in apply changes post deploy (#356) * added missing await in fetch (#353) * Consistent list order (#348) List ordering for specific ObjectTypes and records (InstanceElements) * missing await in apply changes post deploy (#356) * Added settings filter * Hadar CR * add debug logs (#355) * blacklisted static resources (#352) * shouldn't add default ObjectType annotations upon adapter.update (#357) * Hadar comments * rename elemId fieldType name to field_name since it collides with a Custom object that named Name and it causes undesired merge of the ObjectTypes (#354) * Fixed e2e * Fixed e2e * Added settings filter * Hadar CR * Hadar comments * Fixed e2e * Fixed e2e
No description provided.