Skip to content

Commit 9748386

Browse files
committed
Allow user to specify tags when updating journal entry
With `tags_action` parameter which specified whether new tags should be merged in with existing tags or replace them.
1 parent 855967b commit 9748386

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

bugout/app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .calls import ping
66
from .group import Group
77
from .humbug import Humbug
8-
from .journal import Journal, SearchOrder
8+
from .journal import Journal, SearchOrder, TagsAction
99
from .resource import Resource
1010
from .user import User
1111
from .settings import BUGOUT_BROOD_URL, BUGOUT_SPIRE_URL, REQUESTS_TIMEOUT
@@ -595,6 +595,8 @@ def update_entry_content(
595595
title: str,
596596
content: str,
597597
timeout: float = REQUESTS_TIMEOUT,
598+
tags: Optional[List[str]] = None,
599+
tags_action: TagsAction = TagsAction.merge,
598600
) -> data.BugoutJournalEntryContent:
599601
self.journal.timeout = timeout
600602
return self.journal.update_entry_content(
@@ -603,6 +605,8 @@ def update_entry_content(
603605
entry_id=entry_id,
604606
title=title,
605607
content=content,
608+
tags=tags,
609+
tags_action=tags_action,
606610
)
607611

608612
def delete_entry(

bugout/journal.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from enum import Enum
2-
from typing import Any, List, Optional, Union
2+
from typing import Any, Dict, List, Optional, Union
33
import uuid
44

55
from .calls import make_request
@@ -28,6 +28,21 @@ class SearchOrder(Enum):
2828
DESCENDING = "desc"
2929

3030

31+
class TagsAction(Enum):
32+
"""
33+
tags_action query parameter for PUT /{journal_id}/entries/{entry_id} requests.
34+
See Spire API implementation of that endpoint for more details:
35+
https://github.com/bugout-dev/spire/blob/cc748d45d0aa7e3350105810449ff4c14fa64ec9/spire/journal/api.py#L1249
36+
37+
Corresponds to EntryUpdateTagActions enum in Spire:
38+
https://github.com/bugout-dev/spire/blob/cc748d45d0aa7e3350105810449ff4c14fa64ec9/spire/journal/data.py#L32
39+
"""
40+
41+
ignore = "ignore"
42+
replace = "replace"
43+
merge = "merge"
44+
45+
3146
class Journal:
3247
"""
3348
Represent a journal from Bugout.
@@ -301,12 +316,18 @@ def update_entry_content(
301316
entry_id: Union[str, uuid.UUID],
302317
title: str,
303318
content: str,
319+
tags: Optional[List[str]] = None,
320+
tags_action: TagsAction = TagsAction.merge,
304321
) -> BugoutJournalEntryContent:
305322
entry_id_content_path = f"journals/{journal_id}/entries/{entry_id}/content"
323+
params: Dict[str, str] = {}
306324
json = {
307325
"title": title,
308326
"content": content,
309327
}
328+
if tags is not None:
329+
json["tags"] = tags
330+
params["tags_action"] = tags_action.value
310331
headers = {
311332
"Authorization": f"Bearer {token}",
312333
}
@@ -315,6 +336,7 @@ def update_entry_content(
315336
path=entry_id_content_path,
316337
headers=headers,
317338
json=json,
339+
params=params,
318340
)
319341
return BugoutJournalEntryContent(**result)
320342

0 commit comments

Comments
 (0)