Skip to content
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

190 Add package change confirmation #293

Merged

Conversation

lights7412
Copy link
Contributor

@lights7412 lights7412 commented Mar 28, 2023

Closes #190

Checks if there are changes between the package.yaml and the api when publishing. If there are changes it will display the associated changes and ask if you want to continue.

The confirmation can be skipped by adding a -y to the publish command <functionary package publish ~/functionary/examples/demo -y>.

Three Unit tests were added in the cli/tests/tests_utils.py. Further testing can be done by adjusting the package.yaml (ie adding, deleting, changing functions)

@lights7412 lights7412 force-pushed the 190-add-package-change-confirmation branch 2 times, most recently from 5daaab6 to ee06943 Compare March 30, 2023 12:11
@click.pass_context
def publish(ctx, path, keep):
def publish(ctx, path, keep, y):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can give y a name in the @click.option declaration above so that it has a more meaningful variable name here. See the documentation on naming options. Let's name it skip_confirm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

cli/functionary/package.py Outdated Show resolved Hide resolved
if not y and changes:
confirm = input("Continue [y|N]? ").lower()
if confirm not in ("y", "yes"):
exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to use sys.exit() here. We might already make this mistake elsewhere, but exit() is really for the shell and not meant to be used in program code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

cli/functionary/utils.py Outdated Show resolved Hide resolved
cli/functionary/utils.py Outdated Show resolved Hide resolved
cli/functionary/utils.py Outdated Show resolved Hide resolved
cli/functionary/utils.py Show resolved Hide resolved
cli/functionary/utils.py Outdated Show resolved Hide resolved
cli/functionary/utils.py Outdated Show resolved Hide resolved
cli/tests/test_utils.py Outdated Show resolved Hide resolved
@lights7412 lights7412 force-pushed the 190-add-package-change-confirmation branch 5 times, most recently from f9b07c7 to b669097 Compare April 19, 2023 14:56
Copy link
Contributor

@scott-taubman scott-taubman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks much improved and my remaining comments are pretty minor.

One issue that I failed to test for before is that the check raises an exception when publishing a new package because it assumes it's going to find a package in the API call. You'll need to handle the case where there's no existing package to compare the one being published to.

Sorts functions by their package id
"""
functions_lookup = {}
package_id = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This initialization doesn't look necessary based on what happens after it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

packagefunctions = _get_package_functions(path)["functions"]
apifunctions = _get_functions_for_package(_get_package_functions(path)["name"])

# Nothing in the api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this comment. The if not apifunctions is kind of self-explanatory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

if updatedfunctions:
_format_updated_functions(updatedfunctions, "Updated Functions")

return newfunctions or removedfunctions or updatedfunctions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a little bit of ambiguity with what you are returning here. newfunctions or removedfunctions or updatedfunctions will return the first of those values that isn't empty. You then check that value for truthiness later on. What would be more explicit would be to return a boolean here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@lights7412 lights7412 force-pushed the 190-add-package-change-confirmation branch 3 times, most recently from 5fa524b to 7137391 Compare April 20, 2023 18:11
@lights7412 lights7412 force-pushed the 190-add-package-change-confirmation branch from 7137391 to 6c3e635 Compare April 20, 2023 18:13
@scott-taubman scott-taubman merged commit b9fb25b into beer-garden:main Apr 20, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add package change confirmation to publish CLI command
2 participants