Skip to content

Initialize ET and RoG connections only when needed#319

Merged
kkaarreell merged 1 commit intomainfrom
ks_init_conn_when_needed
Feb 13, 2026
Merged

Initialize ET and RoG connections only when needed#319
kkaarreell merged 1 commit intomainfrom
ks_init_conn_when_needed

Conversation

@kkaarreell
Copy link
Collaborator

@kkaarreell kkaarreell commented Feb 13, 2026

Avoid unnecessary external service connections by checking event types before initializing Errata Tool and RoG connections in execute and report commands. This prevents connection errors when processing non-erratum or non-RoG events.

Changes:

  • execute_cmd.py: Check for ERRATUM/ROG events before connecting
  • report_cmd.py: Check for ERRATUM/ROG events before connecting
  • Follows the same defensive pattern already used in jira_cmd.py

Fixes traceback when running execute -C on jobs without erratum events.

🤖 Generated with Claude Code

Summary by Sourcery

Bug Fixes:

  • Prevent errors when running execute and report commands on jobs that do not include erratum or RoG events by skipping unneeded external connections.

Avoid unnecessary external service connections by checking event types
before initializing Errata Tool and RoG connections in execute and
report commands. This prevents connection errors when processing
non-erratum or non-RoG events.

Changes:
- execute_cmd.py: Check for ERRATUM/ROG events before connecting
- report_cmd.py: Check for ERRATUM/ROG events before connecting
- Follows the same defensive pattern already used in jira_cmd.py

Fixes traceback when running execute -C on jobs without erratum events.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@kkaarreell kkaarreell self-assigned this Feb 13, 2026
@sourcery-ai
Copy link

sourcery-ai bot commented Feb 13, 2026

Reviewer's Guide

Defensively gate Errata Tool and RoG connections in execute and report commands so they are only initialized when corresponding ERRATUM/ROG events are present, preventing unnecessary external calls and tracebacks for jobs without those event types.

Sequence diagram for conditional ET/RoG initialization in execute command

sequenceDiagram
    actor User
    participant CLI
    participant ExecuteCommand as cmd_execute
    participant ReportPortal as ReportPortal
    participant ErrataTool as ErrataTool
    participant RoGTool as RoGTool

    User->>CLI: run execute
    CLI->>ExecuteCommand: cmd_execute(ctx, schedule_job_list)

    ExecuteCommand->>ReportPortal: initialize_rp_connection(ctx)
    Note over ExecuteCommand: rp initialized unconditionally

    alt et_enable_comments is true
        ExecuteCommand->>ExecuteCommand: has_erratum = any(job.event.type_ == EventType.ERRATUM for job in schedule_job_list)
        alt has_erratum is true
            ExecuteCommand->>ErrataTool: initialize_et_connection(ctx)
            ErrataTool-->>ExecuteCommand: et connection
        else has_erratum is false
            Note over ExecuteCommand: et remains None (no ErrataTool connection)
        end
    else et_enable_comments is false
        Note over ExecuteCommand: et remains None (comments disabled)
    end

    alt rog_enable_comments is true and rog_token present
        ExecuteCommand->>ExecuteCommand: has_rog = any(job.event.type_ == EventType.ROG for job in schedule_job_list)
        alt has_rog is true
            ExecuteCommand->>RoGTool: RoGTool(token=ctx.settings.rog_token)
            RoGTool-->>ExecuteCommand: rog client
        else has_rog is false
            Note over ExecuteCommand: rog remains None (no RoGTool connection)
        end
    else rog_enable_comments is false or rog_token missing
        Note over ExecuteCommand: rog remains None
    end

    ExecuteCommand-->>CLI: proceed to execute jobs using rp, et, rog
Loading

Sequence diagram for conditional ET/RoG initialization in report command

