# Configuration

The User Story Coverage Tagging tool uses JSON-based configuration files with environment variable overrides.

## Configuration Files

### Default Behavior

By default, scripts look for a file named `settings` in the current directory. You can specify alternative files using the `--settings` flag:

```bash
python3 US1_RPT_create_report_info_files.py --settings my_config
```

### Multiple Configuration Files

You can specify multiple settings files that will be merged together:

```bash
python3 US1_RPT_create_report_info_files.py \
  --settings base_config \
  --settings team_config \
  --settings credentials
```

**Merge Rules:**

* Single values (strings, numbers, booleans) are overridden by the last file
* Arrays are appended (concatenated)
* Objects are merged recursively

### Sample Configuration

A complete sample configuration is available in `settings.sample`. Copy and modify it:

```bash
cp settings.sample settings
```

## Environment Variables

All configuration values can be overridden using environment variables. Environment variables always take precedence over settings files.

### Environment Variable Reference

| Environment Variable               | Settings Path                      | Type       | Description                                                                                                                                                                                          |
| ---------------------------------- | ---------------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `OUTPUT_FOLDER`                    | `output_folder`                    | string     | Directory for generated reports                                                                                                                                                                      |
| `SEALIGHTS_API_TOKEN`              | `sealights.api_token`              | string     | SeaLights API authentication token                                                                                                                                                                   |
| `SEALIGHTS_DOMAIN`                 | `sealights.domain`                 | string     | SeaLights domain (e.g., company.sealights.co)                                                                                                                                                        |
| `SEALIGHTS_COVERAGE_DAYS_BACK`     | `sealights.coverage_days_back`     | integer    | Days to look back for coverage data                                                                                                                                                                  |
| `SEALIGHTS_REPORT_TIMEOUT_MINUTES` | `sealights.report_timeout_minutes` | integer    | Report generation timeout (default: 30)                                                                                                                                                              |
| `SEALIGHTS_USE_REPOSITORY_URL`     | `sealights.use_repository_url`     | boolean    | Use repository URL from SeaLights if available                                                                                                                                                       |
| `SEALIGHTS_VERIFY_SSL`             | `sealights.verify_ssl`             | boolean    | Verify SSL certificates (default: true)                                                                                                                                                              |
| `KEY_PATTERN_REGEX`                | `scm.key_pattern_regex`            | string     | Regex to extract ticket IDs                                                                                                                                                                          |
| `GITHUB_API_URL`                   | `scm.github_api_url`               | string     | GitHub API URL                                                                                                                                                                                       |
| `GITHUB_TOKEN`                     | `scm.github_token`                 | string     | GitHub personal access token                                                                                                                                                                         |
| `GITHUB_OWNER`                     | `scm.github_owner`                 | string     | GitHub organization or user                                                                                                                                                                          |
| `SCM_TYPE`                         | `scm.type`                         | string     | SCM type: github, gitlab, bitbucket, ado                                                                                                                                                             |
| `SCM_VERIFY_SSL`                   | `scm.verify_ssl`                   | boolean    | Verify SSL certificates for SCM API calls                                                                                                                                                            |
| `SCM_REMOVE_PREFIX_REGEX`          | `scm.remove_prefix_regex`          | string     | Regex to strip from branch names                                                                                                                                                                     |
| `JIRA_AUTHORIZATION`               | `jira.authorization`               | string     | Jira authorization header value                                                                                                                                                                      |
| `JIRA_GET_LIST_JQL`                | `jira.jql`                         | string     | JQL query to fetch tickets                                                                                                                                                                           |
| `JIRA_CHILD_LEVELS`                | `jira.child_levels`                | integer    | Number of child levels to traverse                                                                                                                                                                   |
| `JIRA_BASE_URL`                    | `jira.base_url`                    | string     | Jira instance base URL                                                                                                                                                                               |
| `JIRA_API_VERSION`                 | `jira.api_version`                 | integer    | Jira API version (2 or 3)                                                                                                                                                                            |
| `JIRA_CUSTOM_FIELDS`               | `jira.jira_custom_fields`          | JSON       | Custom field mappings for coverage data                                                                                                                                                              |
| `JIRA_EXTRA_TICKET_FIELDS`         | `jira.extra_ticket_fields`         | JSON array | Additional fields to pull from tickets                                                                                                                                                               |
| `JIRA_NOTIFY_USERS`                | `jira.notify_users`                | boolean    | Whether Jira updates should notify users. Defaults to `false`                                                                                                                                        |
| `JIRA_ON_PREM`                     | `jira.on_prem`                     | boolean    | Set to `true` to update the Jira summary field as plain multi-line text instead of Jira ADF                                                                                                          |
| `JIRA_VERIFY_SSL`                  | `jira.verify_ssl`                  | boolean    | Verify SSL certificates for Jira API calls                                                                                                                                                           |
| `JIRA_SUMMARY_RICH_TEMPLATE`       | `jira.summary_rich_template`       | JSON       | Inline template override for `jira.jira_custom_fields.summary_rich`. Supports raw Jira ADF JSON or a `summary_rich_layout_v1` layout document                                                        |
| `ADO_WIQL`                         | `ado.wiql`                         | string     | WIQL query to fetch work items                                                                                                                                                                       |
| `ADO_AUTHORIZATION`                | `ado.authorization`                | string     | Azure DevOps authorization header                                                                                                                                                                    |
| `ADO_ORGANIZATION`                 | `ado.organization`                 | string     | ADO organization name                                                                                                                                                                                |
| `ADO_PROJECT`                      | `ado.project`                      | string     | ADO project name                                                                                                                                                                                     |
| `ADO_CHILD_LEVELS`                 | `ado.child_levels`                 | integer    | Number of child levels to traverse                                                                                                                                                                   |
| `ADO_EXTRA_TICKET_FIELDS`          | `ado.extra_ticket_fields`          | JSON array | Additional work item fields                                                                                                                                                                          |
| `ADO_VERIFY_SSL`                   | `ado.verify_ssl`                   | boolean    | Verify SSL certificates for ADO API calls                                                                                                                                                            |
| `CONFLUENCE_AUTHORIZATION`         | `confluence.authorization`         | string     | Confluence authorization header                                                                                                                                                                      |
| `CONFLUENCE_BASE_URL`              | `confluence.base_url`              | string     | Confluence instance URL                                                                                                                                                                              |
| `CONFLUENCE_SPACE_KEY`             | `confluence.space_key`             | string     | Confluence space key                                                                                                                                                                                 |
| `CONFLUENCE_ANCESTOR_ID`           | `confluence.ancestor_id`           | string     | Parent page ID for reports                                                                                                                                                                           |
| `CONFLUENCE_NOTE`                  | `confluence.note`                  | string     | Note text for Confluence pages                                                                                                                                                                       |
| `CONFLUENCE_EXTRA_SUMMARY_FIELDS`  | `confluence.extra_summary_fields`  | JSON array | Extra fields for summary table                                                                                                                                                                       |
| `CONFLUENCE_SUMMARY_PAGE_TITLE`    | `confluence.summary_page_title`    | string     | Title for summary page                                                                                                                                                                               |
| `CONFLUENCE_DETAILS_PAGE_PREFIX`   | `confluence.details_page_prefix`   | string     | Prefix for detail page titles                                                                                                                                                                        |
| `CONFLUENCE_ON_PREM`               | `confluence.on_prem`               | boolean    | Set to `true` to use Confluence Server/Data Center REST APIs instead of Cloud APIs                                                                                                                   |
| `CONFLUENCE_REPORT_FORMAT`         | `confluence.report_format`         | JSON       | Report format settings. Default is `legacy` (separate pages). Recommended: `{ "type": "single_page", "primary_coverage": { "stage": "overall", "quality_gate": { "warning": 80, "failure": 30 } } }` |
| `CONFLUENCE_QUALITY_GATE`          | `confluence.quality_gate`          | JSON       | Backward-compatible fallback for top coverage thresholds in `single_page` format. Prefer `confluence.report_format.primary_coverage.quality_gate`                                                    |
| `CONFLUENCE_VERIFY_SSL`            | `confluence.verify_ssl`            | boolean    | Verify SSL certificates for Confluence API calls                                                                                                                                                     |
| `TEST_STAGES`                      | `test_stages`                      | JSON array | Test stage definitions                                                                                                                                                                               |
| `GROUPED_TEST_STAGES`              | `grouped_test_stages`              | JSON array | Aggregated test stage groups                                                                                                                                                                         |
| `COVERAGE_APP_LIST`                | `coverage_app_list`                | JSON array | Apps/branches to get coverage from                                                                                                                                                                   |
| `REPO_LIST`                        | `repo_list`                        | JSON array | Repository configurations                                                                                                                                                                            |

