Metadata-Version: 2.5
Name: qamule-pytest-jira
Version: 0.1.0
Summary: Reusable Jira and Xray helpers for QAMule automation.
Requires-Python: >=3.11
Requires-Dist: atlassian-python-api>=3.41.19
Requires-Dist: pytest>=8.3
Requires-Dist: qamule-pytest>=0.1.0
Description-Content-Type: text/markdown

# qamule-pytest-jira

Reusable Jira and Xray helpers for QAMule automation.

Set the following environment variables before using the Python API or CLI:

```sh
export QAMULE_JIRA_URL="https://jira.example.com"
export QAMULE_JIRA_TOKEN="..."
```

The package provides the `qamule-jira` command and a pytest plugin. Mark a
test with `@pytest.mark.xray("TEST-123")` to include its result in the
session artifact `jira/xray-test-results.json`. The artifact uses Xray's
execution import JSON format and can be uploaded without transformation:

```sh
uv run qamule-jira execution import \
	pytest-artifacts/<session-id>/jira/xray-test-results.json
```

The plugin infers the Test Execution project from marked test keys such as
`TEST-123`. When a session contains tests from multiple projects, set the
target explicitly:

```sh
uv run pytest --xray-project-key TEST
```

Alternatively, configure `xray_project_key = TEST` in pytest configuration.

## Read Xray test cases

Fetch Xray test summaries, preconditions, and steps:

```sh
uv run qamule-jira testcase TEST-123 TEST-456
```

The command caches responses in `.xray_cache.sqlite3` for 24 hours by default.
The cache can contain Jira/Xray project data and must not be committed or
shared. This repository ignores the default cache path; protect any custom
path passed with `--cache-path` in the same way. Use `--refresh` to bypass
cached entries.

## Create issue templates

Generate a request body for Jira's Create issue API from the project's live
create metadata. `--field` accepts either a Jira field ID or its displayed name,
so custom fields such as `Example Text` are resolved to the corresponding
`customfield_*` key automatically.

```sh
uv run qamule-jira issue template \
	--project-key DEMO \
	--issue-type Task \
	--field "Example Text" \
	--field "Example Option" \
	create-task.json
```

The generated file is a QAMule issue-create JSON payload containing `fields`
and an empty `attachments` array. Replace placeholder values before sending it
to Jira. Required fields are always included; optional fields are included only
when requested with `--field`.

Create the issue from an edited template file:

```sh
uv run qamule-jira issue create create-task.json
```

The command requires a JSON object containing a `fields` object. To upload files
after the issue is created, add paths to the generated top-level `attachments`
array:

```json
{
	"fields": {
		"project": {"key": "DEMO"},
		"issuetype": {"id": "10000"},
		"summary": "Create with evidence"
	},
	"attachments": [
		"artifacts/report.log",
		"artifacts/error.png"
	]
}
```

Relative attachment paths are resolved from the directory containing the JSON
file. All files are validated before the issue is created. The command then
sends `fields` through Jira's Create issue API, uploads each attachment, and
prints the created issue's ID, key, and URL.
