atli 0.5.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. atli-0.5.1/.gitignore +30 -0
  2. atli-0.5.1/CHANGELOG.md +5 -0
  3. atli-0.5.1/LICENSE +21 -0
  4. atli-0.5.1/PKG-INFO +91 -0
  5. atli-0.5.1/README.md +57 -0
  6. atli-0.5.1/pyproject.toml +74 -0
  7. atli-0.5.1/src/atli/__init__.py +3 -0
  8. atli-0.5.1/src/atli/__main__.py +6 -0
  9. atli-0.5.1/src/atli/cli.py +66 -0
  10. atli-0.5.1/src/atli/client.py +153 -0
  11. atli-0.5.1/src/atli/commands_util.py +45 -0
  12. atli-0.5.1/src/atli/config.py +110 -0
  13. atli-0.5.1/src/atli/config_commands.py +256 -0
  14. atli-0.5.1/src/atli/confluence/__init__.py +1 -0
  15. atli-0.5.1/src/atli/confluence/client.py +422 -0
  16. atli-0.5.1/src/atli/confluence/commands.py +1129 -0
  17. atli-0.5.1/src/atli/confluence/markdown.py +181 -0
  18. atli-0.5.1/src/atli/jira/__init__.py +1 -0
  19. atli-0.5.1/src/atli/jira/agile.py +282 -0
  20. atli-0.5.1/src/atli/jira/agile_commands.py +454 -0
  21. atli-0.5.1/src/atli/jira/body.py +36 -0
  22. atli-0.5.1/src/atli/jira/client.py +491 -0
  23. atli-0.5.1/src/atli/jira/commands.py +1525 -0
  24. atli-0.5.1/src/atli/jira/fields.py +75 -0
  25. atli-0.5.1/src/atli/jira/jql.py +69 -0
  26. atli-0.5.1/src/atli/output.py +54 -0
  27. atli-0.5.1/src/atli/skills/atli-confluence/SKILL.md +173 -0
  28. atli-0.5.1/src/atli/skills/atli-jira/SKILL.md +209 -0
  29. atli-0.5.1/src/atli/skills/using-atli/SKILL.md +96 -0
  30. atli-0.5.1/src/atli/skills_commands.py +144 -0
  31. atli-0.5.1/tests/__init__.py +1 -0
  32. atli-0.5.1/tests/test_client.py +109 -0
  33. atli-0.5.1/tests/test_config.py +100 -0
  34. atli-0.5.1/tests/test_config_commands.py +198 -0
  35. atli-0.5.1/tests/test_confluence.py +681 -0
  36. atli-0.5.1/tests/test_confluence_attach.py +184 -0
  37. atli-0.5.1/tests/test_confluence_attachment_dl.py +151 -0
  38. atli-0.5.1/tests/test_confluence_labels.py +201 -0
  39. atli-0.5.1/tests/test_confluence_property.py +201 -0
  40. atli-0.5.1/tests/test_confluence_space.py +261 -0
  41. atli-0.5.1/tests/test_followup_fixes.py +302 -0
  42. atli-0.5.1/tests/test_integration.py +158 -0
  43. atli-0.5.1/tests/test_jira.py +903 -0
  44. atli-0.5.1/tests/test_jira_agile.py +249 -0
  45. atli-0.5.1/tests/test_jira_bulk_meta.py +218 -0
  46. atli-0.5.1/tests/test_jira_fields.py +140 -0
  47. atli-0.5.1/tests/test_jira_helpers.py +76 -0
  48. atli-0.5.1/tests/test_jira_jql.py +36 -0
  49. atli-0.5.1/tests/test_jira_p3.py +285 -0
  50. atli-0.5.1/tests/test_markdown.py +292 -0
  51. atli-0.5.1/tests/test_review_findings.py +242 -0
  52. atli-0.5.1/tests/test_skills.py +171 -0
  53. atli-0.5.1/tests/test_sprint_move_search.py +265 -0
  54. atli-0.5.1/tests/test_stage5_features.py +368 -0
