Skip to content

ROX-33193: Jira Cloud support#64

Draft
janisz wants to merge 3 commits intomainfrom
jira_cloud
Draft

ROX-33193: Jira Cloud support#64
janisz wants to merge 3 commits intomainfrom
jira_cloud

Conversation

@janisz
Copy link
Collaborator

@janisz janisz commented Feb 17, 2026

Overview

This PR updates junit2jira to work with Jira Cloud by migrating from the deprecated Jira API v2 to v3, switching from andygrunwald/go-jira to ctreminiom/go-atlassian/v2, and converting all templates from Wiki Markup to Atlassian Document Format (ADF).

Problems Encountered and Solutions

1. Authentication Failure (403 Forbidden)

Problem: Initial implementation used PAT (Personal Access Token) authentication with jira.PATAuthTransport, which failed with:

403 Forbidden: "Failed to parse Connect Session Auth Token"

Root Cause: Jira Cloud does not support PAT authentication in the same way as Jira Server/Data Center. Jira Cloud requires Basic Auth using email + API token.

Solution: Changed authentication to Basic Auth:

jiraClient.Auth.SetBasicAuth(jiraUser, jiraToken)
// where jiraUser is email (tjanisze@redhat.com) and jiraToken is the API token

2. API v2 Endpoint Deprecation (410 Gone)

Problem: After fixing authentication, all search requests failed with:

410 Gone: "Migrate to /rest/api/3/search/jql"

Root Cause: Jira Cloud deprecated the /rest/api/2/search endpoint. The error message explicitly instructed migration to /rest/api/3/search/jql.

Investigation: Searched the andygrunwald/go-jira repository and found:

Solution: Migrated from andygrunwald/go-jira to ctreminiom/go-atlassian/v2 v2.3.0, which has native support for Jira API v3 and the new SearchJQL endpoint.

3. Library Migration Challenges

Problem: The go-atlassian library has a completely different API structure compared to go-jira.

Changes Required:

  • Updated imports: github.com/ctreminiom/go-atlassian/v2/jira/v3
  • Replaced Issue.Search.Post() with Issue.Search.SearchJQL()
  • Changed from pagination with startAt to nextPageToken
  • Added context.TODO() to all API calls
  • Updated type definitions from jira.Issue to models.IssueScheme

4. Search Results with Nil Fields

Problem: After migration, search returned issues but all had <nil fields>:

Search returned 7 issues (total: 0)
Found issue: ROX-32488 - <nil fields>

Root Cause: The v3 API requires explicitly requesting which fields to return. Passing nil for the fields parameter returns minimal data without the fields we need for matching.

Solution: Changed the SearchJQL call to explicitly request the summary field:

searchResult, response, err := j.jiraClient.Issue.Search.SearchJQL(
    context.TODO(),
    jql,
    []string{"summary"}, // Explicitly request summary field
    nil,
    50,
    "",
)

5. Wiki Markup No Longer Supported

Problem: After successful migration to v3 API, the tool worked for creating issues and comments, but formatting was wrong. Jira Cloud no longer renders Wiki Markup formatting (the original template format used code blocks with {code:title=Message|borderStyle=solid}).

Solution: Converted all templates from Wiki Markup to Atlassian Document Format (ADF), which is the required format for Jira Cloud.

6. ADF Comment Creation Failure (INVALID_INPUT)

Problem: After implementing ADF structure, issue creation worked perfectly but comment creation failed with:

{
  "errorMessages": ["INVALID_INPUT"],
  "errors": {"comment": "INVALID_INPUT"}
}

Investigation:

  • Created test comments manually via curl - both simple and table comments worked
  • Added debug logging to inspect the JSON payload being sent
  • Discovered the issue: empty table cells had text nodes without the text field

Root Cause: When BUILD TAG or ORCHESTRATOR fields were empty strings, the code created text nodes like:

&models.CommentNodeScheme{
    Type: "text",
    Text: "", // Empty string
}

The Go JSON marshaler was serializing this as {"type":"text"} (omitting the empty text field entirely), which violated ADF schema requirements. ADF text nodes must have a text field, even if it's an empty string.

Solution: Added explicit checks to replace empty strings with a space character:

buildTagText := tc.BuildTag
if buildTagText == "" {
    buildTagText = " " // Use space for empty values
}

This ensures the JSON always includes the text field: {"type":"text","text":" "}

Testing

Created Issues (Examples)

  • ROX-32502 - Issue created with ADF format, includes table with links
    • Comment 15953312 - Successfully added with fixed empty field handling

Environment Variables

The tool now requires two environment variables for Jira Cloud authentication:

export JIRA_USER="your-email@example.com"  # Your Jira Cloud email
export JIRA_TOKEN="your-api-token"          # API token from https://id.atlassian.com/manage-profile/security/api-tokens

Breaking Changes

  • Environment Variables: Now requires JIRA_USER (email) in addition to JIRA_TOKEN
  • Jira URL Format: Should use base URL (e.g., https://instance.atlassian.net) not UI paths
  • API Version: Only works with Jira Cloud API v3 (v2 is deprecated)

References

janisz and others added 2 commits February 17, 2026 16:12
Migrate from andygrunwald/go-jira to ctreminiom/go-atlassian v2.3.0
to support Jira Cloud instances that require the new /rest/api/3/search/jql
endpoint. The old /rest/api/[2|3]/search endpoints were deprecated and
removed from Jira Cloud (effective May 1, 2025).

Key changes:
- Replace go-jira with go-atlassian v2.3.0
- Use SearchJQL() method for new /search/jql endpoint
- Support Basic Auth with email + API token (required for Jira Cloud)
- Use Atlassian Document Format (ADF) for issue descriptions and comments
- Request summary field explicitly in search to fix nil field issue

Fixes issue search and comment creation for Jira Cloud instances.

Related: ctreminiom/go-atlassian#345

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Jira Cloud no longer supports Wiki Markup formatting and requires
Atlassian Document Format (ADF) for issue descriptions and comments.

Changes:
- Remove Wiki Markup template (desc constant)
- Implement buildADFDescription() to generate proper ADF structure
- Use ADF for both issue creation and comment creation
- Add proper ADF node types: heading, codeBlock, table, paragraph
- Fix empty field handling: use space for empty BUILD TAG and ORCHESTRATOR
  to ensure text nodes always have the required 'text' field
- Update description() return type from string to *models.CommentNodeScheme
- Update newIssue() to accept ADF description directly

The ADF structure includes:
- H3 headings for each section (Message, STDERR, STDOUT, ERROR)
- Code blocks with language="text" for test output
- Table with bold headers for Build Information
- Proper text nodes with marks for links and formatting

This fixes the "INVALID_INPUT" error that occurred when creating
comments with empty table cells, which was caused by text nodes
missing the required 'text' field.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@janisz janisz requested a review from porridge as a code owner February 17, 2026 15:45
@janisz janisz marked this pull request as draft February 17, 2026 15:50
Fix test compilation errors after migrating from go-jira to go-atlassian:
- Update imports from github.com/andygrunwald/go-jira to go-atlassian models
- Replace jira.Issue with models.IssueScheme
- Replace jira.IssueFields with models.IssueFieldsScheme
- Update TestDescription to verify ADF structure instead of Wiki Markup
- Verify ADF node types, headings, code blocks, and tables
- Test truncation functionality with ADF format

All tests now pass successfully.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant