codapact-jira 0.1.0__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.
- codapact_jira-0.1.0/LICENSE +21 -0
- codapact_jira-0.1.0/PKG-INFO +129 -0
- codapact_jira-0.1.0/README.md +106 -0
- codapact_jira-0.1.0/codapact.yaml +79 -0
- codapact_jira-0.1.0/gen/python/src/codapact_jira/__init__.py +6 -0
- codapact_jira-0.1.0/gen/python/src/codapact_jira/__main__.py +6 -0
- codapact_jira-0.1.0/gen/python/src/codapact_jira/_docformat.py +233 -0
- codapact_jira-0.1.0/gen/python/src/codapact_jira/_model.json +120757 -0
- codapact_jira-0.1.0/gen/python/src/codapact_jira/cli.py +7676 -0
- codapact_jira-0.1.0/gen/python/src/codapact_jira/client.py +10224 -0
- codapact_jira-0.1.0/gen/python/src/codapact_jira/py.typed +0 -0
- codapact_jira-0.1.0/gen/python/src/codapact_jira/skill/SKILL.md +39 -0
- codapact_jira-0.1.0/gen/python/src/codapact_jira/types.py +11043 -0
- codapact_jira-0.1.0/gen/python/tests/e2e.json +11697 -0
- codapact_jira-0.1.0/gen/python/tests/test_e2e.py +32 -0
- codapact_jira-0.1.0/handlers/docformat.py +233 -0
- codapact_jira-0.1.0/openapi.json +1 -0
- codapact_jira-0.1.0/pyproject.toml +68 -0
- codapact_jira-0.1.0/pyproject.toml.orig +45 -0
- codapact_jira-0.1.0/tests/test_docformat.py +145 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mike Hill
|
|
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.
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codapact-jira
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Typed Python client and `codapact-jira` CLI for the Jira Cloud platform REST API v3, with Markdown rich text, generated by Codapact
|
|
5
|
+
Keywords: jira,atlassian,markdown,adf,cli,api-client,codapact
|
|
6
|
+
Author: Mike Hill
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Typing :: Typed
|
|
15
|
+
Requires-Dist: codapact[keyring,browser]>=0.19.0,<0.20
|
|
16
|
+
Requires-Dist: adflux>=0.4.0,<0.5
|
|
17
|
+
Requires-Python: >=3.13
|
|
18
|
+
Project-URL: Homepage, https://github.com/mikejhill/codapact-jira
|
|
19
|
+
Project-URL: Repository, https://github.com/mikejhill/codapact-jira
|
|
20
|
+
Project-URL: Issues, https://github.com/mikejhill/codapact-jira/issues
|
|
21
|
+
Project-URL: Generator, https://github.com/mikejhill/codapact
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# codapact-jira
|
|
25
|
+
|
|
26
|
+
[](https://github.com/mikejhill/codapact-jira/actions/workflows/ci.yml) [](https://pypi.org/project/codapact-jira/) [](https://pypi.org/project/codapact-jira/) [](https://github.com/mikejhill/codapact-jira/blob/HEAD/LICENSE) [](https://developer.atlassian.com/cloud/jira/platform/rest/v3/) [](https://github.com/mikejhill/codapact)
|
|
27
|
+
|
|
28
|
+
Typed Python client and `codapact-jira` command-line tool for [Jira Cloud](https://developer.atlassian.com/cloud/jira/platform/rest/v3/), generated by [Codapact](https://github.com/mikejhill/codapact).
|
|
29
|
+
|
|
30
|
+
## API source
|
|
31
|
+
|
|
32
|
+
Generated from this exact contract; regenerating it with the same Codapact version reproduces the code byte for byte.
|
|
33
|
+
|
|
34
|
+
| | |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| API | [Jira Cloud](https://developer.atlassian.com/cloud/jira/platform/rest/v3/) |
|
|
37
|
+
| Contract | OpenAPI [`openapi.json`](https://github.com/mikejhill/codapact-jira/blob/HEAD/openapi.json), pinned copy of <https://dac-static.atlassian.com/cloud/jira/platform/swagger-v3.v3.json> |
|
|
38
|
+
| Version | `1001.0.0-SNAPSHOT-eac1257d8e1582ed7dd2a97a93dbea3c277d24be` |
|
|
39
|
+
| SHA-256 | `36a08f68d55c32f4e8dc257c1ca26f693d09e066a041dbf041ccb804dc52b971` |
|
|
40
|
+
| Generator | [Codapact](https://github.com/mikejhill/codapact) `0.19.0` |
|
|
41
|
+
|
|
42
|
+
## Run
|
|
43
|
+
|
|
44
|
+
With [uv](https://docs.astral.sh/uv/); uvx installs the package and its runtime on first use:
|
|
45
|
+
|
|
46
|
+
```console
|
|
47
|
+
uvx codapact-jira --help
|
|
48
|
+
uvx --refresh-package codapact-jira codapact-jira --version # update to the latest
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Requires Python 3.13 or newer.
|
|
52
|
+
|
|
53
|
+
## Credentials
|
|
54
|
+
|
|
55
|
+
Save once in the OS keyring with `uvx codapact-jira auth login`, or set per shell:
|
|
56
|
+
|
|
57
|
+
- `basic`: `JIRA_BASIC_USERNAME`, `JIRA_BASIC_PASSWORD`. Use your Atlassian account email as the username and an API token as the password (create one at https://id.atlassian.com/manage-profile/security/api-tokens).
|
|
58
|
+
- `session`: `JIRA_SESSION`. For sites where API tokens are disabled: signs in through a browser window and sends the session cookies.
|
|
59
|
+
|
|
60
|
+
`<VAR>_COMMAND` runs a command that prints the secret (e.g. a password manager). `uvx codapact-jira doctor` checks settings, credentials, connectivity, and the login.
|
|
61
|
+
|
|
62
|
+
## Use
|
|
63
|
+
|
|
64
|
+
```console
|
|
65
|
+
uvx codapact-jira issues get --issue-id-or-key PROJ-1 --query fields.description
|
|
66
|
+
uvx codapact-jira issue-search search-issues --jql 'project = PROJ ORDER BY created DESC' --fields summary,status
|
|
67
|
+
uvx codapact-jira issues create --fields '{"project":{"key":"PROJ"},"issuetype":{"name":"Task"},"summary":"Fix login"}' --markdown @description.md
|
|
68
|
+
uvx codapact-jira issue-comments add-comment --issue-id-or-key PROJ-1 --markdown 'Deployed :white_check_mark:'
|
|
69
|
+
uvx codapact-jira describe --brief # every command, for scripts and agents
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
As a library:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from codapact_jira import Client
|
|
76
|
+
|
|
77
|
+
client = Client()
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Agent skill
|
|
81
|
+
|
|
82
|
+
The package ships an agent skill that points agents at the CLI. Install it into a skills folder:
|
|
83
|
+
|
|
84
|
+
```console
|
|
85
|
+
uvx codapact-jira skill install --dir ~/.agents/skills # or any skills folder
|
|
86
|
+
uvx codapact-jira skill show # print it
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Rerun after an update to refresh it; a copy with local edits needs `--force`.
|
|
90
|
+
|
|
91
|
+
## Markdown
|
|
92
|
+
|
|
93
|
+
Rich text is Markdown both ways. `--markdown TEXT|@file|@-` sets an issue description,
|
|
94
|
+
a comment or a worklog comment; a Markdown string for `description`, `environment`,
|
|
95
|
+
a comment `body` or a worklog `comment` inside JSON arguments is converted too, and every
|
|
96
|
+
ADF document in a response comes back as Markdown. `--doc-format adf` (or
|
|
97
|
+
`JIRA_DOC_FORMAT=adf`) keeps raw ADF. The dialect (panels as `> [!NOTE]`, `:status[DONE]{color=green}`,
|
|
98
|
+
mentions, Jira emoji such as `:tick:`) is documented by `uvx adflux syntax`.
|
|
99
|
+
|
|
100
|
+
## Sign-in
|
|
101
|
+
|
|
102
|
+
Set `--base-url` (or `JIRA_BASE_URL`) to your site, for example
|
|
103
|
+
`https://your-site.atlassian.net`. Two ways to sign in:
|
|
104
|
+
|
|
105
|
+
- **API token (preferred):** `codapact-jira auth login --scheme basic` with your
|
|
106
|
+
Atlassian email and a token from
|
|
107
|
+
https://id.atlassian.com/manage-profile/security/api-tokens.
|
|
108
|
+
- **Browser sign-in, where API tokens are disabled:** `codapact-jira auth login
|
|
109
|
+
--scheme session` opens a window. The CLI fills in your email; you type your
|
|
110
|
+
password and any second factor yourself. The session cookies go to your keyring
|
|
111
|
+
and are renewed without a window until your identity provider asks for you again.
|
|
112
|
+
Browser sign-in needs Chrome, Edge or `playwright install chromium`.
|
|
113
|
+
|
|
114
|
+
**Known limitation:** the CLI never types your Atlassian password. Atlassian's
|
|
115
|
+
sign-in edge rejects a password typed by browser automation as a bot, even with the
|
|
116
|
+
right password, so a saved password cannot renew a session. When the session ends,
|
|
117
|
+
run `auth login --scheme session` again, or use an API token.
|
|
118
|
+
|
|
119
|
+
## Development
|
|
120
|
+
|
|
121
|
+
The code in `gen/python/` is generated by [Codapact](https://github.com/mikejhill/codapact). Do not edit it; regenerate instead:
|
|
122
|
+
|
|
123
|
+
```console
|
|
124
|
+
uvx codapact==0.19.0 sync --check # has the provider published a new contract?
|
|
125
|
+
uvx codapact==0.19.0 sync # pull it into the pinned copy
|
|
126
|
+
uvx codapact==0.19.0 generate # run where codapact.yaml is
|
|
127
|
+
uv run --directory gen/python pytest # offline: help, dry runs, scenarios
|
|
128
|
+
JIRA_E2E_LIVE=1 uv run --directory gen/python pytest -k live # read-only calls to the real API
|
|
129
|
+
```
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# codapact-jira
|
|
2
|
+
|
|
3
|
+
[](https://github.com/mikejhill/codapact-jira/actions/workflows/ci.yml) [](https://pypi.org/project/codapact-jira/) [](https://pypi.org/project/codapact-jira/) [](https://github.com/mikejhill/codapact-jira/blob/HEAD/LICENSE) [](https://developer.atlassian.com/cloud/jira/platform/rest/v3/) [](https://github.com/mikejhill/codapact)
|
|
4
|
+
|
|
5
|
+
Typed Python client and `codapact-jira` command-line tool for [Jira Cloud](https://developer.atlassian.com/cloud/jira/platform/rest/v3/), generated by [Codapact](https://github.com/mikejhill/codapact).
|
|
6
|
+
|
|
7
|
+
## API source
|
|
8
|
+
|
|
9
|
+
Generated from this exact contract; regenerating it with the same Codapact version reproduces the code byte for byte.
|
|
10
|
+
|
|
11
|
+
| | |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| API | [Jira Cloud](https://developer.atlassian.com/cloud/jira/platform/rest/v3/) |
|
|
14
|
+
| Contract | OpenAPI [`openapi.json`](https://github.com/mikejhill/codapact-jira/blob/HEAD/openapi.json), pinned copy of <https://dac-static.atlassian.com/cloud/jira/platform/swagger-v3.v3.json> |
|
|
15
|
+
| Version | `1001.0.0-SNAPSHOT-eac1257d8e1582ed7dd2a97a93dbea3c277d24be` |
|
|
16
|
+
| SHA-256 | `36a08f68d55c32f4e8dc257c1ca26f693d09e066a041dbf041ccb804dc52b971` |
|
|
17
|
+
| Generator | [Codapact](https://github.com/mikejhill/codapact) `0.19.0` |
|
|
18
|
+
|
|
19
|
+
## Run
|
|
20
|
+
|
|
21
|
+
With [uv](https://docs.astral.sh/uv/); uvx installs the package and its runtime on first use:
|
|
22
|
+
|
|
23
|
+
```console
|
|
24
|
+
uvx codapact-jira --help
|
|
25
|
+
uvx --refresh-package codapact-jira codapact-jira --version # update to the latest
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Requires Python 3.13 or newer.
|
|
29
|
+
|
|
30
|
+
## Credentials
|
|
31
|
+
|
|
32
|
+
Save once in the OS keyring with `uvx codapact-jira auth login`, or set per shell:
|
|
33
|
+
|
|
34
|
+
- `basic`: `JIRA_BASIC_USERNAME`, `JIRA_BASIC_PASSWORD`. Use your Atlassian account email as the username and an API token as the password (create one at https://id.atlassian.com/manage-profile/security/api-tokens).
|
|
35
|
+
- `session`: `JIRA_SESSION`. For sites where API tokens are disabled: signs in through a browser window and sends the session cookies.
|
|
36
|
+
|
|
37
|
+
`<VAR>_COMMAND` runs a command that prints the secret (e.g. a password manager). `uvx codapact-jira doctor` checks settings, credentials, connectivity, and the login.
|
|
38
|
+
|
|
39
|
+
## Use
|
|
40
|
+
|
|
41
|
+
```console
|
|
42
|
+
uvx codapact-jira issues get --issue-id-or-key PROJ-1 --query fields.description
|
|
43
|
+
uvx codapact-jira issue-search search-issues --jql 'project = PROJ ORDER BY created DESC' --fields summary,status
|
|
44
|
+
uvx codapact-jira issues create --fields '{"project":{"key":"PROJ"},"issuetype":{"name":"Task"},"summary":"Fix login"}' --markdown @description.md
|
|
45
|
+
uvx codapact-jira issue-comments add-comment --issue-id-or-key PROJ-1 --markdown 'Deployed :white_check_mark:'
|
|
46
|
+
uvx codapact-jira describe --brief # every command, for scripts and agents
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
As a library:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from codapact_jira import Client
|
|
53
|
+
|
|
54
|
+
client = Client()
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Agent skill
|
|
58
|
+
|
|
59
|
+
The package ships an agent skill that points agents at the CLI. Install it into a skills folder:
|
|
60
|
+
|
|
61
|
+
```console
|
|
62
|
+
uvx codapact-jira skill install --dir ~/.agents/skills # or any skills folder
|
|
63
|
+
uvx codapact-jira skill show # print it
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Rerun after an update to refresh it; a copy with local edits needs `--force`.
|
|
67
|
+
|
|
68
|
+
## Markdown
|
|
69
|
+
|
|
70
|
+
Rich text is Markdown both ways. `--markdown TEXT|@file|@-` sets an issue description,
|
|
71
|
+
a comment or a worklog comment; a Markdown string for `description`, `environment`,
|
|
72
|
+
a comment `body` or a worklog `comment` inside JSON arguments is converted too, and every
|
|
73
|
+
ADF document in a response comes back as Markdown. `--doc-format adf` (or
|
|
74
|
+
`JIRA_DOC_FORMAT=adf`) keeps raw ADF. The dialect (panels as `> [!NOTE]`, `:status[DONE]{color=green}`,
|
|
75
|
+
mentions, Jira emoji such as `:tick:`) is documented by `uvx adflux syntax`.
|
|
76
|
+
|
|
77
|
+
## Sign-in
|
|
78
|
+
|
|
79
|
+
Set `--base-url` (or `JIRA_BASE_URL`) to your site, for example
|
|
80
|
+
`https://your-site.atlassian.net`. Two ways to sign in:
|
|
81
|
+
|
|
82
|
+
- **API token (preferred):** `codapact-jira auth login --scheme basic` with your
|
|
83
|
+
Atlassian email and a token from
|
|
84
|
+
https://id.atlassian.com/manage-profile/security/api-tokens.
|
|
85
|
+
- **Browser sign-in, where API tokens are disabled:** `codapact-jira auth login
|
|
86
|
+
--scheme session` opens a window. The CLI fills in your email; you type your
|
|
87
|
+
password and any second factor yourself. The session cookies go to your keyring
|
|
88
|
+
and are renewed without a window until your identity provider asks for you again.
|
|
89
|
+
Browser sign-in needs Chrome, Edge or `playwright install chromium`.
|
|
90
|
+
|
|
91
|
+
**Known limitation:** the CLI never types your Atlassian password. Atlassian's
|
|
92
|
+
sign-in edge rejects a password typed by browser automation as a bot, even with the
|
|
93
|
+
right password, so a saved password cannot renew a session. When the session ends,
|
|
94
|
+
run `auth login --scheme session` again, or use an API token.
|
|
95
|
+
|
|
96
|
+
## Development
|
|
97
|
+
|
|
98
|
+
The code in `gen/python/` is generated by [Codapact](https://github.com/mikejhill/codapact). Do not edit it; regenerate instead:
|
|
99
|
+
|
|
100
|
+
```console
|
|
101
|
+
uvx codapact==0.19.0 sync --check # has the provider published a new contract?
|
|
102
|
+
uvx codapact==0.19.0 sync # pull it into the pinned copy
|
|
103
|
+
uvx codapact==0.19.0 generate # run where codapact.yaml is
|
|
104
|
+
uv run --directory gen/python pytest # offline: help, dry runs, scenarios
|
|
105
|
+
JIRA_E2E_LIVE=1 uv run --directory gen/python pytest -k live # read-only calls to the real API
|
|
106
|
+
```
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
version: 1
|
|
2
|
+
source:
|
|
3
|
+
type: openapi
|
|
4
|
+
path: openapi.json
|
|
5
|
+
upstream: https://dac-static.atlassian.com/cloud/jira/platform/swagger-v3.v3.json
|
|
6
|
+
shape:
|
|
7
|
+
- select:
|
|
8
|
+
exclude: [searchForIssuesUsingJql, searchForIssuesUsingJqlPost] # removed by Atlassian
|
|
9
|
+
- rename:
|
|
10
|
+
operations:
|
|
11
|
+
search_and_reconsile_issues_using_jql: search_issues
|
|
12
|
+
search_and_reconsile_issues_using_jql_post: search_issues_post
|
|
13
|
+
- group: {by: tag}
|
|
14
|
+
- headers: {addAttachment: {X-Atlassian-Token: no-check}} # required for uploads, any auth
|
|
15
|
+
- auth: {schemes: {basic: basic}} # email + API token (the contract's OAuth needs an app)
|
|
16
|
+
- auth: {schemes: {session: {custom: "Browser sign-in"}}, alternative: true}
|
|
17
|
+
cli:
|
|
18
|
+
env_prefix: JIRA
|
|
19
|
+
extensions: ["codapact_jira._docformat:extension"]
|
|
20
|
+
skill: {path: skills/codapact-jira}
|
|
21
|
+
auth:
|
|
22
|
+
basic:
|
|
23
|
+
check: getCurrentUser
|
|
24
|
+
docs: >-
|
|
25
|
+
Use your Atlassian account email as the username and an API token as the password
|
|
26
|
+
(create one at https://id.atlassian.com/manage-profile/security/api-tokens).
|
|
27
|
+
session:
|
|
28
|
+
check: getCurrentUser
|
|
29
|
+
docs: >-
|
|
30
|
+
For sites where API tokens are disabled: signs in through a browser window and
|
|
31
|
+
sends the session cookies.
|
|
32
|
+
browser:
|
|
33
|
+
login_url: "{base_url}/jira"
|
|
34
|
+
cookies: [tenant.session.token]
|
|
35
|
+
headers: {X-Atlassian-Token: no-check}
|
|
36
|
+
signin_hosts: ["id.atlassian.com", "*.okta.com"]
|
|
37
|
+
# Atlassian's sign-in edge refuses passwords typed by automation (see README), so
|
|
38
|
+
# the person always types it in the window; renewal reuses the session headlessly.
|
|
39
|
+
password_entry: person
|
|
40
|
+
readme:
|
|
41
|
+
name: Jira Cloud
|
|
42
|
+
docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/
|
|
43
|
+
repository: mikejhill/codapact-jira
|
|
44
|
+
examples:
|
|
45
|
+
- "issues get --issue-id-or-key PROJ-1 --query fields.description"
|
|
46
|
+
- "issue-search search-issues --jql 'project = PROJ ORDER BY created DESC' --fields summary,status"
|
|
47
|
+
- "issues create --fields '{\"project\":{\"key\":\"PROJ\"},\"issuetype\":{\"name\":\"Task\"},\"summary\":\"Fix login\"}' --markdown @description.md"
|
|
48
|
+
- "issue-comments add-comment --issue-id-or-key PROJ-1 --markdown 'Deployed :white_check_mark:'"
|
|
49
|
+
sections:
|
|
50
|
+
- title: Markdown
|
|
51
|
+
body: |
|
|
52
|
+
Rich text is Markdown both ways. `--markdown TEXT|@file|@-` sets an issue description,
|
|
53
|
+
a comment or a worklog comment; a Markdown string for `description`, `environment`,
|
|
54
|
+
a comment `body` or a worklog `comment` inside JSON arguments is converted too, and every
|
|
55
|
+
ADF document in a response comes back as Markdown. `--doc-format adf` (or
|
|
56
|
+
`JIRA_DOC_FORMAT=adf`) keeps raw ADF. The dialect (panels as `> [!NOTE]`, `:status[DONE]{color=green}`,
|
|
57
|
+
mentions, Jira emoji such as `:tick:`) is documented by `uvx adflux syntax`.
|
|
58
|
+
- title: Sign-in
|
|
59
|
+
body: |
|
|
60
|
+
Set `--base-url` (or `JIRA_BASE_URL`) to your site, for example
|
|
61
|
+
`https://your-site.atlassian.net`. Two ways to sign in:
|
|
62
|
+
|
|
63
|
+
- **API token (preferred):** `codapact-jira auth login --scheme basic` with your
|
|
64
|
+
Atlassian email and a token from
|
|
65
|
+
https://id.atlassian.com/manage-profile/security/api-tokens.
|
|
66
|
+
- **Browser sign-in, where API tokens are disabled:** `codapact-jira auth login
|
|
67
|
+
--scheme session` opens a window. The CLI fills in your email; you type your
|
|
68
|
+
password and any second factor yourself. The session cookies go to your keyring
|
|
69
|
+
and are renewed without a window until your identity provider asks for you again.
|
|
70
|
+
Browser sign-in needs Chrome, Edge or `playwright install chromium`.
|
|
71
|
+
|
|
72
|
+
**Known limitation:** the CLI never types your Atlassian password. Atlassian's
|
|
73
|
+
sign-in edge rejects a password typed by browser automation as a bot, even with the
|
|
74
|
+
right password, so a saved password cannot renew a session. When the session ends,
|
|
75
|
+
run `auth login --scheme session` again, or use an API token.
|
|
76
|
+
targets:
|
|
77
|
+
- {name: python, output: gen/python, options: {package: codapact_jira, distribution: codapact-jira, include: {_docformat.py: handlers/docformat.py}}}
|
|
78
|
+
- {name: python-cli, output: gen/python}
|
|
79
|
+
- {name: python-readme, output: .}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"""Markdown in, Markdown out: Jira rich-text fields as Markdown instead of ADF JSON.
|
|
2
|
+
|
|
3
|
+
Jira stores descriptions, comments and other rich text as Atlassian Document Format
|
|
4
|
+
(ADF). With ``--doc-format markdown`` (the default; ``JIRA_DOC_FORMAT`` sets it too):
|
|
5
|
+
|
|
6
|
+
* a string in an issue's rich-text fields (``fields.description``, ``fields.environment``,
|
|
7
|
+
their ``update`` ``set`` operations, a comment ``add`` body), a comment ``body`` or a
|
|
8
|
+
worklog ``comment`` is converted from Markdown to ADF before it is sent; other strings
|
|
9
|
+
(``historyMetadata.description``, property values, summaries) and ADF documents are not;
|
|
10
|
+
* every ADF document in a response is converted to Markdown.
|
|
11
|
+
|
|
12
|
+
``--doc-format adf`` sends and returns ADF unchanged. Conversion uses adflux with its Jira
|
|
13
|
+
profile (Jira emoji, panels as ``> [!NOTE]`` alerts, ``:status[...]``...); run
|
|
14
|
+
``uvx adflux syntax`` for the dialect.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import argparse
|
|
20
|
+
import os
|
|
21
|
+
from typing import Any
|
|
22
|
+
|
|
23
|
+
from adflux import AdfluxError, to_markdown
|
|
24
|
+
from adflux import to_adf as _to_adf
|
|
25
|
+
from codapact.runtime.errors import ValidationError
|
|
26
|
+
|
|
27
|
+
PROFILE = "jira"
|
|
28
|
+
CHOICES = ("markdown", "adf")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def to_adf(markdown: str, profile: str) -> dict[str, Any]:
|
|
32
|
+
"""Markdown to ADF; Markdown adflux cannot read is a usage error, not a crash."""
|
|
33
|
+
try:
|
|
34
|
+
return _to_adf(markdown, profile)
|
|
35
|
+
except AdfluxError as error:
|
|
36
|
+
raise usage(f"cannot convert the Markdown: {error}") from None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def is_adf(value: Any) -> bool:
|
|
40
|
+
"""Whether ``value`` is an ADF document."""
|
|
41
|
+
return (
|
|
42
|
+
isinstance(value, dict)
|
|
43
|
+
and value.get("type") == "doc"
|
|
44
|
+
and isinstance(value.get("content"), list)
|
|
45
|
+
and "version" in value
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def to_wire(value: Any, path: tuple[str, ...]) -> Any:
|
|
50
|
+
"""Convert the Markdown string at ``path`` (``*``: each list item) to ADF.
|
|
51
|
+
|
|
52
|
+
Only that exact place changes; a value already ADF, or not a string, is left alone.
|
|
53
|
+
"""
|
|
54
|
+
if not path:
|
|
55
|
+
return to_adf(value, PROFILE) if isinstance(value, str) else value
|
|
56
|
+
key, rest = path[0], path[1:]
|
|
57
|
+
if key == "*":
|
|
58
|
+
return [to_wire(v, rest) for v in value] if isinstance(value, list) else value
|
|
59
|
+
if isinstance(value, dict) and key in value:
|
|
60
|
+
return {**value, key: to_wire(value[key], rest)}
|
|
61
|
+
return value
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def from_wire(value: Any) -> Any:
|
|
65
|
+
"""Convert every ADF document in ``value`` to Markdown, recursively."""
|
|
66
|
+
if is_adf(value):
|
|
67
|
+
try:
|
|
68
|
+
return to_markdown(value, PROFILE)
|
|
69
|
+
except AdfluxError:
|
|
70
|
+
return value # doc-shaped JSON that is not ADF (an entity property, say)
|
|
71
|
+
if isinstance(value, dict):
|
|
72
|
+
return {k: from_wire(v) for k, v in value.items()}
|
|
73
|
+
if isinstance(value, list):
|
|
74
|
+
return [from_wire(v) for v in value]
|
|
75
|
+
return value
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# Operations whose request bodies carry ADF. Elsewhere ``description`` and friends are
|
|
79
|
+
# plain strings (project, field and scheme descriptions), so they are left alone.
|
|
80
|
+
SLOTS: dict[str, tuple[str, ...]] = {
|
|
81
|
+
"create_issue": ("fields", "description"),
|
|
82
|
+
"edit_issue": ("fields", "description"),
|
|
83
|
+
"add_comment": ("body",),
|
|
84
|
+
"update_comment": ("body",),
|
|
85
|
+
"add_worklog": ("comment",),
|
|
86
|
+
"update_worklog": ("comment",),
|
|
87
|
+
}
|
|
88
|
+
# Where each operation's request body carries ADF (paths below ``body``; ``*`` is each
|
|
89
|
+
# item of a list). ``fields`` and ``update`` are free-form maps keyed by Jira field id.
|
|
90
|
+
ISSUE_PATHS: tuple[tuple[str, ...], ...] = (
|
|
91
|
+
("fields", "description"),
|
|
92
|
+
("fields", "environment"),
|
|
93
|
+
("update", "description", "*", "set"),
|
|
94
|
+
("update", "environment", "*", "set"),
|
|
95
|
+
("update", "comment", "*", "add", "body"),
|
|
96
|
+
("update", "worklog", "*", "add", "comment"),
|
|
97
|
+
)
|
|
98
|
+
RICH_TEXT: dict[str, tuple[tuple[str, ...], ...]] = {
|
|
99
|
+
"create_issue": ISSUE_PATHS,
|
|
100
|
+
"edit_issue": ISSUE_PATHS,
|
|
101
|
+
"do_transition": ISSUE_PATHS,
|
|
102
|
+
# the Python field name or Jira's own: the hook runs before the body is encoded
|
|
103
|
+
"create_issues": tuple(
|
|
104
|
+
(name, "*", *path) for name in ("issue_updates", "issueUpdates") for path in ISSUE_PATHS
|
|
105
|
+
),
|
|
106
|
+
"add_comment": (("body",),),
|
|
107
|
+
"update_comment": (("body",),),
|
|
108
|
+
"add_worklog": (("comment",),),
|
|
109
|
+
"update_worklog": (("comment",),),
|
|
110
|
+
"link_issues": (("comment", "body"),),
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def usage(message: str) -> ValidationError:
|
|
115
|
+
"""An input error the CLI reports as a usage error (exit 2, structured with JSON)."""
|
|
116
|
+
return ValidationError("--markdown", message)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _slot(operation: Any) -> tuple[str, ...]:
|
|
120
|
+
"""Where ``--markdown`` goes in this operation's request body."""
|
|
121
|
+
try:
|
|
122
|
+
return SLOTS[str(getattr(operation, "name", ""))]
|
|
123
|
+
except KeyError:
|
|
124
|
+
raise usage("is for creating or editing issues, comments and worklogs") from None
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class MarkdownHook:
|
|
128
|
+
"""Call hook that converts rich text between Markdown and ADF."""
|
|
129
|
+
|
|
130
|
+
def __init__(self, markdown: str | None = None) -> None:
|
|
131
|
+
self.markdown = markdown
|
|
132
|
+
|
|
133
|
+
def before(self, operation: Any, arguments: dict[str, Any]) -> dict[str, Any]:
|
|
134
|
+
if self.markdown is not None:
|
|
135
|
+
path = _slot(operation)
|
|
136
|
+
body = arguments.get("body")
|
|
137
|
+
if body is not None and not isinstance(body, dict):
|
|
138
|
+
raise usage("needs a JSON object body")
|
|
139
|
+
request = dict(body or {})
|
|
140
|
+
target = request
|
|
141
|
+
for key in path[:-1]:
|
|
142
|
+
inner = target.get(key)
|
|
143
|
+
if inner is not None and not isinstance(inner, dict):
|
|
144
|
+
raise usage(f"needs --{key.replace('_', '-')} to be a JSON object")
|
|
145
|
+
target[key] = dict(inner or {})
|
|
146
|
+
target = target[key]
|
|
147
|
+
target[path[-1]] = self.markdown
|
|
148
|
+
arguments = {**arguments, "body": request}
|
|
149
|
+
paths = RICH_TEXT.get(str(getattr(operation, "name", "")), ())
|
|
150
|
+
body = arguments.get("body")
|
|
151
|
+
if not paths or not isinstance(body, dict):
|
|
152
|
+
return arguments
|
|
153
|
+
for path in paths:
|
|
154
|
+
body = to_wire(body, path)
|
|
155
|
+
return {**arguments, "body": body}
|
|
156
|
+
|
|
157
|
+
def after(self, operation: Any, result: Any) -> Any:
|
|
158
|
+
del operation
|
|
159
|
+
return from_wire(result)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class Extension:
|
|
163
|
+
"""``cli.extensions`` entry: the ``--doc-format`` option."""
|
|
164
|
+
|
|
165
|
+
def __init__(self, runtime: Any) -> None:
|
|
166
|
+
self.prefix = getattr(runtime, "env_prefix", "JIRA")
|
|
167
|
+
|
|
168
|
+
def add_options(self, group: argparse._ArgumentGroup, hidden: bool) -> None:
|
|
169
|
+
group.add_argument(
|
|
170
|
+
"--doc-format",
|
|
171
|
+
choices=CHOICES,
|
|
172
|
+
default=argparse.SUPPRESS,
|
|
173
|
+
help=argparse.SUPPRESS
|
|
174
|
+
if hidden
|
|
175
|
+
else f"rich text as markdown (default) or raw adf JSON (env {self.prefix}_DOC_FORMAT)",
|
|
176
|
+
)
|
|
177
|
+
group.add_argument(
|
|
178
|
+
"--markdown",
|
|
179
|
+
metavar="TEXT|@FILE|@-",
|
|
180
|
+
default=argparse.SUPPRESS,
|
|
181
|
+
help=argparse.SUPPRESS
|
|
182
|
+
if hidden
|
|
183
|
+
else "issue description, comment or worklog text as Markdown (text, @file, @- for stdin)",
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
def format(self, args: argparse.Namespace) -> str:
|
|
187
|
+
chosen = getattr(args, "doc_format", None) or os.environ.get(f"{self.prefix}_DOC_FORMAT") or "markdown"
|
|
188
|
+
if chosen not in CHOICES:
|
|
189
|
+
raise ValidationError("--doc-format", f"{self.prefix}_DOC_FORMAT must be markdown or adf")
|
|
190
|
+
return chosen
|
|
191
|
+
|
|
192
|
+
def hooks(self, args: argparse.Namespace) -> list[Any]:
|
|
193
|
+
markdown = _read(getattr(args, "markdown", None))
|
|
194
|
+
if self.format(args) != "markdown":
|
|
195
|
+
if markdown is not None:
|
|
196
|
+
raise usage("needs --doc-format markdown")
|
|
197
|
+
return []
|
|
198
|
+
return [MarkdownHook(markdown)]
|
|
199
|
+
|
|
200
|
+
def notes(self) -> list[str]:
|
|
201
|
+
return [
|
|
202
|
+
(
|
|
203
|
+
"Rich text (issue description and environment, comment body, worklog comment) "
|
|
204
|
+
"is Markdown in and out; --markdown TEXT|@file|@- sets an issue description, "
|
|
205
|
+
"comment or worklog; --doc-format adf sends and returns ADF JSON. "
|
|
206
|
+
"Dialect: uvx adflux syntax."
|
|
207
|
+
),
|
|
208
|
+
]
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _read(value: str | None) -> str | None:
|
|
212
|
+
if value is None:
|
|
213
|
+
return None
|
|
214
|
+
if value == "@-":
|
|
215
|
+
import sys
|
|
216
|
+
|
|
217
|
+
try: # UTF-8 like @file, whatever the console's code page
|
|
218
|
+
return sys.stdin.buffer.read().decode("utf-8")
|
|
219
|
+
except UnicodeError as error:
|
|
220
|
+
raise usage(f"stdin is not UTF-8: {error}") from None
|
|
221
|
+
if value.startswith("@"):
|
|
222
|
+
from pathlib import Path
|
|
223
|
+
|
|
224
|
+
try:
|
|
225
|
+
return Path(value[1:]).read_text(encoding="utf-8")
|
|
226
|
+
except (OSError, UnicodeError) as error:
|
|
227
|
+
raise usage(f"cannot read {value[1:]}: {getattr(error, 'strerror', None) or error}") from None
|
|
228
|
+
return value
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def extension(runtime: Any) -> Extension:
|
|
232
|
+
"""Factory named in ``cli.extensions``."""
|
|
233
|
+
return Extension(runtime)
|