-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat(#373): merge-contacts action #647
Open
kennsippell
wants to merge
21
commits into
main
Choose a base branch
from
373-merge-contacts-options
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
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d16df6d
Testing this common library going to get weird
kennsippell 3e1827e
Move-Contacts tests passing again
kennsippell d914e64
First test passing for merge
kennsippell 090895c
Negative cases
kennsippell 3e6168c
Fix move-contacts tests again
kennsippell 2449dd4
Some renaming
kennsippell b5f8c3b
Refactor to use options
kennsippell 1273fb6
Move folder structure
kennsippell 25ad230
Lineage Constraints
kennsippell 5ad9d85
Rename to Hierarchy Operations
kennsippell 7ea3393
replaceRelevantLineage
kennsippell 78f2c01
Refacatoring for lineage-manipulation
kennsippell d677b48
Tests for fn folder
kennsippell 2442fcc
Pass eslint
kennsippell a0a0c84
Backend interface change
kennsippell f73f9c6
Fix failing test in mock-hierarchies
kennsippell 8e35f2d
SonarCube
kennsippell 17c4c04
SonarQube - Is his really better code?
kennsippell 7af035c
SonarQube - Fix?
kennsippell 687a6a2
SonarQube
kennsippell 49c6d51
Oops
kennsippell 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 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ upload-docs.*.log.json | |
/.vscode/ | ||
/.idea/ | ||
/.settings/ | ||
/json_docs/ | ||
*.swp | ||
coverage | ||
.nyc_output | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,68 @@ | ||
const minimist = require('minimist'); | ||
const path = require('path'); | ||
|
||
const environment = require('../lib/environment'); | ||
const pouch = require('../lib/db'); | ||
const { info } = require('../lib/log'); | ||
|
||
const HierarchyOperations = require('../lib/hierarchy-operations'); | ||
|
||
module.exports = { | ||
requiresInstance: true, | ||
execute: () => { | ||
const args = parseExtraArgs(environment.pathToProject, environment.extraArgs); | ||
const db = pouch(); | ||
const options = { | ||
docDirectoryPath: args.docDirectoryPath, | ||
force: args.force, | ||
}; | ||
return HierarchyOperations(options, db).merge(args.sourceIds, args.destinationId); | ||
} | ||
}; | ||
|
||
// Parses extraArgs and asserts if required parameters are not present | ||
const parseExtraArgs = (projectDir, extraArgs = []) => { | ||
const args = minimist(extraArgs, { boolean: true }); | ||
|
||
const sourceIds = (args.remove || '') | ||
.split(',') | ||
.filter(Boolean); | ||
|
||
if (!args.keep) { | ||
usage(); | ||
throw Error(`Action "merge-contacts" is missing required contact ID ${bold('--keep')}. Other contacts will be merged into this contact.`); | ||
} | ||
|
||
if (sourceIds.length === 0) { | ||
usage(); | ||
throw Error(`Action "merge-contacts" is missing required contact ID(s) ${bold('--remove')}. These contacts will be merged into the contact specified by ${bold('--keep')}`); | ||
} | ||
|
||
return { | ||
destinationId: args.keep, | ||
sourceIds, | ||
docDirectoryPath: path.resolve(projectDir, args.docDirectoryPath || 'json_docs'), | ||
force: !!args.force, | ||
}; | ||
}; | ||
|
||
const bold = text => `\x1b[1m${text}\x1b[0m`; | ||
const usage = () => { | ||
info(` | ||
${bold('cht-conf\'s merge-contacts action')} | ||
When combined with 'upload-docs' this action merges multiple contacts and all their associated data into one. | ||
|
||
${bold('USAGE')} | ||
cht --local merge-contacts -- --keep=<keep_id> --remove=<remove_id1>,<remove_id2> | ||
|
||
${bold('OPTIONS')} | ||
--keep=<keep_id> | ||
Specifies the ID of the contact that should have all other contact data merged into it. | ||
|
||
--remove=<remove_id1>,<remove_id2> | ||
A comma delimited list of IDs of contacts which will be deleted and all of their data will be merged into the keep contact. | ||
|
||
--docDirectoryPath=<path to stage docs> | ||
Specifies the folder used to store the documents representing the changes in hierarchy. | ||
`); | ||
}; |
This file contains 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.
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.
Struggling with the interface here. I've gone through:
Welcome suggestions that seem intuitive.