### Using Environment Variables

**Set environment variables before running:**

```bash
export SEALIGHTS_API_TOKEN="your-token-here"
export JIRA_BASE_URL="https://yourcompany.atlassian.net"
python3 US1_RPT_create_report_info_files.py --settings settings
```

**JSON values in environment variables:**

For complex values (arrays, objects), use JSON format:

```bash
export TEST_STAGES='[{"name":"Unit","reportJsonKey":"unit","reportTitle":"Unit Tests"}]'
```

## Configuration Sections

### Output Configuration

Controls where generated files are saved.

```json
{
  "output_folder": "./reports"
}
```

* `output_folder` - Directory path for output files. Leave empty for current directory.

### SeaLights Configuration

Connection and authentication for SeaLights platform.

```json
{
  "sealights": {
    "api_token": "your-api-token",
    "domain": "yourcompany.sealights.co",
    "coverage_days_back": 14,
    "report_timeout_minutes": 30,
    "use_repository_url": false,
    "verify_ssl": true
  }
}
```

**Fields:**

* `api_token` *(required)* - SeaLights API token for authentication
* `domain` *(required)* - Your SeaLights account domain
* `coverage_days_back` *(required)* - Number of days to look back for coverage data
* `report_timeout_minutes` *(optional, default: 30)* - Max wait time for report generation
* `use_repository_url` *(optional, default: false)* - Use repository URLs from SeaLights when available
* `verify_ssl` *(optional, default: true)* - Verify SSL certificates for API calls

