Skip to content

Commit

Permalink
Move to using Doogat's JiraAdapter instead of buvis'
Browse files Browse the repository at this point in the history
  • Loading branch information
tbouska committed Nov 30, 2024
1 parent faea8cc commit 7381e28
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 26 deletions.
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ package-mode = false
[tool.poetry.dependencies]
python = "^3.12"
# buvis-pybase = "0.1.3"
buvis-pybase = {version = "0.1.5a7", source = "test-pypi"}
buvis-pybase = {version = "0.1.5a8", source = "test-pypi"}
# buvis-pybase = {path = "../buvis-pybase", develop = true}

[tool.poetry.group.dev.dependencies]
click = "8.1.7"
# doogat-core = "0.1.2"
doogat-core = {version = "0.1.3a29", source = "test-pypi"}
# doogat-core = {path = "../../../../doogat/doogat-core", develop = true}
doogat-core = {version = "0.1.3a31", source = "test-pypi"}
# doogat-core = {path = "../../doogat/doogat-core", develop = true}
# doogat-integrations = "0.1.0"
doogat-integrations = {version = "0.1.0a3", source = "test-pypi"}
# doogat-integrations = {path = "../../../../doogat/doogat-integrations", develop = true}
doogat-integrations = {version = "0.1.0a4", source = "test-pypi"}
# doogat-integrations = {path = "../../doogat/doogat-integrations", develop = true}
pre-commit = "4.0.1"
pyfiglet = "1.0.2"
ping3 = "4.0.8"
Expand Down
46 changes: 31 additions & 15 deletions src/bim/bim/commands/sync_note/sync_note.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import tzlocal

from pathlib import Path
from datetime import datetime
from buvis.pybase.adapters import (
console,
JiraAdapter,
)
from buvis.pybase.configuration import Configuration, ConfigurationKeyNotFoundError
from doogat.core import (
MarkdownZettelFormatter,
MarkdownZettelRepository,
ReadDoogatUseCase,
)
from doogat.integrations import ProjectZettelJiraIssueDTOAssembler
from doogat.core.domain.entities import ProjectZettel
from doogat.integrations.jira import (
JiraAdapter,
)

DEFAULT_JIRA_IGNORE_US_LABEL = "do-not-track"


class CommandSyncNote:
Expand All @@ -25,7 +31,8 @@ def __init__(self: "CommandSyncNote", cfg: Configuration) -> None:

match cfg.get_configuration_item("target_system"):
case "jira":
self._target = JiraAdapter(cfg.get_configuration_item("jira_adapter"))
jira_cfg = cfg.copy("jira_adapter")
self._target = JiraAdapter(jira_cfg)
case _:
raise NotImplementedError
self._cfg = cfg
Expand All @@ -36,25 +43,34 @@ def execute(self: "CommandSyncNote") -> None:
formatter = MarkdownZettelFormatter()
note = reader.execute(str(self.path_note))

if note.type != "project":
if isinstance(note, ProjectZettel):
project: ProjectZettel = note
else:
console.failure(f"{self.path_note} is not a project")
return None
return

cfg_jira_adapter = self._cfg.get_configuration_item("jira_adapter")

if not hasattr(note, "us") or not note.us:
assembler = ProjectZettelJiraIssueDTOAssembler(
defaults=self._cfg.get_configuration_item("jira_adapter")["defaults"]
if isinstance(cfg_jira_adapter, dict):
cfg_dict_jira_adapter = cfg_jira_adapter.copy()
ignore_flag = cfg_dict_jira_adapter.get(
"ignore",
DEFAULT_JIRA_IGNORE_US_LABEL,
)
dto = assembler.to_dto(note)
new_issue = self._target.create(dto)
else:
ignore_flag = DEFAULT_JIRA_IGNORE_US_LABEL

if not hasattr(project, "us") or not project.us:
new_issue = self._target.create_from_project(project)
md_style_link = f"[{new_issue.id}]({new_issue.link})"
note._data.reference["us"] = md_style_link
note.add_log_entry(
f"- [i] {datetime.now().strftime("%Y-%m-%d %H:%M")} - Jira Issue created: {md_style_link}"
project.us = md_style_link
project.add_log_entry(
f"- [i] {datetime.now(tzlocal.get_localzone()).strftime("%Y-%m-%d %H:%M")} - Jira Issue created: {md_style_link}",
)
formatted_content = formatter.format(note.get_data())
formatted_content = formatter.format(project.get_data())
self.path_note.write_bytes(formatted_content.encode("utf-8"))
console.success(f"Jira Issue {new_issue.id} created from {self.path_note}")
elif note.us == self._defaults["ignore"]:
elif note.us == ignore_flag:
console.warning("Project is set to ignore Jira")
else:
console.success(f"Already linked to {note.us}")
12 changes: 6 additions & 6 deletions src/bim/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ readme = "README.md"
python = "^3.12"
click = "8.1.7"
# buvis-pybase = "0.1.4"
buvis-pybase = {version = "0.1.5a7", source = "test-pypi"} # doogat-core from test-pypi won't install this
# buvis-pybase = {path = "../../../buvis-pybase", develop = true}
# buvis-pybase = {version = "0.1.5a7", source = "test-pypi"} # doogat-core from test-pypi won't install this
buvis-pybase = {path = "../../../buvis-pybase", develop = true}
# doogat-core = "0.1.2"
doogat-core = {version = "0.1.3a29", source = "test-pypi"}
# doogat-core = {path = "../../../../doogat/doogat-core", develop = true}
# doogat-core = {version = "0.1.3a29", source = "test-pypi"}
doogat-core = {path = "../../../../doogat/doogat-core", develop = true}
# doogat-integrations = "0.1.0"
doogat-integrations = {version = "0.1.0a3", source = "test-pypi"}
# doogat-integrations = {path = "../../../../doogat/doogat-integrations", develop = true}
# doogat-integrations = {version = "0.1.0a3", source = "test-pypi"}
doogat-integrations = {path = "../../../../doogat/doogat-integrations", develop = true}

[[tool.poetry.source]]
name = "test-pypi"
Expand Down

0 comments on commit 7381e28

Please sign in to comment.