Skip to content

feat(jira): add Jira Server/Data Center support via api_version#561

Open
sergeyklay wants to merge 2 commits into
mainfrom
feat/jira-api-version
Open

feat(jira): add Jira Server/Data Center support via api_version#561
sergeyklay wants to merge 2 commits into
mainfrom
feat/jira-api-version

Conversation

@sergeyklay
Copy link
Copy Markdown
Member

🎯 Scope & Context

Type: Feat

Intent: Extend the Jira adapter to support Jira Server and Data Center in addition to Jira Cloud. A new optional tracker.api_version config field ("2" or "3", default "3") selects the REST API variant at adapter construction time, enabling users running self-hosted Jira to connect without any adapter code changes.

Related Issues: #549

🧭 Reviewer Guide

Complexity: High

Entry Point

Start with internal/tracker/jira/jira.go. This file contains all the new construction logic: normalizeAPIVersion, resolveAuth, checkHostVersion, basePath, paginatedSearchV2, and commentPayload. The adapter struct gains apiVersion and basePath fields that drive every request path and body-format decision downstream.

Sensitive Areas

  • internal/tracker/jira/jira.go: Auth header selection (resolveAuth) decides between Basic and Bearer based on the presence of a colon in api_key and the API version. The v2 colon-free path must produce Bearer <token> and must be rejected on v3. The host/version guard (checkHostVersion) blocks Cloud endpoints combined with api_version "2" to prevent silent failures against the wrong API surface.
  • internal/tracker/jira/normalize.go: extractBody switches between ADF flattening (v3) and raw JSON-string unquoting (v2). An incorrect branch here would pass raw ADF JSON or stripped wiki markup to the prompt template.
  • internal/config/config.go and internal/config/schema.go: The new api_version field follows the same extractString / resolveEnvRef / env-key-guard pattern as in_progress_state. A bare YAML integer reaches extractString as an empty string; the adapter applies its own coercion later.

⚠️ Risk Assessment

  • Breaking Changes: No breaking changes. api_version defaults to "3", preserving all existing Cloud behavior. Existing configs without the field are unaffected.
  • Migrations/State: No migrations or state changes.

Introduces a new optional tracker config field `api_version` ("2" or
"3", default "3") that selects the Jira REST API variant at adapter
construction time.

Key changes:
- v2 uses offset-based pagination on `/rest/api/2/search` instead of
  the v3 cursor-based `/rest/api/3/search/jql` endpoint
- v2 descriptions and comment bodies are raw wiki-markup strings;
  v3 continues to flatten ADF to plain text
- v2 comment creation sends a raw-string body; v3 sends ADF
- A colon-free api_key authenticates as Bearer (PAT) on v2 and is
  rejected on v3, which requires email:token Basic auth
- Construction-time host/version guard rejects Cloud endpoints with
  api_version "2" and warns on non-Cloud endpoints with "3"
- Config layer, schema validator, and resolve map all carry the new
  field through; bare YAML integers draw a type_mismatch advisory
Copilot AI review requested due to automatic review settings June 3, 2026 21:21
@sergeyklay sergeyklay requested a review from serghei-dev as a code owner June 3, 2026 21:21
@sergeyklay sergeyklay added the area:tracker-adapter Tracker interface, Jira adapter, GitHub adapter, file adapter label Jun 3, 2026
@sergeyklay sergeyklay added this to the M23: Operator Controls milestone Jun 3, 2026
@sergeyklay sergeyklay linked an issue Jun 3, 2026 that may be closed by this pull request
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the Jira tracker adapter to support Jira Server/Data Center by introducing an optional tracker.api_version configuration switch (defaulting to "3" for Cloud), and branching request paths/pagination/auth/body handling based on whether v2 or v3 is selected.

Changes:

  • Add tracker.api_version to config/schema/docs, plumb it through CLI config resolution, and normalize/validate it at Jira adapter construction.
  • Implement v2-specific adapter behavior: /rest/api/2 base paths, v2 search offset pagination, v2 Bearer-vs-Basic auth selection, and v2 comment/description body handling (raw wiki-markup strings).
  • Add/extend tests and fixtures to cover v2 pagination, auth, payload shape, and v3 regression behavior.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
internal/tracker/jira/jira.go Adds api_version selection, base path switching, v2 pagination/auth/comment payload branching.
internal/tracker/jira/normalize.go Introduces v2 search response envelope and api-version-aware body extraction for descriptions/comments.
internal/tracker/jira/normalize_test.go Updates existing normalization tests for new function signatures (apiVersion parameter).
internal/tracker/jira/normalize_v2_test.go Adds focused tests for v2 body extraction and v2 normalization invariants.
internal/tracker/jira/jira_v2_test.go Adds end-to-end adapter tests for v2 search pagination, auth, comment write shape, and v3 regressions.
internal/tracker/jira/client.go Refactors client construction to accept a fully-formed Authorization header (Basic/Bearer).
internal/tracker/jira/client_test.go Updates client tests to construct the Basic auth header explicitly.
internal/tracker/jira/testdata/search_v2_single_page.json Adds v2 search fixture for a single-page offset response.
internal/tracker/jira/testdata/search_v2_multi_page_1.json Adds v2 search fixture for multi-page offset pagination (page 1).
internal/tracker/jira/testdata/search_v2_multi_page_2.json Adds v2 search fixture for multi-page offset pagination (page 2).
internal/tracker/jira/testdata/comments_v2.json Adds v2 comment fixture with wiki-markup bodies and null author coverage.
internal/config/schema.go Registers tracker.api_version as a known tracker field.
internal/config/schema_api_version_test.go Adds schema validation tests ensuring api_version is recognized and type mismatches are advisory.
internal/config/config.go Adds TrackerConfig.APIVersion and extracts/resolves tracker.api_version.
internal/config/config_api_version_test.go Adds config parsing tests to ensure api_version is carried through and $VAR is resolved consistently.
cmd/sortie/resolve.go Includes api_version in the raw tracker config map passed to adapter constructors.
docs/jira-adapter-notes.md Updates adapter notes to document v2/v3 behavior, auth selection, body formats, and pagination differences.
docs/architecture.md Updates the architecture/config spec to include tracker.api_version semantics and quoting guidance.

Comment thread internal/tracker/jira/jira.go Outdated
Comment thread internal/tracker/jira/jira.go Outdated
Comment thread internal/tracker/jira/jira.go
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 3, 2026

Codecov Report

❌ Patch coverage is 96.32353% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/tracker/jira/jira.go 95.72% 3 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Comment thread internal/config/config.go
Comment on lines +355 to +358
apiVersion := extractString(m, "api_version")
if !envKeys["tracker.api_version"] {
apiVersion = resolveEnvRef(apiVersion)
}
Comment on lines +249 to +262
host := strings.ToLower(parsed.Hostname())
isCloud := strings.HasSuffix(host, ".atlassian.net")

if isCloud && apiVersion == "2" {
return &domain.TrackerError{
Kind: domain.ErrTrackerPayload,
Message: fmt.Sprintf("tracker.api_version 2 targets Jira Server / Data Center; endpoint %s is Jira Cloud, which requires api_version 3", host),
}
}

if !isCloud && apiVersion == "3" {
slog.Warn("tracker.api_version 3 against non-cloud endpoint will return 404",
slog.String("host", host))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:tracker-adapter Tracker interface, Jira adapter, GitHub adapter, file adapter

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Support Jira REST API v2 for Server/Data Center instances

3 participants