Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/jrnl-org/jrnl into upstr…
Browse files Browse the repository at this point in the history
…eam_develop
  • Loading branch information
micahellison committed Nov 21, 2020
2 parents 95c4bc7 + 046ebc7 commit 3cfef5f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.JRNL_BOT_TOKEN }}

- name: Check branch for new commits
run: |
git fetch origin
git fetch --tags origin
BRANCH="${GITHUB_REF##*/}"
if [[ $(git rev-parse "origin/$BRANCH") != $GITHUB_SHA ]]; then
echo "BRANCH: $BRANCH"
Expand Down
10 changes: 2 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@

[Full Changelog](https://github.com/jrnl-org/jrnl/compare/v2.5...HEAD)

**Fixed bugs:**

- Writing to DayOne fails, creates files in `duplicateEntries` [\#493](https://github.com/jrnl-org/jrnl/issues/493)

**Build:**
**Implemented enhancements:**

- 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))
- Allow --edit flag partway through an entry [\#906](https://github.com/jrnl-org/jrnl/issues/906)

## [v2.5](https://pypi.org/project/jrnl/v2.5/) (2020-11-07)

Expand Down
30 changes: 27 additions & 3 deletions features/steps/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,21 @@ def matches_editor_arg(context, regex):
), 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 prompt_return(prompt=""):
if type(inputs) == str:
Expand Down Expand Up @@ -270,7 +285,9 @@ def run_with_input(context, command, inputs=""):
def _mock_editor(command):
context.editor_command = command
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()

if "password" in context:
Expand Down Expand Up @@ -348,6 +365,11 @@ def run(context, command, text=""):

def _mock_editor(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:
password = context.password
Expand All @@ -359,10 +381,12 @@ def _mock_editor(command):
# see: https://github.com/psf/black/issues/664
with \
patch("sys.argv", args), \
patch("getpass.getpass", side_effect=_mock_getpass(password)), \
patch("subprocess.call", side_effect=_mock_editor), \
patch("getpass.getpass", side_effect=_mock_getpass(password)) as mock_getpass, \
patch("subprocess.call", side_effect=_mock_editor) as mock_editor, \
patch("sys.stdin.read", side_effect=lambda: text) \
:
context.editor = mock_editor
context.getpass = mock_getpass
cli(args[1:])
context.exit_status = 0
# fmt: on
Expand Down
20 changes: 20 additions & 0 deletions features/write.feature
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ Feature: Writing new entries.
| dayone |
| 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
Given we use the config "<config_file>.yaml"
And we use the password "test" if prompted
Expand Down
11 changes: 9 additions & 2 deletions jrnl/jrnl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
write_mode
Expand All @@ -108,6 +112,8 @@ def write_mode(args, config, journal, **kwargs):
if args.text:
logging.debug("Write mode: cli text detected: %s", args.text)
raw = " ".join(args.text).strip()
if args.edit:
raw = _write_in_editor(config, raw)

elif not sys.stdin.isatty():
logging.debug("Write mode: receiving piped text")
Expand Down Expand Up @@ -157,10 +163,11 @@ def search_mode(args, journal, **kwargs):
_display_search_results(**kwargs)


def _write_in_editor(config):
def _write_in_editor(config, template=None):
if config["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)

else:
Expand Down

0 comments on commit 3cfef5f

Please sign in to comment.