sequenceDiagram
    actor User
    participant CLI
    participant ReportCommand as cmd_report
    participant ReportPortal as ReportPortal
    participant Jira as Jira
    participant ErrataTool as ErrataTool
    participant RoGTool as RoGTool

    User->>CLI: run report
    CLI->>ReportCommand: cmd_report(ctx)

    alt rp_url is configured
        ReportCommand->>ReportPortal: initialize_rp_connection(ctx)
        ReportPortal-->>ReportCommand: rp connection
    else rp_url not configured
        Note over ReportCommand: rp is None
    end

    ReportCommand->>Jira: ctx.get_jira_connection().get_connection()
    Jira-->>ReportCommand: jira_connection

    alt et_enable_comments is true
        ReportCommand->>ReportCommand: has_erratum = any(job.event.type_ == EventType.ERRATUM for job in all_execute_jobs)
        alt has_erratum is true
            ReportCommand->>ErrataTool: initialize_et_connection(ctx)
            ErrataTool-->>ReportCommand: et connection
        else has_erratum is false
            Note over ReportCommand: et remains None (no ErrataTool connection)
        end
    else et_enable_comments is false
        Note over ReportCommand: et remains None
    end

    alt rog_enable_comments is true and rog_token present
        ReportCommand->>ReportCommand: has_rog = any(job.event.type_ == EventType.ROG for job in all_execute_jobs)
        alt has_rog is true
            ReportCommand->>RoGTool: RoGTool(token=ctx.settings.rog_token)
            RoGTool-->>ReportCommand: rog client
        else has_rog is false
            Note over ReportCommand: rog remains None
        end
    else rog_enable_comments is false or rog_token missing
        Note over ReportCommand: rog remains None
    end

    ReportCommand-->>CLI: generate reports using rp, jira_connection, et, rog
Loading

File-Level Changes

Change Details Files
Initialize Errata Tool and RoG connections in execute command only when corresponding events exist in the scheduled jobs.
  • Replace unconditional ET initialization (when comments enabled) with a prior scan of schedule_job_list for EventType.ERRATUM before calling initialize_et_connection
  • Replace unconditional RoGTool construction (when comments enabled and token present) with a prior scan of schedule_job_list for EventType.ROG before instantiating RoGTool
  • Default both et and rog to None when no relevant events are found, preserving existing downstream interface
newa/cli/commands/execute_cmd.py
Initialize Errata Tool and RoG connections in report command only when corresponding events exist in all_execute_jobs.
  • Replace unconditional ET initialization (when comments enabled) with a prior scan of all_execute_jobs for EventType.ERRATUM before calling initialize_et_connection
  • Replace unconditional RoGTool construction (when comments enabled and token present) with a prior scan of all_execute_jobs for EventType.ROG before instantiating RoGTool
  • Default both et and rog to None when no relevant events are present, consistent with execute command and jira_cmd defensive pattern
newa/cli/commands/report_cmd.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 left some high level feedback:

  • The new Errata Tool and RoG initialization logic in both execute_cmd.py and report_cmd.py is nearly identical; consider extracting a shared helper (e.g., get_optional_et(ctx, jobs) / get_optional_rog(ctx, jobs)) to avoid duplication and keep future changes in sync.
  • Since you now compute has_erratum and has_rog by scanning all jobs, it might be worth consolidating the two any(...) passes into a single loop over the job list (tracking both flags) if these job lists can be large or this path is performance-sensitive.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new Errata Tool and RoG initialization logic in both execute_cmd.py and report_cmd.py is nearly identical; consider extracting a shared helper (e.g., `get_optional_et(ctx, jobs)` / `get_optional_rog(ctx, jobs)`) to avoid duplication and keep future changes in sync.
- Since you now compute `has_erratum` and `has_rog` by scanning all jobs, it might be worth consolidating the two `any(...)` passes into a single loop over the job list (tracking both flags) if these job lists can be large or this path is performance-sensitive.

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 merged commit 43f0316 into main Feb 13, 2026
18 checks passed
@kkaarreell kkaarreell deleted the ks_init_conn_when_needed branch February 13, 2026 21:36
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