Skip to content

Add RoG (GitLab) comment support with jira, execute, and report triggers#317

Merged
kkaarreell merged 1 commit intomainfrom
ks_rog_comments
Feb 12, 2026
Merged

Add RoG (GitLab) comment support with jira, execute, and report triggers#317
kkaarreell merged 1 commit intomainfrom
ks_rog_comments

Conversation

@kkaarreell
Copy link
Collaborator

@kkaarreell kkaarreell commented Feb 11, 2026

This commit implements GitLab merge request commenting functionality parallel to the existing Errata Tool comment feature, allowing NEWA to add private/internal notes to GitLab MRs at key workflow stages.

Changes:

  • Add RoGCommentTrigger enum with JIRA, EXECUTE, and REPORT values
  • Add rog_comment_triggers field to Issue and IssueAction models
  • Add rog_enable_comments setting to Settings model (newa.conf)
  • Implement add_comment() method in RoGTool for creating internal notes
  • Add RoGCommentTrigger to YAML representer for proper serialization
  • Add JIRA trigger: comment when issue is created or mapped via --map-issue
  • Add EXECUTE trigger: comment when test execution is initiated
  • Add REPORT trigger: comment when test execution completes
  • Fix iterator exhaustion bug in jira_cmd.py (convert to list before multiple iterations)
  • Fix refresh_issue() to handle Jira issues with None descriptions
  • Use double newlines in GitLab comments for proper Markdown rendering
  • Update README documentation with rog_comment_triggers configuration

The RoG commenting feature mirrors the Errata Tool implementation:

  • Controlled by [rog] enable_comments setting in newa.conf
  • Configured per-action via rog_comment_triggers list in issue-config
  • Comments are added as private/internal GitLab notes
  • Supports conditional initialization based on event type

Fixes two critical bugs discovered during implementation:

  1. jira_cmd.py: Iterator exhaustion when checking event types before processing artifact_jobs loop (convert iterator to list)
  2. jira_service.py: refresh_issue() failed on issues with None description (convert None to empty string before processing)

🤖 Generated with Claude Code

Summary by Sourcery

Add configurable GitLab (RoG) merge request commenting tied to Jira workflow events and improve Jira integration robustness.

New Features:

  • Introduce RoGCommentTrigger enum and rog_comment_triggers on issues and actions to control when GitLab MR comments are posted.
  • Enable RoGTool to add internal comments to GitLab merge requests during Jira creation/mapping, test execution start, and test report completion.
  • Add rog_enable_comments configuration option and environment variable support to toggle RoG commenting behavior, including YAML serialization support for RoGCommentTrigger.

Bug Fixes:

  • Prevent iterator exhaustion in jira_cmd by materializing artifact jobs before multiple passes.
  • Ensure Jira refresh_issue safely handles issues with None descriptions when updating NEWA IDs.

Enhancements:

  • Wire RoG integration through jira, execute, and report CLI flows so MR comments mirror existing Errata Tool comment behavior.
  • Add detailed debug logging to Jira refresh_issue and refine artifact job discovery logging to be event-agnostic.
  • Document RoG comment trigger configuration and enable_comments usage in README.

@kkaarreell kkaarreell self-assigned this Feb 11, 2026
@sourcery-ai
Copy link

sourcery-ai bot commented Feb 11, 2026

Reviewer's Guide

Implements RoG (GitLab) merge request private comment support parallel to existing Errata Tool comments, driven by new RoGCommentTrigger configuration and a rog_enable_comments setting, while also fixing Jira-related robustness issues and iterator exhaustion in jira_cmd.

Sequence diagram for JIRA command with RoG JIRA trigger comments