### SCM Configuration

Source control management settings for GitHub, GitLab, Bitbucket, or Azure DevOps.

```json
{
  "scm": {
    "key_pattern_regex": "PROJ-[0-9]+",
    "github_api_url": "https://api.github.com",
    "github_token": "ghp_xxxxxxxxxxxx",
    "github_owner": "your-organization",
    "type": "github",
    "remove_prefix_regex": "^refs/heads/"
  }
}
```

**Fields:**

* `key_pattern_regex` *(required)* - Regex pattern to extract ticket IDs from text
* `type` *(required)* - SCM platform: `github`, `gitlab`, `bitbucket`, or `ado`
* `github_api_url` *(for GitHub)* - GitHub API endpoint
* `github_token` *(for GitHub)* - Personal access token
* `github_owner` *(for GitHub)* - Organization or user name
* `remove_prefix_regex` *(optional)* - Regex to remove from branch names

**Regex Pattern Examples:**

* Jira: `"[A-Z]+-[0-9]+"`
* GitHub Issues: `"#[0-9]+"`
* ADO Work Items: `"[0-9]+"`
* Custom: `"(FEAT|BUG|TASK)-[0-9]+"`

### Jira Configuration

Settings for Jira Cloud or On-Premises integration.

```json
{
  "jira": {
    "authorization": "Basic base64-encoded-credentials",
    "jql": "project = MYPROJ AND created > startOfMonth(-1)",
    "child_levels": 2,
    "base_url": "https://yourcompany.atlassian.net",
    "api_version": 3,
    "on_prem": false,
    "jira_custom_fields": {
      "summary_rich": {
        "id": "customfield_10918",
        "template_file": "summary_template.json"
      },
      "coverage": {
        "overall": "customfield_10900",
        "unit_tests": "customfield_10901"
      }
    },
    "extra_ticket_fields": [
      {"name": "Team", "field": "customfield_10400.name"},
      {"name": "Priority", "field": "priority.name"}
    ],
    "extra_link": {
      "link": "https://yourcompany.com/coverage/{ticket_id}",
      "text": "View Coverage Dashboard"
    }
  }
}
```

**Fields:**

