From d68b9e1ca1fff4a5050f3f01d9f30145db7fb49a Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sat, 21 Nov 2020 15:11:58 -0800 Subject: [PATCH 1/5] More changelog fixes (#1092) * add bot token since gh actions doesn't allow pushing to protected branch * add a max for issues, since we keep getting rate limited * add jrnl bot username to commit step * change token for git repo --- .github/workflows/changelog.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/changelog.yaml b/.github/workflows/changelog.yaml index 2a53f291..8bc90605 100644 --- a/.github/workflows/changelog.yaml +++ b/.github/workflows/changelog.yaml @@ -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" @@ -56,6 +59,7 @@ jobs: excludeLabels: stale,wontfix excludeTagsRegex: '(alpha|beta|rc)' sinceTag: ${{ env.gittag }} + maxIssues: 150 releaseUrl: https://pypi.org/project/jrnl/%s/ verbose: false From 336936651fad1d61c3a3f464f14ca9b4522ff1bd Mon Sep 17 00:00:00 2001 From: Jrnl Bot Date: Sat, 21 Nov 2020 23:19:54 +0000 Subject: [PATCH 3/5] Update changelog --- CHANGELOG.md | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a082a1c9..cc4aa6f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,19 +1,5 @@ # Changelog -## [Unreleased](https://github.com/jrnl-org/jrnl/) - -[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:** - -- 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) [Full Changelog](https://github.com/jrnl-org/jrnl/compare/v2.4.5...v2.5) From cfdd05358a54f480c4e439b7eb16372f5b4ed186 Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sat, 21 Nov 2020 15:20:21 -0800 Subject: [PATCH 4/5] Add ability to put --edit partly through a cli entry to move it to the editor (#1091) also add some functionality to test suite to see what the editor file contents were and make assertions about it --- features/steps/core.py | 30 +++++++++++++++++++++++++++--- features/write.feature | 20 ++++++++++++++++++++ jrnl/jrnl.py | 11 +++++++++-- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/features/steps/core.py b/features/steps/core.py index 8b49cbb2..58c0a71d 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -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: @@ -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: @@ -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 @@ -359,10 +381,12 @@ def run(context, command, text=""): # 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 diff --git a/features/write.feature b/features/write.feature index 2b19d126..efa26201 100644 --- a/features/write.feature +++ b/features/write.feature @@ -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 ".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 ".yaml" And we use the password "test" if prompted diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index 01f649fc..ccbca33e 100644 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -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 @@ -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") @@ -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: From 046ebc75148593608515d39dfeffb25b61e2f83e Mon Sep 17 00:00:00 2001 From: Jrnl Bot Date: Sat, 21 Nov 2020 23:21:21 +0000 Subject: [PATCH 5/5] Update changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc4aa6f6..77602897 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [Unreleased](https://github.com/jrnl-org/jrnl/) + +[Full Changelog](https://github.com/jrnl-org/jrnl/compare/v2.5...HEAD) + +**Implemented enhancements:** + +- 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) [Full Changelog](https://github.com/jrnl-org/jrnl/compare/v2.4.5...v2.5)