atli-0.5.1/.gitignore ADDED
@@ -0,0 +1,30 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.so
5
+ .Python
6
+ build/
7
+ dist/
8
+ *.egg-info/
9
+ .eggs/
10
+
11
+ .venv/
12
+ venv/
13
+ env/
14
+ .python-version
15
+
16
+ .pytest_cache/
17
+ .coverage
18
+ .coverage.*
19
+ htmlcov/
20
+ .tox/
21
+
22
+ .mypy_cache/
23
+ .ruff_cache/
24
+
25
+ .idea/
26
+ .vscode/
27
+ *.swp
28
+ .DS_Store
29
+
30
+ .env*
@@ -0,0 +1,5 @@
1
+ # Release Notes 已迁移
2
+
3
+ 变更记录统一维护在 [`docs/CHANGELOG.md`](../docs/CHANGELOG.md)(含 0.1.0 至今的完整历史)。
4
+
5
+ 本文件保留仅为兼容旧链接,不再更新。
atli-0.5.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 atli contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
atli-0.5.1/PKG-INFO ADDED
@@ -0,0 +1,91 @@
1
+ Metadata-Version: 2.5
2
+ Name: atli
3
+ Version: 0.5.1
4
+ Summary: Lightweight CLI for self-hosted Jira and Confluence (Server / Data Center)
5
+ Project-URL: Homepage, https://github.com/yuanyuan06/atli-kit
6
+ Project-URL: Repository, https://github.com/yuanyuan06/atli-kit
7
+ Project-URL: Issues, https://github.com/yuanyuan06/atli-kit/issues
8
+ Project-URL: Documentation, https://github.com/yuanyuan06/atli-kit/blob/main/docs/user-guide.md
9
+ Project-URL: Changelog, https://github.com/yuanyuan06/atli-kit/blob/main/docs/CHANGELOG.md
10
+ Author: atli contributors
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: atlassian,cli,confluence,data-center,jira,server
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Environment :: Console
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Software Development :: Bug Tracking
25
+ Classifier: Topic :: Utilities
26
+ Requires-Python: >=3.10
27
+ Requires-Dist: click>=8.1
28
+ Requires-Dist: httpx>=0.27
29
+ Requires-Dist: markdown-it-py>=3.0
30
+ Requires-Dist: pydantic>=2.0
31
+ Requires-Dist: rich>=13.0
32
+ Requires-Dist: tomli>=2.0.0; python_version < '3.11'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # atli
36
+
37
+ Lightweight CLI for self-hosted **Jira** and **Confluence** (Server / Data Center).
38
+
39
+ No Atlassian SDK — talks directly to the REST APIs over `httpx`. Bearer-token
40
+ (PAT) auth, REST API v2, plain `click` commands, `--json` on everything for
41
+ scripting.
42
+
43
+ > **This package targets Server / Data Center only.** Anything `*.atlassian.net`
44
+ > (Cloud) is out of scope.
45
+
46
+ ## Install
47
+
48
+ ```bash
49
+ uv tool install atli # or: pipx install atli
50
+ atli skills install # optional: the 3 bundled agent skills → ~/.agents/skills
51
+ ```
52
+
53
+ ## Quick start
54
+
55
+ ```bash
56
+ atli config init # writes ~/.config/atli/config.toml (chmod 600)
57
+ $EDITOR ~/.config/atli/config.toml # fill in URLs + personal access tokens
58
+ atli config validate # check connectivity and credentials
59
+
60
+ atli jira view PROJ-123
61
+ atli jira list --jql "assignee = currentUser() AND status != Done"
62
+ atli jira create --project PROJ --type Task --summary "Fix the thing"
63
+ atli jira transition PROJ-123 --to "In Progress"
64
+
65
+ atli conf view --space TEAM --title "Design Doc"
66
+ atli conf create --space TEAM --title "Notes" --file notes.md --format markdown
67
+ ```
68
+
69
+ Config comes from `~/.config/atli/config.toml`, or from env vars
70
+ `ATLI_JIRA_URL` / `ATLI_JIRA_TOKEN` / `ATLI_CONFLUENCE_URL` /
71
+ `ATLI_CONFLUENCE_TOKEN` (env wins over file). `--profile NAME` picks a
72
+ `[profile]` section.
73
+
74
+ ## Agent skills
75
+
76
+ The wheel bundles three Claude Code skills (`using-atli`, `atli-jira`,
77
+ `atli-confluence`). They are package data, not installed automatically:
78
+
79
+ ```bash
80
+ atli skills list # bundled vs installed
81
+ atli skills install # → ~/.agents/skills (or $ATLI_SKILLS_DIR)
82
+ atli skills install --target ~/.claude/skills
83
+ ```
84
+
85
+ ## Links
86
+
87
+ - Documentation: <https://github.com/yuanyuan06/atli-kit/blob/main/docs/user-guide.md>
88
+ - Upgrade notes: <https://github.com/yuanyuan06/atli-kit/blob/main/docs/UPGRADE.md>
89
+ - Changelog: <https://github.com/yuanyuan06/atli-kit/blob/main/docs/CHANGELOG.md>
90
+
91
+ MIT licensed.
atli-0.5.1/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # atli
2
+
3
+ Lightweight CLI for self-hosted **Jira** and **Confluence** (Server / Data Center).
4
+
5
+ No Atlassian SDK — talks directly to the REST APIs over `httpx`. Bearer-token
6
+ (PAT) auth, REST API v2, plain `click` commands, `--json` on everything for
7
+ scripting.
8
+
9
+ > **This package targets Server / Data Center only.** Anything `*.atlassian.net`
10
+ > (Cloud) is out of scope.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ uv tool install atli # or: pipx install atli
16
+ atli skills install # optional: the 3 bundled agent skills → ~/.agents/skills
17
+ ```
18
+
19
+ ## Quick start
20
+
21
+ ```bash
22
+ atli config init # writes ~/.config/atli/config.toml (chmod 600)
23
+ $EDITOR ~/.config/atli/config.toml # fill in URLs + personal access tokens
24
+ atli config validate # check connectivity and credentials
25
+
26
+ atli jira view PROJ-123
27
+ atli jira list --jql "assignee = currentUser() AND status != Done"
28
+ atli jira create --project PROJ --type Task --summary "Fix the thing"
29
+ atli jira transition PROJ-123 --to "In Progress"
30
+
31
+ atli conf view --space TEAM --title "Design Doc"
32
+ atli conf create --space TEAM --title "Notes" --file notes.md --format markdown
33
+ ```
34
+
35
+ Config comes from `~/.config/atli/config.toml`, or from env vars
36
+ `ATLI_JIRA_URL` / `ATLI_JIRA_TOKEN` / `ATLI_CONFLUENCE_URL` /
37
+ `ATLI_CONFLUENCE_TOKEN` (env wins over file). `--profile NAME` picks a
38
+ `[profile]` section.
39
+
40
+ ## Agent skills
41
+
42
+ The wheel bundles three Claude Code skills (`using-atli`, `atli-jira`,
43
+ `atli-confluence`). They are package data, not installed automatically:
44
+
45
+ ```bash
46
+ atli skills list # bundled vs installed
47
+ atli skills install # → ~/.agents/skills (or $ATLI_SKILLS_DIR)
48
+ atli skills install --target ~/.claude/skills
49
+ ```
50
+
51
+ ## Links
52
+
53
+ - Documentation: <https://github.com/yuanyuan06/atli-kit/blob/main/docs/user-guide.md>
54
+ - Upgrade notes: <https://github.com/yuanyuan06/atli-kit/blob/main/docs/UPGRADE.md>
55
+ - Changelog: <https://github.com/yuanyuan06/atli-kit/blob/main/docs/CHANGELOG.md>
56
+
57
+ MIT licensed.
@@ -0,0 +1,74 @@
1
+ [project]
2
+ name = "atli"
3
+ # Single source of truth for the version: src/atli/__init__.py::__version__.
4
+ # Do NOT add a static version here — hatchling reads it back from that file
5
+ # (see [tool.hatch.version]). Bump the version in exactly one place.
6
+ dynamic = ["version"]
7
+ description = "Lightweight CLI for self-hosted Jira and Confluence (Server / Data Center)"
8
+ readme = "README.md"
9
+ requires-python = ">=3.10"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ authors = [{ name = "atli contributors" }]
13
+ keywords = ["atlassian", "jira", "confluence", "cli", "server", "data-center"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Environment :: Console",
17
+ "Intended Audience :: Developers",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3 :: Only",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ "Topic :: Software Development :: Bug Tracking",
26
+ "Topic :: Utilities",
27
+ ]
28
+ dependencies = [
29
+ "click>=8.1",
30
+ "httpx>=0.27",
31
+ "rich>=13.0",
32
+ "pydantic>=2.0",
33
+ "markdown-it-py>=3.0",
34
+ "tomli>=2.0.0;python_version<'3.11'",
35
+ ]
36
+
37
+ [project.scripts]
38
+ atli = "atli.cli:main"
39
+
40
+ [project.urls]
41
+ Homepage = "https://github.com/yuanyuan06/atli-kit"
42
+ Repository = "https://github.com/yuanyuan06/atli-kit"
43
+ Issues = "https://github.com/yuanyuan06/atli-kit/issues"
44
+ Documentation = "https://github.com/yuanyuan06/atli-kit/blob/main/docs/user-guide.md"
45
+ Changelog = "https://github.com/yuanyuan06/atli-kit/blob/main/docs/CHANGELOG.md"
46
+
47
+ [build-system]
48
+ requires = ["hatchling"]
49
+ build-backend = "hatchling.build"
50
+
51
+ [tool.hatch.build.targets.wheel]
52
+ packages = ["src/atli"]
53
+ # No force-include needed: the skills live inside the package
54
+ # (src/atli/skills/) and ship as package data in both wheel and sdist.
55
+
56
+ [tool.hatch.version]
57
+ path = "src/atli/__init__.py"
58
+
59
+ [tool.hatch.build.targets.sdist]
60
+ # The sdist is for auditing and rebuilding, not for shipping internal notes.
61
+ # docs/ holds internal process reports (stage summaries, review findings) and
62
+ # uv.lock is redundant with the dependency declarations in pyproject.toml.
63
+ exclude = ["/docs", "/uv.lock"]
64
+
65
+ [tool.uv]
66
+ dev-dependencies = [
67
+ "pytest>=8.0",
68
+ "pytest-cov>=5.0",
69
+ "respx>=0.21",
70
+ ]
71
+
72
+ [tool.pytest.ini_options]
73
+ testpaths = ["tests"]
74
+ pythonpath = ["src"]
@@ -0,0 +1,3 @@
1
+ """atli — Lightweight CLI for self-hosted Jira and Confluence."""
2
+
3
+ __version__ = "0.5.1"
@@ -0,0 +1,6 @@
1
+ """Allow running atli as `python -m atli`."""
2
+
3
+ from atli.cli import main
4
+
5
+ if __name__ == "__main__":
6
+ main()
@@ -0,0 +1,66 @@
1
+ """Root CLI entry point for `atli`."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import click
6
+
7
+ from atli import __version__
8
+ from atli.config import Config, ConfigError
9
+ from atli.config_commands import config_cmd
10
+ from atli.confluence.commands import conf
11
+ from atli.jira.commands import jira
12
+ from atli.output import fail
13
+ from atli.skills_commands import skills_cmd
14
+
15
+
16
+ def _ensure_config(ctx: click.Context) -> Config:
17
+ """Lazy-load config on first access. Fails with friendly error if broken."""
18
+ if ctx.obj["config"] is None:
19
+ try:
20
+ ctx.obj["config"] = Config.load(ctx.obj["profile"])
21
+ except ConfigError as e:
22
+ fail(str(e))
23
+ return ctx.obj["config"]
24
+
25
+
26
+ @click.group(context_settings={"help_option_names": ["-h", "--help"]})
27
+ @click.version_option(version=__version__, prog_name="atli")
28
+ @click.option("--profile", default="default", show_default=True, help="Config profile to use")
29
+ @click.option("--json", "json_output", is_flag=True, help="Output raw JSON")
30
+ @click.option("--quiet", is_flag=True, help="Suppress progress messages")
31
+ @click.pass_context
32
+ def cli(ctx: click.Context, profile: str, json_output: bool, quiet: bool) -> None:
33
+ """atli — lightweight CLI for self-hosted Jira and Confluence."""
34
+ ctx.ensure_object(dict)
35
+ ctx.obj["json"] = json_output
36
+ ctx.obj["quiet"] = quiet
37
+ ctx.obj["profile"] = profile
38
+ # Defer config loading: let config subcommands run even if config is broken
39
+ ctx.obj["config"] = None
40
+
41
+
42
+ cli.add_command(jira)
43
+ cli.add_command(conf)
44
+ cli.add_command(config_cmd)
45
+ cli.add_command(skills_cmd)
46
+
47
+
48
+ @cli.command("completion")
49
+ @click.argument("shell", type=click.Choice(["bash", "zsh", "fish"]))
50
+ def completion(shell: str) -> None:
51
+ """Print shell completion script. Example: eval \"$(atli completion zsh)\""""
52
+ from click.shell_completion import get_completion_class
53
+
54
+ cls = get_completion_class(shell)
55
+ if cls is None:
56
+ fail(f"unsupported shell: {shell}")
57
+ comp = cls(cli=cli, ctx_args={}, prog_name="atli", complete_var="_ATLI_COMPLETE")
58
+ click.echo(comp.source())
59
+
60
+
61
+ def main() -> None:
62
+ cli()
63
+
64
+
65
+ if __name__ == "__main__":
66
+ main()
@@ -0,0 +1,153 @@
1
+ """Base HTTP client for Atlassian REST APIs.
2
+
3
+ Wraps `httpx.Client` with bearer-token auth, JSON content type, and
4
+ exception wrapping that turns HTTPStatusError into a friendly
5
+ `AtlassianAPIError` so command code can show clean errors instead of
6
+ tracebacks.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from typing import Any
12
+
13
+ import httpx
14
+
15
+
16
+ class AtlassianAPIError(Exception):
17
+ """Raised when an Atlassian REST call returns a non-2xx response."""
18
+
19
+ def __init__(self, status: int, message: str, url: str = "") -> None:
20
+ super().__init__(f"HTTP {status}: {message} ({url})" if url else f"HTTP {status}: {message}")
21
+ self.status = status
22
+ self.message = message
23
+ self.url = url
24
+
25
+
26
+ class AtlassianClient:
27
+ """Thin HTTP wrapper for Jira / Confluence REST APIs.
28
+
29
+ `base_url` should be the host root (e.g. `https://jira.company.com`),
30
+ and each method takes the API path (e.g. `/rest/api/2/issue/PROJ-1`).
31
+ """
32
+
33
+ def __init__(
34
+ self,
35
+ base_url: str,
36
+ token: str,
37
+ *,
38
+ timeout: float = 30.0,
39
+ client: httpx.Client | None = None,
40
+ ) -> None:
41
+ if not base_url or not token:
42
+ raise ValueError("base_url and token must be non-empty")
43
+ self.base_url = base_url.rstrip("/")
44
+ self.token = token
45
+ self._owned_client = client is None
46
+ self.client = client or httpx.Client(
47
+ headers={
48
+ "Authorization": f"Bearer {token}",
49
+ "Content-Type": "application/json",
50
+ "Accept": "application/json",
51
+ },
52
+ timeout=timeout,
53
+ )
54
+
55
+ def close(self) -> None:
56
+ if self._owned_client:
57
+ self.client.close()
58
+
59
+ def __enter__(self) -> "AtlassianClient":
60
+ return self
61
+
62
+ def __exit__(self, *exc_info: Any) -> None:
63
+ self.close()
64
+
65
+ def request(self, method: str, path: str, **kwargs: Any) -> dict:
66
+ url = f"{self.base_url}{path}"
67
+
68
+ # Special handling for file uploads: httpx needs to set Content-Type with boundary.
69
+ # Temporarily remove Content-Type from client headers, let httpx auto-set it,
70
+ # then restore. This is cleaner than trying to merge headers manually.
71
+ if "files" in kwargs:
72
+ original_content_type = self.client.headers.get("content-type")
73
+ if original_content_type:
74
+ del self.client.headers["content-type"]
75
+ try:
76
+ resp = self.client.request(method, url, **kwargs)
77
+ except httpx.RequestError as e:
78
+ raise AtlassianAPIError(0, f"network error: {e}", url) from e
79
+ finally:
80
+ if original_content_type:
81
+ self.client.headers["content-type"] = original_content_type
82
+ else:
83
+ # Normal request: merge any caller-supplied headers.
84
+ # A value of None means "remove this header".
85
+ extra_headers = kwargs.pop("headers", {})
86
+ if extra_headers:
87
+ headers: dict[str, str] = {}
88
+ for key, value in self.client.headers.items():
89
+ headers[key] = value
90
+ for key, value in extra_headers.items():
91
+ lower_key = key.lower()
92
+ if value is None:
93
+ headers.pop(lower_key, None)
94
+ else:
95
+ headers[lower_key] = value
96
+ kwargs["headers"] = headers
97
+
98
+ try:
99
+ resp = self.client.request(method, url, **kwargs)
100
+ except httpx.RequestError as e:
101
+ raise AtlassianAPIError(0, f"network error: {e}", url) from e
102
+
103
+ # Common response handling: only 2xx is success
104
+ if not (200 <= resp.status_code < 300):
105
+ raise AtlassianAPIError(resp.status_code, _extract_error(resp), url)
106
+
107
+ if not resp.content:
108
+ return {}
109
+ try:
110
+ return resp.json()
111
+ except ValueError:
112
+ # Non-JSON response with 2xx status
113
+ if resp.content.strip():
114
+ # Non-empty non-JSON is unexpected for successful API calls
115
+ raise AtlassianAPIError(
116
+ resp.status_code,
117
+ f"unexpected non-JSON response: {resp.text[:200]}",
118
+ url,
119
+ )
120
+ # Empty body or whitespace-only: treat as empty dict
121
+ return {}
122
+
123
+ def get(self, path: str, **kwargs: Any) -> dict:
124
+ return self.request("GET", path, **kwargs)
125
+
126
+ def post(self, path: str, **kwargs: Any) -> dict:
127
+ return self.request("POST", path, **kwargs)
128
+
129
+ def put(self, path: str, **kwargs: Any) -> dict:
130
+ return self.request("PUT", path, **kwargs)
131
+
132
+ def delete(self, path: str, **kwargs: Any) -> dict:
133
+ return self.request("DELETE", path, **kwargs)
134
+
135
+
136
+ def _extract_error(resp: httpx.Response) -> str:
137
+ """Pull a useful message out of an Atlassian error response."""
138
+ try:
139
+ data = resp.json()
140
+ except ValueError:
141
+ return resp.text.strip()[:200] or resp.reason_phrase
142
+
143
+ # Atlassian shapes vary: errorMessages list, errors dict, or message field.
144
+ if isinstance(data, dict):
145
+ if msgs := data.get("errorMessages"):
146
+ return "; ".join(str(m) for m in msgs)
147
+ if errors := data.get("errors"):
148
+ if isinstance(errors, dict):
149
+ return "; ".join(f"{k}: {v}" for k, v in errors.items())
150
+ return str(errors)
151
+ if msg := data.get("message"):
152
+ return str(msg)
153
+ return resp.text.strip()[:200] or resp.reason_phrase
@@ -0,0 +1,45 @@
1
+ """Shared utilities for CLI commands across all Atlassian products."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import click
6
+
7
+ from atli.client import AtlassianAPIError
8
+ from atli.config import Config, ConfigError
9
+ from atli.confluence.client import ConfluenceClient
10
+ from atli.jira.client import JiraClient
11
+ from atli.output import fail
12
+
13
+
14
+ def make_jira_client(ctx: click.Context) -> JiraClient:
15
+ """Create a JiraClient from context config, or fail with a user-friendly error."""
16
+ cfg: Config = ctx.obj["config"]
17
+ try:
18
+ cfg.require_jira()
19
+ except ConfigError as e:
20
+ fail(str(e))
21
+ return JiraClient(cfg.jira_url, cfg.jira_token)
22
+
23
+
24
+ def make_confluence_client(ctx: click.Context) -> ConfluenceClient:
25
+ """Create a ConfluenceClient from context config, or fail with a user-friendly error."""
26
+ cfg: Config = ctx.obj["config"]
27
+ try:
28
+ cfg.require_confluence()
29
+ except ConfigError as e:
30
+ fail(str(e))
31
+ return ConfluenceClient(cfg.confluence_url, cfg.confluence_token)
32
+
33
+
34
+ def _name(d: dict) -> str:
35
+ """Extract human-readable name from a Jira entity dict (issue, field, user, etc)."""
36
+ if d is None:
37
+ return ""
38
+ return d.get("name") or d.get("displayName") or d.get("key") or d.get("id") or "?"
39
+
40
+
41
+ def _person(d: dict | None) -> str:
42
+ """Extract person name from a Jira user dict."""
43
+ if d is None:
44
+ return ""
45
+ return d.get("displayName") or d.get("name") or d.get("emailAddress") or "?"
@@ -0,0 +1,110 @@
1
+ """Configuration management for atli.
2
+
3
+ Reads `~/.config/atli/config.toml`, supports multiple profiles, and lets
4
+ environment variables override file values. Designed so that a missing config
5
+ file is not fatal — env vars alone are enough to run.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import os
11
+ import sys
12
+ from dataclasses import dataclass
13
+ from pathlib import Path
14
+
15
+ if sys.version_info >= (3, 11):
16
+ import tomllib
17
+ else:
18
+ try:
19
+ import tomli as tomllib
20
+ except ModuleNotFoundError as e:
21
+ raise ImportError(
22
+ "tomli is required for Python 3.10. "
23
+ "Install it with: pip install tomli"
24
+ ) from e
25
+
26
+ def default_config_dir() -> Path:
27
+ """Resolve the config dir at call time so HOME changes are honored."""
28
+ return Path.home() / ".config" / "atli"
29
+
30
+
31
+ def default_config_file() -> Path:
32
+ return default_config_dir() / "config.toml"
33
+
34
+
35
+ ENV_VARS = {
36
+ "jira_url": "ATLI_JIRA_URL",
37
+ "jira_token": "ATLI_JIRA_TOKEN",
38
+ "confluence_url": "ATLI_CONFLUENCE_URL",
39
+ "confluence_token": "ATLI_CONFLUENCE_TOKEN",
40
+ }
41
+
42
+
43
+ class ConfigError(Exception):
44
+ """Raised when required config values are missing or unreadable."""
45
+
46
+
47
+ @dataclass
48
+ class Config:
49
+ """Resolved configuration for one profile."""
50
+
51
+ profile: str = "default"
52
+ jira_url: str = ""
53
+ jira_token: str = ""
54
+ confluence_url: str = ""
55
+ confluence_token: str = ""
56
+
57
+ @classmethod
58
+ def load(
59
+ cls,
60
+ profile: str = "default",
61
+ config_file: Path | None = None,
62
+ env: dict[str, str] | None = None,
63
+ ) -> "Config":
64
+ """Load config for `profile`. Env vars override file values.
65
+
66
+ Missing config file is fine — env vars alone may be enough. Missing
67
+ profile is also fine when env vars supply the values; an explicit
68
+ profile request that has no file *and* no env vars will yield an
69
+ empty Config and let `require_jira()` / `require_confluence()` raise
70
+ a useful error at the point of use.
71
+ """
72
+ path = config_file or default_config_file()
73
+ env = os.environ if env is None else env
74
+
75
+ file_section: dict[str, str] = {}
76
+ if path.exists():
77
+ try:
78
+ with path.open("rb") as f:
79
+ data = tomllib.load(f)
80
+ except Exception as e:
81
+ raise ConfigError(f"failed to parse {path}: {e}")
82
+ if profile not in data and profile != "default":
83
+ raise ConfigError(
84
+ f"profile '{profile}' not found in {path}. "
85
+ f"Available: {sorted(data.keys())}"
86
+ )
87
+ file_section = data.get(profile, {})
88
+
89
+ resolved: dict[str, str] = {}
90
+ for field, env_var in ENV_VARS.items():
91
+ resolved[field] = env.get(env_var) or file_section.get(field, "")
92
+
93
+ return cls(profile=profile, **resolved)
94
+
95
+ def require_jira(self) -> None:
96
+ if not self.jira_url or not self.jira_token:
97
+ raise ConfigError(
98
+ "Jira not configured. Set jira_url + jira_token in "
99
+ f"{default_config_file()} (profile '{self.profile}') or export "
100
+ "ATLI_JIRA_URL and ATLI_JIRA_TOKEN."
101
+ )
102
+
103
+ def require_confluence(self) -> None:
104
+ if not self.confluence_url or not self.confluence_token:
105
+ raise ConfigError(
106
+ "Confluence not configured. Set confluence_url + "
107
+ f"confluence_token in {default_config_file()} (profile "
108
+ f"'{self.profile}') or export ATLI_CONFLUENCE_URL and "
109
+ "ATLI_CONFLUENCE_TOKEN."
110
+ )