-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
Add shell hooks #190
base: develop
Are you sure you want to change the base?
Add shell hooks #190
Conversation
Thanks for the PR, I like the concept. I'm tied up on other projects at the minute but will take a look as soon as I can. |
@dullage thanks! Any updates? |
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.
lgtm - I've not tested this out but when I first saw this project this first thing I wondered was would this fit into my existing git backed notes directory.
A later change may need to deal with error reporting to the UI, so the user knows something happened. For example with git, if a conflict has taken place and need manual merging.
|
||
Requirements: | ||
|
||
- python3, node, npm, pipenv |
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.
👍 thanks for doc'ing this. I was thinking about experimenting with this so this will help!
@@ -3,6 +3,7 @@ | |||
import re | |||
import shutil | |||
import time | |||
import subprocess |
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.
Pedantic suggestion; recommend moving this to the line above to have pep-8 sorting. I know the existing code isn't strictly adhering to this. https://pypi.org/project/isort/ can help with this.
@@ -42,6 +42,7 @@ Equally, the only thing flatnotes caches is the search index and that's incremen | |||
* Light/dark themes. | |||
* Multiple authentication options (none, read-only, username/password, 2FA). | |||
* Restful API. | |||
* Hook on create/update/delete. |
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.
Recommend a new section to provide a demo like you did in the PR.
Alternative suggestion for git, sample. 100% Untested :-) I used this technique in some of my (shell) scripts I removed the git add -A
to also handle deletes and possible renames (rename detection can be a little hit and miss)
FLATNOTES_HOOK_CREATE="git add -u :/ ; git add . && git commit -m 'note %s' && git push"
FLATNOTES_HOOK_UPDATE="$FLATNOTES_HOOK_CREATE"
FLATNOTES_HOOK_DELETE="$FLATNOTES_HOOK_CREATE"
|
||
1. Install deps: | ||
|
||
pipenv install |
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.
Possibly dumb question; Should this include --ignore-pipfile
?
Line 50 in 5b5369b
RUN pipenv install --deploy --ignore-pipfile --system && \ |
From https://pipenv.pypa.io/en/latest/commands.html#install
--ignore-pipfile — Install from the Pipfile.lock and completely ignore Pipfile information.
Sorry for the late reply. I have a few concerns with the current approach but hopefully a potential solution for them.
To solve these, my suggestion is to look into the [Background Tasks)(https://fastapi.tiangolo.com/tutorial/background-tasks/) functionality of FastAPI. You may be able to use this to perform the shell hook after the response has been returned to the client. Additionally, I think it would also be prudent to wrap the |
I completely understand and share your concerns. I apologize for not detailing these points in the PR description earlier. Given the specific use-case example, I couldn't identify a better alternative 🤷♂️ |
Adds shell hooks via environment variables
FLATNOTES_HOOK_<name>
.FLATNOTES_HOOK_CREATE
- executes once note createdFLATNOTES_HOOK_UPDATE
- executes once note updatedFLATNOTES_HOOK_DELETE
- executes once note removedIn each option,
%s
will be replaced by path to note. Work dir is set to notes dir.It opens opportunity to enable syncs. For example: