Skip to content

Sanitize rendered issue descriptions to prevent Jira Cloud auto-linking#342

Merged
kkaarreell merged 1 commit into
mainfrom
ks_fix_description_sanitization
Apr 10, 2026
Merged

Sanitize rendered issue descriptions to prevent Jira Cloud auto-linking#342
kkaarreell merged 1 commit into
mainfrom
ks_fix_description_sanitization

Conversation

@kkaarreell

@kkaarreell kkaarreell commented Apr 10, 2026

Copy link
Copy Markdown
Collaborator

When rendering Jira issue descriptions from templates, the rendered text (containing strings like RHEL-9.8.0) was not being sanitized for Jira Cloud. This caused Jira to incorrectly auto-link these strings as issue references.

This fix applies the sanitize_comment() method to the rendered description, which replaces regular hyphens with non-breaking hyphens (U+2011) for Jira Cloud instances. This preserves the visual appearance while preventing unwanted auto-linking behavior.

🤖 Generated with Claude Code

Summary by Sourcery

Bug Fixes:

  • Prevent Jira Cloud from auto-linking version-like strings in issue descriptions by sanitizing rendered text prior to API calls.

@kkaarreell kkaarreell self-assigned this Apr 10, 2026
@sourcery-ai

sourcery-ai Bot commented Apr 10, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Applies Jira-specific description sanitization when creating or updating issues so that rendered descriptions (especially version-like strings) are pre-processed via the existing Jira formatting helper before being sent to Jira Cloud, preventing unwanted auto-linking behavior.

Sequence diagram for sanitized Jira issue creation flow

sequenceDiagram
    actor User
    participant CLI
    participant JiraService
    participant JiraCloud

    User->>CLI: Invoke create_issue with raw description
    CLI->>JiraService: create_issue(description, use_newa_id, fields, links)
    JiraService->>JiraService: _format_for_jira(description)
    alt use_newa_id is True
        JiraService->>JiraService: newa_id(action)
        JiraService->>JiraService: _format_for_jira(newa_id)
        JiraService->>JiraService: Prepend formatted newa_id to sanitized description
    end
    JiraService->>JiraCloud: POST create issue with sanitized description
    JiraCloud-->>JiraService: Created issue
    JiraService-->>CLI: Return Issue
    CLI-->>User: Show created issue key
Loading

Sequence diagram for sanitized Jira issue update flow

sequenceDiagram
    actor User
    participant CLI
    participant JiraService
    participant JiraCloud

    User->>CLI: Invoke update_issue with raw description
    CLI->>JiraService: update_issue(issue, description)
    JiraService->>JiraService: _format_for_jira(description)
    JiraService->>JiraService: get_details(issue)
    JiraService->>JiraService: Read current_description from issue_details
    JiraService->>JiraCloud: PUT update issue with sanitized description
    JiraCloud-->>JiraService: Updated issue
    JiraService-->>CLI: Return success flag
    CLI-->>User: Confirm description updated
Loading

Class diagram for JiraService description sanitization changes

classDiagram
    class JiraService {
        +create_issue(summary, description, action, use_newa_id, fields, links) Issue
        +update_issue(issue, description) bool
        +get_details(issue) Issue
        -_format_for_jira(text) str
        -newa_id(action) str
    }

    class Issue {
        +key str
        +fields IssueFields
    }

    class IssueFields {
        +description str
    }

    JiraService --> Issue
    Issue --> IssueFields
Loading

File-Level Changes

Change Details Files
Sanitize issue descriptions via the Jira formatting helper before sending them to Jira Cloud when creating new issues.
  • Introduce a preprocessing step that passes the description through the _format_for_jira helper at the start of create_issue.
  • Ensure that the sanitized description is used for the base description content before optionally prefixing it with the formatted NEWA ID.
newa/services/jira_service.py
Sanitize issue descriptions via the Jira formatting helper before sending them to Jira Cloud when updating existing issues.
  • Add a preprocessing step that passes the updated description through the _format_for_jira helper at the start of update_issue.
  • Guarantee that any subsequent description manipulations (e.g., NEWA ID updates) operate on already-sanitized description text.
newa/services/jira_service.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Consider keeping _render_action_fields free of side-effectful dependencies by passing in a sanitize_comment callable (or pre-sanitizing the description at a higher layer) instead of reaching into ctx to get a Jira connection inside the helper.
  • If Jira Cloud auto-linking is also undesirable in other text fields (e.g., summary or any custom text fields), it may be worth centralizing the sanitization logic at a single boundary where all outbound Jira text is processed consistently.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider keeping `_render_action_fields` free of side-effectful dependencies by passing in a `sanitize_comment` callable (or pre-sanitizing the description at a higher layer) instead of reaching into `ctx` to get a Jira connection inside the helper.
- If Jira Cloud auto-linking is also undesirable in other text fields (e.g., summary or any custom text fields), it may be worth centralizing the sanitization logic at a single boundary where all outbound Jira text is processed consistently.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@kkaarreell kkaarreell force-pushed the ks_fix_description_sanitization branch from d6ce0a1 to 48272ba Compare April 10, 2026 12:38
@kkaarreell

Copy link
Copy Markdown
Collaborator Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In both create_issue and update_issue, description is passed directly into _format_for_jira; if description can be None in any call path, consider normalizing it to an empty string or handling None inside _format_for_jira to avoid potential runtime errors.
  • In create_issue, description is sanitized before potentially prefixing the NEWA ID, but the NEWA ID itself is sanitized separately; consider consolidating the formatting logic (e.g., build the full description string first, then pass it once through _format_for_jira) to keep behavior consistent and reduce the chance of discrepancies if the sanitizer changes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In both create_issue and update_issue, description is passed directly into _format_for_jira; if description can be None in any call path, consider normalizing it to an empty string or handling None inside _format_for_jira to avoid potential runtime errors.
- In create_issue, description is sanitized before potentially prefixing the NEWA ID, but the NEWA ID itself is sanitized separately; consider consolidating the formatting logic (e.g., build the full description string first, then pass it once through _format_for_jira) to keep behavior consistent and reduce the chance of discrepancies if the sanitizer changes.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

…thods

Sanitize description text before passing to Jira API to prevent conflicts
with Jira's auto-linking syntax. This ensures user-provided descriptions
are properly formatted for Jira Cloud.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@kkaarreell kkaarreell force-pushed the ks_fix_description_sanitization branch from 48272ba to c4aa63e Compare April 10, 2026 12:46
@kkaarreell kkaarreell merged commit 0abe941 into main Apr 10, 2026
18 checks passed
@kkaarreell kkaarreell deleted the ks_fix_description_sanitization branch April 10, 2026 12:53
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