Skip to content

Add optional 'EmailFrom' configuration to NGAS Utils#107

Open
szampier wants to merge 1 commit intoICRAR:masterfrom
szampier:add-email-from-configuration
Open

Add optional 'EmailFrom' configuration to NGAS Utils#107
szampier wants to merge 1 commit intoICRAR:masterfrom
szampier:add-email-from-configuration

Conversation

@szampier
Copy link
Copy Markdown
Contributor

@szampier szampier commented Apr 28, 2026

This backward-compatible change affects only the NGAS utilities (likely used only at ESO). It introduces a new optional parameter in the ~/.ngas configuration file to address an issue with email notifications sent by the xsync tool.

Summary by Sourcery

Enhancements:

  • Introduce an optional EmailFrom parameter in the NGAS configuration to override the default sender address for notification emails.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 28, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds an optional EmailFrom configuration parameter for NGAS utilities and updates xsync email sending logic to use it while preserving the existing default behavior.

Sequence diagram for updated send_email EmailFrom resolution

sequenceDiagram
    actor User
    participant Xsync
    participant NgasUtilsLib
    participant NgasResourceFile
    participant SmtpServer

    User->>Xsync: Trigger xsync operation
    Xsync->>NgasUtilsLib: send_email(subject, to, message)
    NgasUtilsLib->>NgasResourceFile: get_parameter_ngas_resource_file(SmtpHost)
    NgasResourceFile-->>NgasUtilsLib: smtp_host or empty
    alt smtp_host is empty
        NgasUtilsLib-->>Xsync: Print error No SMTP host defined in RC file
    else smtp_host is defined
        NgasUtilsLib->>NgasResourceFile: get_parameter_ngas_resource_file(EmailFrom)
        NgasResourceFile-->>NgasUtilsLib: email_from or empty
        alt EmailFrom is defined
            NgasUtilsLib->>NgasUtilsLib: from_field = email_from
        else EmailFrom is not defined
            NgasUtilsLib->>NgasUtilsLib: from_field = getpass_user@host
        end
        NgasUtilsLib->>SmtpServer: Connect and send email with from_field
        SmtpServer-->>User: Deliver notification email
    end
Loading

Flow diagram for send_email with optional EmailFrom override

flowchart TD
    A[send_email called] --> B[Read SmtpHost from NGAS RC file]
    B --> C{SmtpHost defined?}
    C -- No --> D[Print error No SMTP host defined in RC file]
    D --> E[Return]
    C -- Yes --> F[Read EmailFrom from NGAS RC file]
    F --> G{EmailFrom defined?}
    G -- Yes --> H[Set from_field = EmailFrom]
    G -- No --> I[Set from_field = getpass_user@host]
    H --> J[Split recipient list and send via SMTP]
    I --> J[Split recipient list and send via SMTP]
    J --> K[End]
Loading

File-Level Changes

Change Details Files
Introduce configurable email sender address with backward-compatible fallback.
  • Add new NGAS_RC_PAR_EMAIL_FROM constant for the EmailFrom configuration key in the NGAS resource file.
  • Update send_email() to read the EmailFrom value from the NGAS configuration via get_parameter_ngas_resource_file.
  • Fallback to the previous from_field value based on the current user and host when EmailFrom is not configured.
  • Keep the rest of the email sending logic (SMTP resolution, recipient parsing, headers) unchanged.
src/ngamsUtils/ngamsUtils/ngasUtilsLib.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
Copy Markdown

@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:

  • When reading NGAS_RC_PAR_EMAIL_FROM, consider normalizing the value (e.g., strip() and verifying it is non-empty and looks like an email address) before using it, so that misconfigured or whitespace-only values don’t silently fall back or produce an invalid From header.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When reading `NGAS_RC_PAR_EMAIL_FROM`, consider normalizing the value (e.g., `strip()` and verifying it is non-empty and looks like an email address) before using it, so that misconfigured or whitespace-only values don’t silently fall back or produce an invalid `From` header.

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.

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