sequenceDiagram
    actor User
    participant CLI as jira_cmd
    participant Ctx as CLIContext
    participant JH as JiraHandler
    participant RoG as RoGTool
    participant GL as GitLab

    User->>CLI: run jira --config ...
    CLI->>Ctx: load_artifact_jobs()
    Ctx-->>CLI: iterator of ArtifactJob
    CLI->>CLI: artifact_jobs = list(iterator)

    CLI->>CLI: has_erratum = any(EventType.ERRATUM)
    CLI->>CLI: has_rog = any(EventType.ROG)
    CLI->>RoG: create(token)
    RoG-->>CLI: RoGTool instance

    loop for each ArtifactJob
        CLI->>JH: create IssueHandler
        CLI->>CLI: _process_issue_config(..., jira_handler, et, rog)
        CLI->>CLI: _process_issue_action(..., et, rog)
        CLI->>CLI: _find_or_create_issue(...)
        CLI->>JH: refresh_issue(action, issue)
        JH-->>CLI: trigger_comment bool

        alt Errata Tool JIRA trigger
            CLI->>CLI: _handle_erratum_comment_for_jira(..., trigger_comment)
        end

        alt RoG JIRA trigger
            CLI->>CLI: _handle_rog_comment_for_jira(..., trigger_comment)
            CLI->>RoG: add_comment(artifact_job.rog.id, comment)
            RoG->>GL: get(project).mergerequests.get(number)
            RoG->>GL: notes.create(body, internal=true)
            GL-->>RoG: note created
        end
    end
Loading

Sequence diagram for EXECUTE and REPORT commands with RoG triggers

sequenceDiagram
    actor User
    participant ExecCLI as execute_cmd
    participant ReportCLI as report_cmd
    participant Ctx as CLIContext
    participant RP as ReportPortal
    participant JIRA as Jira
    participant RoG as RoGTool
    participant GL as GitLab

    User->>ExecCLI: run execute
    ExecCLI->>Ctx: get_jira_connection()
    ExecCLI->>RP: initialize_rp_connection(ctx)
    ExecCLI->>RoG: create(token) if rog_enable_comments

    ExecCLI->>ExecCLI: _process_rp_launches_and_jira_updates(ctx, rp, et, rog, mapping)
    loop for each jira_id, jobs
        ExecCLI->>RP: create_launch(job)
        RP-->>ExecCLI: launch_url
        ExecCLI->>JIRA: update issue status and fields

        alt EXECUTE trigger enabled and job.rog set
            ExecCLI->>ExecCLI: _add_rog_comment_for_execution(...)
            ExecCLI->>JIRA: issue(jira_id).fields.summary
            JIRA-->>ExecCLI: issue_summary
            ExecCLI->>RoG: add_comment(job.rog.id, comment including launch_url)
            RoG->>GL: mergerequests.get(number).notes.create(internal=true)
        end
    end

    User->>ReportCLI: run report
    ReportCLI->>Ctx: get_jira_connection()
    ReportCLI->>RP: initialize_rp_connection(ctx)
    ReportCLI->>RoG: create(token) if rog_enable_comments

    ReportCLI->>ReportCLI: _process_jira_id_reports(ctx, jira_id, execute_jobs, rp, jira_connection, et, rog)
    loop for each jira_id
        ReportCLI->>RP: _get_rp_launch_details(execute_jobs)
        RP-->>ReportCLI: launch_uuid, launch_url
        alt REPORT trigger enabled and execute_job.rog set
            ReportCLI->>ReportCLI: _add_rog_comment_for_report(...)
            ReportCLI->>JIRA: issue(jira_id).fields.summary
            JIRA-->>ReportCLI: issue_summary
            ReportCLI->>RoG: add_comment(execute_job.rog.id, comment)
            RoG->>GL: mergerequests.get(number).notes.create(internal=true)
        end
    end
Loading

Class diagram for RoG comment configuration and models

classDiagram
    class Settings {
        bool et_enable_comments
        bool et_deduplicate_releases
        bool rog_enable_comments
        string rog_token
    }

    class RoGCommentTrigger {
        <<enum>>
        JIRA
        EXECUTE
        REPORT
    }

    class ErratumCommentTrigger {
        <<enum>>
        JIRA
        EXECUTE
        REPORT
    }

    class Issue {
        list~ErratumCommentTrigger~ erratum_comment_triggers
        list~RoGCommentTrigger~ rog_comment_triggers
        string action_id
    }

    class IssueAction {
        list~ErratumCommentTrigger~ erratum_comment_triggers
        list~RoGCommentTrigger~ rog_comment_triggers
        string id
        string environment
    }

    class RoGTool {
        string url
        string token
        connection_factory() gitlab.Gitlab
        add_comment(mr_url string, comment string) void
        parse_mr_project_and_number(url string) tuple~string,string~
    }

    Settings --> RoGTool : configures
    Issue --> RoGCommentTrigger : uses
    IssueAction --> RoGCommentTrigger : uses
    Issue --> ErratumCommentTrigger : uses
    IssueAction --> ErratumCommentTrigger : uses
    RoGTool --> RoGCommentTrigger : used for triggers via config
Loading

File-Level Changes

Change Details Files
Introduce RoG (GitLab) MR comment triggers and wiring through issues, actions, YAML, and public APIs.
  • Add RoGCommentTrigger enum with JIRA/EXECUTE/REPORT values and export it from package modules
  • Extend Issue and IssueAction models with rog_comment_triggers lists using enum-based converters
  • Register RoGCommentTrigger with the YAML representer for proper serialization/deserialization
  • Expose RoGCommentTrigger via newa.init and newa.models.init for external use
newa/models/base.py
newa/models/issues.py
newa/utils/yaml_utils.py
newa/__init__.py
newa/models/__init__.py
Add RoGTool GitLab note support and hook it into jira, execute, and report workflows via triggers.
  • Implement RoGTool.add_comment() to create internal GitLab MR notes based on MR URL
  • Propagate rog_comment_triggers from IssueAction into created Issue instances in Jira job creation
  • Add RoG-comment handlers for Jira adoption, execution start, and report completion that format comments with double newlines and Jira links
  • Initialize RoGTool in jira, execute, and report commands when rog_enable_comments and token are set and pass it through helper functions
newa/services/rog_service.py
newa/cli/jira_helpers.py
newa/cli/execute_helpers.py
newa/cli/report_helpers.py
newa/cli/commands/jira_cmd.py
newa/cli/commands/execute_cmd.py
newa/cli/commands/report_cmd.py
Add configuration and documentation for enabling RoG commenting.
  • Extend Settings with rog_enable_comments boolean loaded from [rog] enable_comments / NEWA_ROG_ENABLE_COMMENTS
  • Adjust artifact job discovery log message to be event-generic rather than erratum-specific
  • Document rog.enable_comments and rog_comment_triggers usage and triggers in README plus env var list update
newa/models/settings.py
README.md
Fix Jira-related robustness issues: iterator exhaustion and handling of issues with None descriptions, plus improved logging.
  • Convert ctx.load_artifact_jobs() result to list in jira_cmd and use it both to detect event types and to iterate, avoiding iterator exhaustion
  • Delay Errata Tool and RoG initialization until their corresponding event types are present
  • In JiraService.refresh_issue, normalize None descriptions to empty strings before string operations, add debug logging, and log when no update is required
newa/cli/commands/jira_cmd.py
newa/services/jira_service.py
Align Jira helper logic and comment trigger naming with generalized comment handling.
  • Rename trigger_erratum_comment to trigger_comment and thread it through helpers to support both Errata and RoG comment flows
  • Guard refresh_issue() calls with --no-newa-id and add debug logging around its return value
  • Ensure both Errata and RoG comment handlers use the shared trigger flag when deciding to post comments
newa/cli/jira_helpers.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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 2 issues, and left some high level feedback:

  • Consider adding basic exception handling and logging around the GitLab API calls in RoGTool.add_comment so that a failure to post a merge request note does not crash the entire NEWA workflow.
  • The new RoG comment helper functions (_handle_rog_comment_for_jira, _add_rog_comment_for_execution, _add_rog_comment_for_report) duplicate comment text construction; factoring shared templates or a small formatter utility would make future changes to wording or formatting less error-prone.
  • The additional debug logging in JiraHandler.refresh_issue is quite verbose; you may want to reduce or consolidate some of these messages to keep logs readable in normal debug runs.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider adding basic exception handling and logging around the GitLab API calls in `RoGTool.add_comment` so that a failure to post a merge request note does not crash the entire NEWA workflow.
- The new RoG comment helper functions (`_handle_rog_comment_for_jira`, `_add_rog_comment_for_execution`, `_add_rog_comment_for_report`) duplicate comment text construction; factoring shared templates or a small formatter utility would make future changes to wording or formatting less error-prone.
- The additional debug logging in `JiraHandler.refresh_issue` is quite verbose; you may want to reduce or consolidate some of these messages to keep logs readable in normal debug runs.

## Individual Comments

### Comment 1
<location> `newa/cli/jira_helpers.py:347-353` </location>
<code_context>
         processed_actions[action.id] = new_issue
         short_sleep()
-        trigger_erratum_comment = jira_handler.refresh_issue(action, new_issue)
+        # Refresh issue description to add/update NEWA ID unless --no-newa-id is used
+        if not no_newa_id:
+            ctx.logger.debug(f"Calling refresh_issue for {new_issue.id}")
+            trigger_comment = jira_handler.refresh_issue(action, new_issue)
+            ctx.logger.debug(f"refresh_issue returned: {trigger_comment}")
+        else:
+            ctx.logger.info("Skipping issue refresh due to --no-newa-id flag")
         ctx.logger.info(f"Issue {new_issue} re-used")

</code_context>

<issue_to_address>
**issue (bug_risk):** Skipping `refresh_issue` when `--no-newa-id` is set also prevents NEWA label updates and comment triggering on reused issues.

Previously, `refresh_issue` always ran for reused issues, ensuring NEWA labels were kept in sync and allowing its return value to drive erratum/RoG comments. With the new guard on `--no-newa-id`, reused issues will no longer get NEWA label updates, and `trigger_comment` stays `False`, so `_handle_erratum_comment_for_jira` / `_handle_rog_comment_for_jira` will never run even when configured.

If the flag’s intent is only to hide the NEWA ID in the description, consider decoupling these behaviors (e.g., still calling `refresh_issue` but skipping only the description change, or adding a separate control for label/comment behavior).
</issue_to_address>

### Comment 2
<location> `README.md:364` </location>
<code_context>
    - `jira` - Adds a comment when a Jira issue is initially 'adopted' by NEWA (either created or taken over due to `jira --map-issue` parameter).
    - `execute` - Adds a comment when automated tests are initiated by NEWA.
    - `report` - Adds a comment when automated tests results are reported by NEWA.
+ - `rog_comment_triggers` - For specified triggers, provides an update in a RoG (GitLab) merge request through a comment. This functionality needs to be enabled also in the `newa` configuration file through `[rog] enable_comments = 1`. The following triggers are currently supported:
+   - `jira` - Adds a comment when a Jira issue is initially 'adopted' by NEWA (either created or taken over due to `jira --map-issue` parameter).
</code_context>

<issue_to_address>
**suggestion (typo):** Adjust "automated tests results" to the more natural "automated test results".

Suggested implementation:

```
   - `report` - Adds a comment when automated test results are reported by NEWA.

```

```
   - `report` - Adds a comment when automated test results are reported by NEWA.

```
</issue_to_address>

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.

This commit implements GitLab merge request commenting functionality
parallel to the existing Errata Tool comment feature, allowing NEWA to
add private/internal notes to GitLab MRs at key workflow stages.

Changes:
- Add RoGCommentTrigger enum with JIRA, EXECUTE, and REPORT values
- Add rog_comment_triggers field to Issue and IssueAction models
- Add rog_enable_comments setting to Settings model (newa.conf)
- Implement add_comment() method in RoGTool for creating internal notes
- Add RoGCommentTrigger to YAML representer for proper serialization
- Add JIRA trigger: comment when issue is created or mapped via --map-issue
- Add EXECUTE trigger: comment when test execution is initiated
- Add REPORT trigger: comment when test execution completes
- Fix iterator exhaustion bug in jira_cmd.py (convert to list before multiple iterations)
- Fix refresh_issue() to handle Jira issues with None descriptions
- Use double newlines in GitLab comments for proper Markdown rendering
- Update README documentation with rog_comment_triggers configuration

The RoG commenting feature mirrors the Errata Tool implementation:
- Controlled by [rog] enable_comments setting in newa.conf
- Configured per-action via rog_comment_triggers list in issue-config
- Comments are added as private/internal GitLab notes
- Supports conditional initialization based on event type

Fixes two critical bugs discovered during implementation:
1. jira_cmd.py: Iterator exhaustion when checking event types before
   processing artifact_jobs loop (convert iterator to list)
2. jira_service.py: refresh_issue() failed on issues with None
   description (convert None to empty string before processing)

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

Co-Authored-By: Claude <noreply@anthropic.com>
@kkaarreell kkaarreell merged commit 706ad5e into main Feb 12, 2026
18 checks passed
@kkaarreell kkaarreell deleted the ks_rog_comments branch February 12, 2026 00:19
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