Skip to content

Commit 7a4d14f

Browse files
author
Tomáš Bouška
committed
Start creating sync to Jira
1 parent b8fcad5 commit 7a4d14f

File tree

7 files changed

+111
-11
lines changed

7 files changed

+111
-11
lines changed

.python-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12.1

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ It used to be done automatically by direnv, but in some cases I needed to work w
7777

7878
The scripts are using `buvis-pybase` and `doogat-core` which I'm also developing. Unfortunately, there is currently no easy way to use editable and non-editable packages in same `pyproject.toml` (see: https://github.com/python-poetry/poetry/issues/8219). So I need to modify `pyproject.toml`.
7979

80-
1. Uncomment `# buvis-pybase = {path = "../buvis-pybase", develop = true}` in `pyproject.toml`
80+
1. Switch to local files:
81+
- macOS: Uncomment `# buvis-pybase = {path = "../buvis-pybase", develop = true}` or `# doogat-core = {path = "../../doogat/doogat-core", develop = true}` in `pyproject.toml`
82+
- Windows (there is an issue in Poetry in Windows causing it to be unable to resolve pth files):
83+
- in scripts root: `pip install -e ../buvis-pybase/` or `pip install -e ..\..\doogat\doogat-core\`
84+
- in script's root (like `src/bim` for example): `pip install -e ../../../buvis-pybase/` or `pip install -e ..\..\..\..\doogat\doogat-core\`
8185
2. Update dependencies: `poetry update`
8286
3. Do the work in both projects
8387
4. When done, you push to `buvis-pybase` project first

pyproject.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ package-mode = false
99
[tool.poetry.dependencies]
1010
python = "^3.12"
1111
# buvis-pybase = "0.1.3"
12-
buvis-pybase = {version = "0.1.5a5", source = "test-pypi"}
13-
# buvis-pybase = {path = "../buvis-pybase", develop = true}
12+
# buvis-pybase = {version = "0.1.5a5", source = "test-pypi"}
13+
buvis-pybase = {path = "../buvis-pybase", develop = true}
1414

1515
[tool.poetry.group.dev.dependencies]
1616
click = "8.1.7"
1717
# doogat-core = "0.1.2"
18-
doogat-core = {version = "0.1.3a26", source = "test-pypi"}
19-
# doogat-core = {path = "../../doogat/doogat-core", develop = true}
18+
# doogat-core = {version = "0.1.3a26", source = "test-pypi"}
19+
doogat-core = {path = "../../doogat/doogat-core", develop = true}
2020
pre-commit = "4.0.1"
2121
pyfiglet = "1.0.2"
2222
ping3 = "4.0.8"

src/bim/bim/cli.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
from buvis.pybase.adapters import console
77
from buvis.pybase.configuration import Configuration
88

9-
from bim.commands import CommandFormatNote, CommandImportNote, CommandParseTags
9+
from bim.commands import CommandFormatNote, CommandImportNote, CommandParseTags, CommandSyncNote
1010

1111
try:
1212
cfg = Configuration(Path(__file__, "../../config.yaml"))
1313
except FileNotFoundError:
1414
cfg = Configuration()
1515

1616

17-
@click.group(help="CLI to BUVIS InforMesh")
17+
@click.group(help="CLI to BUVIS InfoMesh")
1818
def cli() -> None:
1919
pass
2020

@@ -75,6 +75,23 @@ def format_note(
7575
console.failure(f"{path_to_note} doesn't exist")
7676

7777

78+
@cli.command("sync", help="Synchronize note with external system")
79+
@click.argument("path_to_note")
80+
@click.argument("target_system")
81+
def sync_note(
82+
path_to_note: Path,
83+
target_system: str,
84+
) -> None:
85+
if Path(path_to_note).is_file():
86+
cfg.set_configuration_item("path_note", path_to_note)
87+
cfg.set_configuration_item("target_system", target_system)
88+
buvis_cfg = Configuration()
89+
cfg.set_configuration_item("jira_adapter", buvis_cfg.get_configuration_item("jira_adapter"))
90+
cmd = CommandSyncNote(cfg)
91+
cmd.execute()
92+
else:
93+
console.failure(f"{path_to_note} doesn't exist")
94+
7895
@cli.command("parse_tags", help="Parse Obsidian Metadata Extractor tags.json")
7996
@click.argument("path_to_tags_json")
8097
@click.option(

src/bim/bim/commands/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .format_note.format_note import CommandFormatNote
22
from .import_note.import_note import CommandImportNote
33
from .parse_tags.parse_tags import CommandParseTags
4+
from .sync_note.sync_note import CommandSyncNote
45

5-
__all__ = ["CommandFormatNote", "CommandImportNote", "CommandParseTags"]
6+
__all__ = ["CommandFormatNote", "CommandImportNote", "CommandParseTags", "CommandSyncNote"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
from pathlib import Path
2+
3+
from buvis.pybase.adapters import console, JiraAdapter
4+
from buvis.pybase.configuration import Configuration, ConfigurationKeyNotFoundError
5+
from doogat.core import (
6+
MarkdownZettelFormatter,
7+
MarkdownZettelRepository,
8+
ReadDoogatUseCase,
9+
)
10+
11+
12+
class CommandSyncNote:
13+
def __init__(self: "CommandSyncNote", cfg: Configuration) -> None:
14+
try:
15+
path_note = Path(str(cfg.get_configuration_item("path_note")))
16+
if not path_note.is_file():
17+
raise FileNotFoundError
18+
self.path_note = path_note
19+
except ConfigurationKeyNotFoundError as e:
20+
raise FileNotFoundError from e
21+
22+
match cfg.get_configuration_item("target_system"):
23+
case "jira":
24+
self._target = JiraAdapter(cfg.get_configuration_item("jira_adapter"))
25+
case _:
26+
raise NotImplementedError
27+
self._cfg = cfg
28+
29+
30+
def execute(self: "CommandSyncNote") -> None:
31+
repo = MarkdownZettelRepository()
32+
reader = ReadDoogatUseCase(repo)
33+
formatter = MarkdownZettelFormatter()
34+
note = reader.execute(str(self.path_note))
35+
36+
defaults = self._cfg.get_configuration_item("jira_adapter")["defaults"]
37+
if note.type != "project":
38+
console.failure(f"{self.path_note} is not a project")
39+
return None
40+
41+
if not hasattr(note, "us") or not note.us:
42+
if note.deliverable == "enhancement":
43+
issue_type = {"name": defaults["enhancements"]["issue_type"]}
44+
feature = defaults["enhancements"]["feature"]
45+
labels = defaults["enhancements"]["labels"].split(",")
46+
priority = {"name": defaults["enhancements"]["priority"]}
47+
else:
48+
issue_type = {"name": defaults["bugs"]["issue_type"]}
49+
feature = defaults["bugs"]["feature"]
50+
labels = defaults["bugs"]["labels"].split(",")
51+
priority = {"name": defaults["bugs"]["priority"]}
52+
53+
description = "No description provided"
54+
55+
for section in note._data.sections:
56+
title, content = section
57+
if title == "## Description":
58+
description = content
59+
60+
new_issue = self._target.create_issue(
61+
title = note.title,
62+
description = description,
63+
feature = feature,
64+
issue_type = issue_type,
65+
labels = labels,
66+
priority = priority,
67+
ticket = note.ticket,
68+
)
69+
note._data.reference["us"] = new_issue.link
70+
71+
formatted_content = formatter.format(note.get_data())
72+
73+
self.path_note.write_bytes(formatted_content.encode("utf-8"))
74+
console.success(f"Jira Issue {new_issue.key} created from {self.path_note}")
75+
else:
76+
console.success("No Jira Issue creation necessary")

src/bim/pyproject.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ readme = "README.md"
99
python = "^3.12"
1010
click = "8.1.7"
1111
# doogat-core = "0.1.2"
12-
buvis-pybase = {version = "0.1.5a5", source = "test-pypi"} # doogat-core from test-pypi won't install this
13-
doogat-core = {version = "0.1.3a26", source = "test-pypi"}
14-
# doogat-core = {path = "../../../../doogat/doogat-core", develop = true}
12+
# buvis-pybase = {version = "0.1.5a5", source = "test-pypi"} # doogat-core from test-pypi won't install this
13+
buvis-pybase = {path = "../../../buvis-pybase", develop = true}
14+
# doogat-core = {version = "0.1.3a26", source = "test-pypi"}
15+
doogat-core = {path = "../../../../doogat/doogat-core", develop = true}
1516

1617
[[tool.poetry.source]]
1718
name = "test-pypi"

0 commit comments

Comments
 (0)