-
Notifications
You must be signed in to change notification settings - Fork 16
feat: new deploy diff #1352
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
Open
doc-han
wants to merge
12
commits into
main
Choose a base branch
from
diff-stuff
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: new deploy diff #1352
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a7d4fc9
feat: diff init
doc-han 2a1b2ea
feat: use changed when body is fully changed
doc-han b5a2c7c
chore: fix mutation problem
doc-han 2b94782
Merge branch 'main' into diff-stuff
doc-han 614e998
Merge branch 'main' into diff-stuff
doc-han 2a589d6
chore: update changelog
doc-han 01632f4
Merge branch 'main' into diff-stuff
doc-han 83b47c5
feat: resolve changes
doc-han 7f8d1d8
fix: unknown edge references
doc-han 3255ef9
feat: edge changes
doc-han 19837bf
chore: format
doc-han e7e399f
tests: resolve failing tests
doc-han File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@openfn/project': minor | ||
| '@openfn/cli': minor | ||
| --- | ||
|
|
||
| Adds new form of json diffing for cli |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import c from 'chalk'; | ||
| import Project, { generateStepDiff, generateEdgeDiff } from '@openfn/project'; | ||
| import type { StepChange, EdgeChange } from '@openfn/project'; | ||
| import type { Logger } from '../util/logger'; | ||
|
|
||
| export { generateStepDiff, generateEdgeDiff }; | ||
| export type { StepChange, EdgeChange }; | ||
|
|
||
| const printEdgeDiff = (edges: EdgeChange[], logger: Logger) => { | ||
| for (const edge of edges) { | ||
| if (edge.type === 'added') { | ||
| logger.always(c.green(` ${edge.id}: added`)); | ||
| } else if (edge.type === 'removed') { | ||
| logger.always(c.red(` ${edge.id}: removed`)); | ||
| } else if (edge.type === 'changed' && edge.changes) { | ||
| logger.always(c.yellow(` ${edge.id}:`)); | ||
| const { condition, label, enabled } = edge.changes; | ||
| if (condition) | ||
| logger.always( | ||
| c.yellow( | ||
| ` - condition: ${condition.from ?? 'none'} -> ${ | ||
| condition.to ?? 'none' | ||
| }` | ||
| ) | ||
| ); | ||
| if (label) | ||
| logger.always( | ||
| c.yellow( | ||
| ` - label: "${label.from ?? ''}" -> "${label.to ?? ''}"` | ||
| ) | ||
| ); | ||
| if (enabled) | ||
| logger.always( | ||
| c.yellow(` - enabled: ${enabled.from} -> ${enabled.to}`) | ||
| ); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| const printStepDiff = (steps: StepChange[], logger: Logger) => { | ||
| for (const step of steps) { | ||
| if (step.type === 'added') { | ||
| logger.always(c.green(` ${step.name}: added`)); | ||
| } else if (step.type === 'removed') { | ||
| logger.always(c.red(` ${step.name}: removed`)); | ||
| } else if (step.type === 'changed' && step.changes) { | ||
| logger.always(c.yellow(` ${step.name}:`)); | ||
| const { name, adaptor, body } = step.changes; | ||
| if (name) | ||
| logger.always(c.yellow(` - name: "${name.from}" -> "${name.to}"`)); | ||
| if (adaptor) | ||
| logger.always( | ||
| c.yellow(` - adaptor: ${adaptor.from} -> ${adaptor.to}`) | ||
| ); | ||
| if (body) logger.always(c.yellow(` - body: ${body}`)); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| export const printRichDiff = ( | ||
| local: Project, | ||
| remote: Project, | ||
| locallyChangedWorkflows: string[], | ||
| logger: Logger | ||
| ) => { | ||
| const diffs = remote.diff(local, locallyChangedWorkflows); | ||
| if (diffs.length === 0) { | ||
| logger.info('No workflow changes detected'); | ||
| return diffs; | ||
| } | ||
|
|
||
| const removed = diffs.filter((d) => d.type === 'removed'); | ||
| const changed = diffs.filter((d) => d.type === 'changed'); | ||
| const added = diffs.filter((d) => d.type === 'added'); | ||
|
|
||
| logger.always('This will make the following changes to the remote project:'); | ||
|
|
||
| if (removed.length > 0) { | ||
| logger.break(); | ||
| for (const diff of removed) { | ||
| const wf = remote.getWorkflow(diff.id); | ||
| const label = wf?.name || diff.id; | ||
| logger.always(c.red(`${label}: deleted`)); | ||
| } | ||
| } | ||
|
|
||
| if (changed.length > 0) { | ||
| logger.break(); | ||
| for (const diff of changed) { | ||
| const localWf = local.getWorkflow(diff.id); | ||
| const remoteWf = remote.getWorkflow(diff.id); | ||
| const label = localWf?.name || diff.id; | ||
| logger.always(c.yellow(`${label}: changed`)); | ||
| printStepDiff(generateStepDiff(localWf, remoteWf), logger); | ||
| printEdgeDiff(generateEdgeDiff(localWf, remoteWf), logger); | ||
| } | ||
| } | ||
|
|
||
| if (added.length > 0) { | ||
| logger.break(); | ||
| for (const diff of added) { | ||
| const wf = local.getWorkflow(diff.id); | ||
| const label = wf?.name || diff.id; | ||
| logger.always(c.green(`${label}: added`)); | ||
| } | ||
| } | ||
|
|
||
| logger.break(); | ||
| return diffs; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.