* `authorization` *(required)* - Authorization header value (Basic or Bearer)
* `jql` *(required)* - JQL query to fetch tickets
* `child_levels` *(optional, default: 1)* - How many levels of child issues to include
* `base_url` *(required)* - Jira instance URL
* `api_version` *(required)* - Jira REST API version (2 for older, 3 for newer)
* `on_prem` *(optional, default: false)* - Set to `true` for Jira Server/Data Center. The `summary` custom field is updated as plain multi-line text instead of Jira ADF. When a `text_only_layout_v1` template is configured via `summary_rich`, that rendered text is used instead of the default plain-text fallback
* `jira_custom_fields` *(optional)* - Custom field IDs for coverage data
  * `summary` - Coverage summary field ID. Jira Cloud receives Jira ADF rich text; Jira Server/Data Center with `on_prem: true` receives plain multi-line text (or `text_only_layout_v1` template output if configured)
  * `summary_rich` *(recommended for Cloud; use `text_only_layout_v1` for on-prem)* - Object with `id` (custom field ID) and `template_file` (path to a `summary_rich_layout_v1`, `text_only_layout_v1`, or raw Jira ADF JSON template). Cloud instances use this field directly; on-prem instances render `text_only_layout_v1` templates as plain text and write the result to the `summary` field. See [summary\_rich Template Format](#summary_rich-template-format) below
  * `coverage` - Map of report JSON keys to custom field IDs for numeric coverage percentages
* `extra_ticket_fields` *(optional)* - Additional fields to extract from tickets
* `extra_link` *(optional)* - Extra link appended to the ticket summary. Object with `link` (supports `{ticket_id}` placeholder), `text`, and optional `image` (with `url`, `layout`, `alt_text`, `height`, `width`)
* `notify_users` *(optional, default: false)* - Controls the Jira `notifyUsers` query parameter when updating issues. Leave it as `false` to preserve current behavior, or set it to `true` if your token cannot update issues with notifications disabled or if you want notifications sent

**JQL Examples:**

```
"project = MYPROJ AND created >= -30d"
"issueType = Story AND sprint in openSprints()"
"labels = sprint-42 AND status != Closed"
```

### summary\_rich Template Format

The `summary_rich` field accepts either a raw [Jira ADF](https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/) JSON document or a simpler layout document using `"template_type": "summary_rich_layout_v1"` (Jira Cloud) or `"template_type": "text_only_layout_v1"` (Jira Server/Data Center on-prem). The layout formats are designed to be easy to author by hand and support dynamic coverage values, quality-gate icons, stage listings, and optional Confluence links.

**Minimal example** (`summary_template.json`):

```json
{
  "template_type": "summary_rich_layout_v1",
  "content": [
    {
      "type": "quality_gate",
      "field": "overall",
      "warning": 80,
      "failure": 30,
      "label": "Code Changes Coverage",
      "coverage_text": "{overall}%"
    },
    {
      "type": "stage_badges",
      "source": "grouped_test_stages"
    },
    {
      "type": "text",
      "text": "{overall_count} covered / {results_count} modified methods"
    },
    {
      "type": "link",
      "text": "Coverage Report",
      "text_url": "{detailed_coverage_report_url}",
      "skip_if_empty": true
    }
  ]
}
```

**Supported block types:**

* `quality_gate` - Renders a Jira panel whose colour is chosen automatically from coverage thresholds. Set `warning` and `failure` thresholds; coverage above `warning` → `success` panel, above `failure` → `warning` panel, otherwise `error` panel. Use `field` with a plain report key (e.g. `overall`, `unit_tests`) and the renderer resolves the matching coverage value automatically. Plain placeholders like `{overall}%` also resolve to rounded values.
* `info` - Renders a Jira panel with a fixed label and highlighted coverage value. Use `info_type` to choose the Jira panel type (`info`, `note`, `success`, `warning`, or `error`).
* `stage_badges` - Renders a single paragraph of stage coverage badges. Provide `stages` as an ordered array of report JSON keys or `{ "key": "...", "label": "..." }` entries. Alternatively set `source` to `grouped_test_stages`, `test_stages`, or `all` to populate from settings automatically.
* `text` - Renders a plain paragraph. Supports `{placeholder}` substitution for any coverage context key (e.g. `{overall_count}`, `{results_count}`, `{ticket_id}`).
* `link` - Renders a linked text paragraph or an external image. Set `skip_if_empty: true` to omit the block when the URL is empty. Use `text_url` for the text link target. For images, provide an `image` object with `url`, `layout`, `alt_text`, `height`, `width`, and optional `external_url` for the click target.
* `divider` - Renders a horizontal rule separator.
* `empty_paragraph` - Renders an empty paragraph for spacing.

**Available template context keys** (usable as `{key}` placeholders in any `text` or `coverage_text` value):

| Key                              | Description                                                 |
| -------------------------------- | ----------------------------------------------------------- |
| `{ticket_id}`                    | The Jira ticket key                                         |
| `{results_count}`                | Total modified methods                                      |
| `{results_files}`                | Total modified files                                        |
| `{overall_count}`                | Covered methods (overall)                                   |
| `{<stage>_coverage}`             | Raw coverage % for a stage                                  |
| `{<stage>_coverage_rounded}`     | Rounded coverage % for a stage                              |
| `{<stage>}`                      | Alias for rounded coverage %                                |
| `{detailed_coverage_report_url}` | URL of the Confluence detail page (if generated)            |
| `{uncovered_method_report_url}`  | URL of the uncovered-methods Confluence page (if generated) |
| `{extra_link_url}`               | URL from `jira.extra_link`                                  |
| `{extra_link_text}`              | Text from `jira.extra_link`                                 |

The `summary_rich_template` setting (or `JIRA_SUMMARY_RICH_TEMPLATE` env var) can be used to supply the template inline as a JSON value, overriding `template_file`.

#### text\_only\_layout\_v1 (Jira Server / Data Center)

Use `"template_type": "text_only_layout_v1"` when `on_prem: true`. The template is rendered to plain text and written to the `summary` custom field. Quality-gate icons (🟢/🟡/🔴) are included where configured.

**Example** (`summary_template_onprem.json`):

```json
{
  "template_type": "text_only_layout_v1",
  "indent": "   ",
  "content": [
    {
      "type": "coverage_section",
      "header": "Coverage:",
      "stages": [
        { "label": "Overall",       "field": "overall",       "warning": 80, "failure": 30, "show_icon": true },
        { "label": "Test Stage 1",  "field": "test_stage_1",  "warning": 80, "failure": 30, "show_icon": true },
        { "label": "Test Stage 2",  "field": "test_stage_2",  "warning": 80, "failure": 30, "show_icon": true },
        { "label": "Test Stage 3",  "field": "test_stage_3",  "warning": 80, "failure": 30, "show_icon": true }
      ]
    },
    { "type": "empty_line" },
    {
      "type": "summary_section",
      "header": "Summary:",
      "overall_field": "overall",
      "stages": [
        { "label": "Test Stage 1", "field": "test_stage_1" },
        { "label": "Test Stage 2", "field": "test_stage_2" },
        { "label": "Test Stage 3", "field": "test_stage_3" }
      ]
    },
    {
      "type": "link",
      "text": "Here is the detail report: {detailed_coverage_report_url}"
    }
  ]
}
```

This produces output like:

```
Coverage:
   Overall: 🟢 87%
   Test Stage 1: 🟡 65%
   Test Stage 2: 🔴 22%
   Test Stage 3: 🟢 91%

Summary:
   Total of 42 methods were modified in 8 files.
   Number of methods tested in one or more test stages: 37
   Number of methods untested in one or more test stages: 5
   Number of methods untested in Test Stage 1: 15
   Number of methods untested in Test Stage 2: 33
   Number of methods untested in Test Stage 3: 4
Here is the detail report: https://confluence.example.com/display/MYSPACE/PROJ-123
```

**Supported block types for `text_only_layout_v1`:**

* `coverage_section` - Renders a labelled coverage line per stage. Each stage entry uses `field` (report JSON key), `label` (display name), `warning`/`failure` thresholds for the icon, and `show_icon: true` to include the 🟢/🟡/🔴 icon. Set `source` to `grouped_test_stages`, `test_stages`, or `all` to auto-populate stages from settings instead of listing them explicitly.
* `summary_section` - Renders a summary block with total method counts and per-stage untested counts. Set `overall_field` to the report JSON key used for the "tested in one or more stages" count (default: `overall`). Accepts the same `stages` or `source` as `coverage_section` for the per-stage untested lines.
* `text` - Renders a plain line. Supports `{placeholder}` substitution for any coverage context key.
* `link` - Renders a plain text line. Supports `{placeholder}` substitution. The block is skipped if the rendered text is empty.
* `divider` - Renders `---`.
* `empty_line` - Renders a blank line.

***

### Azure DevOps Configuration

Settings for Azure DevOps integration.

```json
{
  "ado": {
    "wiql": "SELECT [System.Id] FROM WorkItems WHERE [System.WorkItemType] = 'User Story' AND [System.ChangedDate] >= @Today - 30",
    "authorization": "Basic base64-pat-token",
    "organization": "your-organization",
    "project": "your-project",
    "child_levels": 2,
    "extra_ticket_fields": [
      {"name": "Team", "field": "System.TeamProject"}
    ]
  }
}
```

**Fields:**

* `wiql` *(required)* - WIQL query to fetch work items
* `authorization` *(required)* - Authorization header with PAT token
* `organization` *(required)* - ADO organization name
* `project` *(required)* - Project name
* `child_levels` *(optional, default: 1)* - Levels of child work items
* `extra_ticket_fields` *(optional)* - Additional fields to extract

**WIQL Examples:**

```
"SELECT [System.Id] FROM WorkItems WHERE [System.WorkItemType] = 'User Story'"
"SELECT [System.Id] FROM WorkItems WHERE [System.IterationPath] = 'Sprint 42'"
```

### Confluence Configuration

Settings for creating Confluence pages.

```json
{
  "confluence": {
    "authorization": "Basic base64-credentials",
    "base_url": "https://yourcompany.atlassian.net",
    "on_prem": false,
    "space_key": "DEV",
    "ancestor_id": "123456789",
    "note": "This page is auto-generated. Changes will be overwritten.",
    "extra_summary_fields": ["Team", "Priority"],
    "summary_page_title": "Sprint Coverage Summary",
    "details_page_prefix": "Coverage -",
    "report_format": {
      "type": "single_page",
      "primary_coverage": {
        "stage": "overall",
        "quality_gate": {
          "warning": 80,
          "failure": 30
        }
      }
    },
    "verify_ssl": true
  }
}
```

**Fields:**

* `authorization` *(required)* - Authorization header value
* `base_url` *(required)* - Confluence instance URL
* `on_prem` *(optional, default: false)* - Set to `true` to use Confluence Server/Data Center REST APIs instead of Confluence Cloud APIs
* `space_key` *(required)* - Confluence space identifier
* `ancestor_id` *(required)* - Parent page ID for created pages
* `note` *(optional)* - Warning note added to pages
* `extra_summary_fields` *(optional)* - Fields to include in summary table
* `summary_page_title` *(optional)* - Title for auto-generated summary page
* `details_page_prefix` *(optional)* - Prefix for detail page titles
* `report_format` *(optional, default: legacy)* - Controls the page layout. Defaults to `"legacy"` for backward compatibility (separate detail and uncovered-methods pages). The recommended value is `type: "single_page"`, which produces one combined coverage page per ticket with a quality-gate colour indicator. The `primary_coverage` block selects which test stage drives the quality-gate colour on the summary table
* `quality_gate` *(optional)* - Backward-compatible fallback for top-level coverage thresholds. Prefer `report_format.primary_coverage.quality_gate` for new configurations
* `verify_ssl` *(optional, default: true)* - Verify SSL certificates for Confluence API calls

### Test Stages Configuration

Defines test stages/phases for coverage reporting.

```json
{
  "test_stages": [
    {
      "name": "Unit_Tests",
      "reportJsonKey": "unit_tests",
      "reportTitle": "Unit Tests"
    },
    {
      "name": "Integration_Tests",
      "reportJsonKey": "integration_tests",
      "reportTitle": "Integration Tests"
    },
    {
      "name": "E2E_Tests",
      "reportJsonKey": "e2e_tests",
      "reportTitle": "E2E Tests"
    }
  ]
}
```

**Fields per stage:**

* `name` *(required)* - Stage name as it appears in SeaLights TGA report
* `reportJsonKey` *(required)* - JSON key in generated report files
* `reportTitle` *(required)* - Display title in HTML/Confluence reports

### Grouped Test Stages Configuration

Creates aggregated coverage metrics from multiple test stages.

```json
{
  "grouped_test_stages": [
    {
      "name": "Overall",
      "reportJsonKey": "overall",
      "reportTitle": "Overall Coverage",
      "stages": ["Unit_Tests", "Integration_Tests", "E2E_Tests"],
      "show_gate": true,
      "severity": 2
    },
    {
      "name": "Pre_Prod",
      "reportJsonKey": "pre_prod",
      "reportTitle": "Pre-Production",
      "stages": ["Integration_Tests", "E2E_Tests"],
      "show_gate": true,
      "severity": 1
    }
  ]
}
```

**Fields per group:**

* `name` *(required)* - Group identifier
* `reportJsonKey` *(required)* - JSON key in report files
* `reportTitle` *(required)* - Display title
* `stages` *(required)* - Array of stage names to aggregate
* `show_gate` *(optional)* - Show pass/fail gate in reports
* `severity` *(optional)* - 1 (orange) or 2 (red) for failed gates

### Coverage App List Configuration

Specifies which applications and branches to collect coverage from.

```json
{
  "coverage_app_list": [
    {
      "app_regex": "my-app",
      "branch_regex": "main",
      "integration_build": false
    },
    {
      "app_regex": "my-integration-build",
      "branch_regex": "develop",
      "integration_build": true
    }
  ]
}
```

**Fields per entry:**

* `app_regex` *(required)* - Regex matching SeaLights application name
* `branch_regex` *(required)* - Regex matching branch name
* `integration_build` *(optional, default: false)* - If true, treats as integration build with components

**Regex Matching:**

* Use exact names: `"my-app"`
* Use patterns: `"app-.*"`
* Match any: `".*"`

### Repository List Configuration

Maps git repositories to SeaLights applications.

```json
{
  "repo_list": [
    {
      "repoName": "frontend-app",
      "baseUrl": "git@github.com:mycompany/",
      "branchName": "main",
      "SealightsAppName": "frontend",
      "SealightsBranchName": "main",
      "ignore": false
    },
    {
      "repoName": "backend-api",
      "baseUrl": "https://github.com/mycompany/",
      "branchName": "develop",
      "SealightsAppName": "api-service",
      "SealightsBranchName": "dev"
    }
  ]
}
```

**Fields per repository:**

* `repoName` *(required)* - Repository name in git
* `baseUrl` *(required)* - Git base URL (SSH or HTTPS)
* `branchName` *(required)* - Branch to process
* `SealightsAppName` *(required)* - Application name in SeaLights
* `SealightsBranchName` *(required)* - Branch name in SeaLights
* `ignore` *(optional, default: false)* - Skip this repository

## Complete Configuration Example

See `settings.sample` for a fully commented example with all options.

## Configuration Validation

Scripts validate configuration at startup. Common validation errors:

* **Missing required fields** - Check that all required settings are present
* **Invalid regex patterns** - Test regex patterns using online tools
* **Invalid URLs** - Ensure URLs include protocol (https\://)
* **Invalid JSON in env vars** - Validate JSON format for array/object values

## Best Practices

### 1. Separate Sensitive Data

Split configuration into multiple files:

```bash
# base_config - Non-sensitive settings
{
  "output_folder": "./reports",
  "test_stages": [...]
}

# credentials - Sensitive tokens (gitignored)
{
  "sealights": {"api_token": "..."},
  "jira": {"authorization": "..."}
}

# Usage
python3 script.py --settings base_config --settings credentials
```

### 2. Use Environment Variables for CI/CD

In CI/CD pipelines, use environment variables instead of files:

```yaml
# GitHub Actions example
env:
  SEALIGHTS_API_TOKEN: ${{ secrets.SEALIGHTS_TOKEN }}
  JIRA_AUTHORIZATION: ${{ secrets.JIRA_AUTH }}
```

### 3. Version Control Settings

* **Commit:** Base configuration, structure, regex patterns
* **Ignore:** Credentials, tokens, production URLs

```gitignore
settings
credentials
*_credentials.json
```

### 4. Document Custom Fields

When using custom fields, document them in comments:

```json
{
  "jira": {
    "jira_custom_fields": {
      "// Note: customfield_10917 = Coverage Summary Text Field": "",
      "summary": "customfield_10917",
      "coverage": {
        "// Note: customfield_10900 = Overall Coverage %": "",
        "overall": "customfield_10900"
      }
    }
  }
}
```

## Next Steps

* [Examples](/knowledgebase/setup-and-configuration/integrations/user-story-coverage/examples.md) - See configuration in action
* [Security Considerations](/knowledgebase/setup-and-configuration/integrations/user-story-coverage/security-considerations.md) - Protect sensitive data
* [Troubleshooting](/knowledgebase/setup-and-configuration/integrations/user-story-coverage/troubleshooting.md) - Configuration issues and solutions


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sealights.io/knowledgebase/setup-and-configuration/integrations/user-story-coverage/configuration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
