Skip to content

Conversation

@zumm
Copy link
Contributor

@zumm zumm commented Jul 30, 2025

Resolves #460

@coderabbitai
Copy link

coderabbitai bot commented Jul 30, 2025

Walkthrough

The Sender.Send method and related functions now accept an explicit environment parameter, allowing environment variable resolution to be controlled or mocked. All internal calls and tests have been updated to pass this environment parameter. A new test verifies that custom environment variables are used for URL and body template resolution, rather than the process environment.

Changes

Cohort / File(s) Change Summary
Sender Environment Handling
monitor/hook/sender.go
Modified Sender.Send, resolveURL, and resolveBody to accept an explicit *util.Environment parameter for environment variable resolution. Default behaviour falls back to OS environment if none is provided.
Test Adjustments and Additions
monitor/hook/sender_test.go
Updated all Send calls to pass the environment parameter. Added TestCustomEnv to verify custom environment variable usage. Added imports for constants and util.
Wrapper Integration
wrapper.go
Updated resticWrapper.sendMonitoring to pass profile environment to Sender.Send.

Sequence Diagram(s)

sequenceDiagram
    participant Wrapper
    participant Sender
    participant UtilEnv

    Wrapper->>UtilEnv: GetEnvironment(true)
    Wrapper->>Sender: Send(cfg, ctx, env)
    Sender->>UtilEnv: env.Get(var) (for URL/body template resolution)
    Sender->>Sender: resolveURL/resolveBody(..., env)
    Sender-->>Wrapper: (result)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Assessment against linked issues

Objective Addressed Explanation
Allow use of environment variables from env-file in send-before/send-after URLs and templates (#460)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7e87a1 and 578c526.

📒 Files selected for processing (3)
  • monitor/hook/sender.go (6 hunks)
  • monitor/hook/sender_test.go (14 hunks)
  • wrapper.go (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
monitor/hook/sender_test.go (1)

Learnt from: creativeprojects
PR: #425
File: schedule/handler_windows.go:97-118
Timestamp: 2025-02-04T14:38:07.701Z
Learning: The shell.SplitArguments function in the resticprofile project returns only []string and does not return any error.

monitor/hook/sender.go (1)

Learnt from: creativeprojects
PR: #425
File: schedule/handler_windows.go:97-118
Timestamp: 2025-02-04T14:38:07.701Z
Learning: The shell.SplitArguments function in the resticprofile project returns only []string and does not return any error.

🔇 Additional comments (9)
wrapper.go (1)

702-702: LGTM! This change directly addresses the PR objective.

The modification correctly passes the profile's environment variables to the Send method, ensuring that env-file variables are properly resolved in HTTP webhook URLs and bodies.

monitor/hook/sender.go (5)

23-23: LGTM! Proper import added for util package.


75-82: Excellent implementation with backward compatibility.

The method signature change adds the explicit environment parameter whilst maintaining backward compatibility by defaulting to OS environment when nil is passed. This directly addresses the PR objective of enabling profile env-file variables in webhook templates.


84-85: Correct propagation of environment parameter.

The environment parameter is properly passed to both resolveURL and resolveBody functions, ensuring consistent variable resolution throughout the webhook processing.

Also applies to: 103-103


212-212: Function signatures correctly updated.

Both resolveBody and resolveURL functions now accept the environment parameter, maintaining consistency with the overall design change.

Also applies to: 242-242


237-237: Key change that resolves the issue.

Replacing os.Getenv(s) with env.Get(s) is the core fix that enables environment variables from profile env-files to be properly resolved in webhook templates, directly addressing issue #460.

Also applies to: 267-267

monitor/hook/sender_test.go (3)

19-20: LGTM! Required imports added.


99-99: Correct adaptation to new method signature.

All existing tests have been updated to pass nil for the new environment parameter, preserving their original behaviour whilst adapting to the new API.

Also applies to: 118-118, 137-137, 155-155, 163-163, 183-183, 200-200, 214-214, 234-234, 273-273, 324-324, 363-363, 397-397


423-451: Excellent test coverage for the new functionality.

The TestCustomEnv test comprehensively validates the core feature:

  • Creates a controlled environment with custom variables
  • Verifies that OS environment variables are ignored when custom environment is provided
  • Tests both URL and body variable substitution
  • Uses proper test isolation with t.Setenv

This test ensures that the fix for issue #460 works as expected.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Jul 30, 2025

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.38%. Comparing base (c7e87a1) to head (578c526).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
wrapper.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #544      +/-   ##
==========================================
+ Coverage   79.36%   79.38%   +0.02%     
==========================================
  Files         136      136              
  Lines       13334    13337       +3     
==========================================
+ Hits        10582    10587       +5     
+ Misses       2333     2331       -2     
  Partials      419      419              
Flag Coverage Δ
unittests 79.38% <91.67%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@creativeprojects
Copy link
Owner

Works fine! thanks for the investigation, and thanks for the fix 👍🏻

@creativeprojects creativeprojects added this to the v0.32.0 milestone Aug 4, 2025
@creativeprojects creativeprojects merged commit f9039fa into creativeprojects:master Aug 4, 2025
9 checks passed
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.

Use env variable in send-before url

2 participants