Skip to content

Commit 9fdef35

Browse files
authored
Merge pull request #36 from bugout-dev/fix-update-entry-with-tag-action
Adds support for updating tags in the same HTTP request as an entry update
2 parents 855967b + 52089ec commit 9fdef35

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

bugout/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
__email__ = "engineering@bugout.dev"
99
__license__ = "MIT"
10-
__version__ = "0.1.18"
10+
__version__ = "0.1.19"
1111

1212
__all__ = (
1313
"__author__",

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: 24 additions & 2 deletions
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"
306-
json = {
323+
params: Dict[str, str] = {}
324+
json: Dict[str, Any] = {
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)