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

Support minor edits #50

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pip install md2cf
```text
usage: md2cf [-h] [-o HOST] [-u USERNAME] [-p PASSWORD] [--token TOKEN]
[--insecure] [-s SPACE] [-a PARENT_TITLE | -A PARENT_ID]
[-t TITLE] [-m MESSAGE] [-i PAGE_ID] [--prefix PREFIX]
[--strip-top-header] [--remove-text-newlines]
[-t TITLE] [-m MESSAGE] [--minor-edit] [-i PAGE_ID]
[--prefix PREFIX] [--strip-top-header] [--remove-text-newlines]
[--replace-all-labels] [--preface-markdown [PREFACE_MARKDOWN] |
--preface-file PREFACE_FILE]
[--postface-markdown [POSTFACE_MARKDOWN] | --postface-file
Expand Down Expand Up @@ -159,6 +159,8 @@ Uploading a page with the same title twice will update the existing one.

If you want to update a page by page ID, use the `--page-id` option. This allows you to change the page's title, or to update a page with a title that is annoying to use as a parameter.

With the `--minor-edit` option you can prevent notifications being sent to watcher of the page. This corresponds to the "Notify watchers" checkbox when editing pages manually.

### Avoiding uploading content that hasn't changed

If you want to avoid redundant uploads (and the corresponding update emails) when your content hasn't changed, you can add the `--only-changed` option. Note that this will store a hash of the page/attachment contents at the end of the version update message.
Expand Down
6 changes: 6 additions & 0 deletions md2cf/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def get_parser():
help="a title for the page. Determined from the document if missing",
)
page_group.add_argument("-m", "--message", help="update message for the change")
page_group.add_argument(
"--minor-edit", action="store_true", help="do not notify watchers of change"
)
page_group.add_argument("-i", "--page-id", help="ID of the page to be updated")
page_group.add_argument(
"--prefix",
Expand Down Expand Up @@ -227,6 +230,7 @@ def upsert_page(
page: md2cf.document.Page,
only_changed: bool = False,
replace_all_labels: bool = False,
minor_edit: bool = False,
):
existing_page = confluence.get_page(
title=page.title,
Expand Down Expand Up @@ -303,6 +307,7 @@ def upsert_page(
parent_id=page.parent_id,
update_message=page_message,
labels=page.labels if replace_all_labels else None,
minor_edit=minor_edit,
)

if not replace_all_labels and page.labels:
Expand Down Expand Up @@ -477,6 +482,7 @@ def main():
page=page,
only_changed=args.only_changed,
replace_all_labels=args.replace_all_labels,
minor_edit=args.minor_edit,
)
except HTTPError as e:
sys.stderr.write("{} - {}\n".format(str(e), e.response.content))
Expand Down
11 changes: 10 additions & 1 deletion md2cf/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,19 @@ def create_page(

return self.api.content.post(json=page_structure)

def update_page(self, page, body, parent_id=None, update_message=None, labels=None):
def update_page(
self,
page,
body,
parent_id=None,
update_message=None,
labels=None,
minor_edit=False,
):
update_structure = {
"version": {
"number": page.version.number + 1,
"minorEdit": minor_edit,
},
"title": page.title,
"type": "page",
Expand Down
10 changes: 6 additions & 4 deletions tests/unit/test_confluence.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,7 @@ def test_update_page(confluence):
test_new_body = "<p>This is my new body</p>"

update_structure = {
"version": {
"number": test_page_version + 1,
},
"version": {"number": test_page_version + 1, "minorEdit": False},
"title": test_page_title,
"type": "page",
"body": {"storage": {"value": test_new_body, "representation": "storage"}},
Expand Down Expand Up @@ -292,7 +290,11 @@ def test_update_page_with_message(confluence):
test_new_body = "<p>This is my new body</p>"

update_structure = {
"version": {"number": test_page_version + 1, "message": test_page_message},
"version": {
"number": test_page_version + 1,
"message": test_page_message,
"minorEdit": False,
},
"title": test_page_title,
"type": "page",
"body": {"storage": {"value": test_new_body, "representation": "storage"}},
Expand Down