Merge branch 'develop' of https://github.com/jrnl-org/jrnl into upstream_develop

This commit is contained in:
Micah Jerome Ellison 2020-11-21 15:23:22 -08:00
commit 3cfef5f929
5 changed files with 61 additions and 13 deletions

View file

@ -10,10 +10,13 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
with:
token: ${{ secrets.JRNL_BOT_TOKEN }}
- name: Check branch for new commits - name: Check branch for new commits
run: | run: |
git fetch origin git fetch origin
git fetch --tags origin
BRANCH="${GITHUB_REF##*/}" BRANCH="${GITHUB_REF##*/}"
if [[ $(git rev-parse "origin/$BRANCH") != $GITHUB_SHA ]]; then if [[ $(git rev-parse "origin/$BRANCH") != $GITHUB_SHA ]]; then
echo "BRANCH: $BRANCH" echo "BRANCH: $BRANCH"

View file

@ -4,15 +4,9 @@
[Full Changelog](https://github.com/jrnl-org/jrnl/compare/v2.5...HEAD) [Full Changelog](https://github.com/jrnl-org/jrnl/compare/v2.5...HEAD)
**Fixed bugs:** **Implemented enhancements:**
- Writing to DayOne fails, creates files in `duplicateEntries` [\#493](https://github.com/jrnl-org/jrnl/issues/493) - Allow --edit flag partway through an entry [\#906](https://github.com/jrnl-org/jrnl/issues/906)
**Build:**
- Add initial config for Github Actions [\#1078](https://github.com/jrnl-org/jrnl/pull/1078) ([wren](https://github.com/wren))
- Update dependencies - pyxdg, pytest, black [\#1076](https://github.com/jrnl-org/jrnl/pull/1076) ([micahellison](https://github.com/micahellison))
- Add PyPI classifiers [\#1074](https://github.com/jrnl-org/jrnl/pull/1074) ([micahellison](https://github.com/micahellison))
## [v2.5](https://pypi.org/project/jrnl/v2.5/) (2020-11-07) ## [v2.5](https://pypi.org/project/jrnl/v2.5/) (2020-11-07)

View file

@ -230,6 +230,21 @@ def matches_editor_arg(context, regex):
), f"\nRegex didn't match exactly 1 time:\n{regex}\n{str(args)}" ), f"\nRegex didn't match exactly 1 time:\n{regex}\n{str(args)}"
@then("the editor file content should {method}")
@then("the editor file content should {method} empty")
@then('the editor file content should {method} "{text}"')
def contains_editor_file(context, method, text=""):
text = text or context.text or ""
content = context.editor_file.get("content")
format = f'\n"""\n{content}\n"""\n'
if method == "be":
assert content == text, format
elif method == "contain":
assert text in content, format
else:
assert False, f"Method '{method}' not supported"
def _mock_getpass(inputs): def _mock_getpass(inputs):
def prompt_return(prompt=""): def prompt_return(prompt=""):
if type(inputs) == str: if type(inputs) == str:
@ -270,7 +285,9 @@ def run_with_input(context, command, inputs=""):
def _mock_editor(command): def _mock_editor(command):
context.editor_command = command context.editor_command = command
tmpfile = command[-1] tmpfile = command[-1]
context.editor_file = tmpfile with open(tmpfile, "r") as editor_file:
file_content = editor_file.read()
context.editor_file = {"name": tmpfile, "content": file_content}
Path(tmpfile).touch() Path(tmpfile).touch()
if "password" in context: if "password" in context:
@ -348,6 +365,11 @@ def run(context, command, text=""):
def _mock_editor(command): def _mock_editor(command):
context.editor_command = command context.editor_command = command
tmpfile = command[-1]
with open(tmpfile, "r") as editor_file:
file_content = editor_file.read()
context.editor_file = {"name": tmpfile, "content": file_content}
Path(tmpfile).touch()
if "password" in context: if "password" in context:
password = context.password password = context.password
@ -359,10 +381,12 @@ def run(context, command, text=""):
# see: https://github.com/psf/black/issues/664 # see: https://github.com/psf/black/issues/664
with \ with \
patch("sys.argv", args), \ patch("sys.argv", args), \
patch("getpass.getpass", side_effect=_mock_getpass(password)), \ patch("getpass.getpass", side_effect=_mock_getpass(password)) as mock_getpass, \
patch("subprocess.call", side_effect=_mock_editor), \ patch("subprocess.call", side_effect=_mock_editor) as mock_editor, \
patch("sys.stdin.read", side_effect=lambda: text) \ patch("sys.stdin.read", side_effect=lambda: text) \
: :
context.editor = mock_editor
context.getpass = mock_getpass
cli(args[1:]) cli(args[1:])
context.exit_status = 0 context.exit_status = 0
# fmt: on # fmt: on

View file

@ -43,6 +43,26 @@ Feature: Writing new entries.
| dayone | | dayone |
| encrypted | | encrypted |
Scenario Outline: Writing a partial entry from command line with edit flag should go to the editor
Given we use the config "<config_file>.yaml"
And we use the password "test" if prompted
When we run "jrnl this is a partial --edit"
Then we should see the message "Entry added"
Then the editor should have been called
And the editor file content should be
"""
this is a partial
"""
When we run "jrnl -n 1"
Then the output should contain "this is a partial"
Examples: configs
| config_file |
| basic_onefile |
| basic_encrypted |
| basic_dayone |
| basic_folder |
Scenario Outline: Writing an empty entry from the editor should yield "Nothing saved to file" message Scenario Outline: Writing an empty entry from the editor should yield "Nothing saved to file" message
Given we use the config "<config_file>.yaml" Given we use the config "<config_file>.yaml"
And we use the password "test" if prompted And we use the password "test" if prompted

View file

@ -83,6 +83,10 @@ def _is_write_mode(args, config, **kwargs):
) )
) )
# Might be writing and want to move to editor part of the way through
if args.edit and args.text:
write_mode = True
# If the text is entirely tags, then we are also searching (not writing) # If the text is entirely tags, then we are also searching (not writing)
if ( if (
write_mode write_mode
@ -108,6 +112,8 @@ def write_mode(args, config, journal, **kwargs):
if args.text: if args.text:
logging.debug("Write mode: cli text detected: %s", args.text) logging.debug("Write mode: cli text detected: %s", args.text)
raw = " ".join(args.text).strip() raw = " ".join(args.text).strip()
if args.edit:
raw = _write_in_editor(config, raw)
elif not sys.stdin.isatty(): elif not sys.stdin.isatty():
logging.debug("Write mode: receiving piped text") logging.debug("Write mode: receiving piped text")
@ -157,10 +163,11 @@ def search_mode(args, journal, **kwargs):
_display_search_results(**kwargs) _display_search_results(**kwargs)
def _write_in_editor(config): def _write_in_editor(config, template=None):
if config["editor"]: if config["editor"]:
logging.debug("Write mode: opening editor") logging.debug("Write mode: opening editor")
template = _get_editor_template(config) if not template:
template = _get_editor_template(config)
raw = get_text_from_editor(config, template) raw = get_text_from_editor(config, template)
else: else: