Skip to content

Add missing run-* and send-* to all command sections#504

Merged
creativeprojects merged 4 commits intomasterfrom
send-and-command
May 18, 2025
Merged

Add missing run-* and send-* to all command sections#504
creativeprojects merged 4 commits intomasterfrom
send-and-command

Conversation

@creativeprojects
Copy link
Copy Markdown
Owner

@creativeprojects creativeprojects commented May 18, 2025

Some restic commands where missing the ability to run commands (before and after) or send monitoring data (before and after)

Now the run-* and send-* can be used on all restic commands

Fixes #492
Fixes #496

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2025

Walkthrough

The changes refactor configuration structures for command sections, centralising monitoring and shell command hooks into a unified GenericSection. New types for monitoring HTTP requests are introduced in a separate file. Tests are updated to reflect the new structure, and additional tests ensure all commands support run-before and send-before hooks. Version numbers and documentation aliases are incremented or updated.

Changes

File(s) Change Summary
config/profile.go Refactored configuration structs: unified and renamed types, centralised monitoring and shell command hooks into GenericSection, updated field types and method receivers, and removed duplicated monitoring section types.
config/send.go Introduced new types and methods for HTTP monitoring sections (SendMonitoringSections, SendMonitoringSection, SendMonitoringHeader), including configuration, path normalisation, and grouping logic.
config/profile_test.go Updated tests for new config structure, added tests to verify run-before and send-before support across all commands.
monitor/hook/sender_test.go Updated test configuration to use new section structure, no change to test logic.
wrapper_test.go Updated test to use new section struct types for Check, Forget, and Prune.
Makefile Changed Hugo version tag from 0.145.0 to v0.145.0 for binary fetching.
docs/version.toml, main.go, sonar-project.properties, go.mod Updated version strings: docs to v0.31.0, main.go to 0.31.0-dev, SonarQube to 0.31.0, Go module to 1.24.3.
contrib/templates/reference.gomd Added aliases field with /configuration/reference to front matter.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ConfigLoader
    participant Profile
    participant GenericSectionWithSchedule
    participant GenericSection
    participant SendMonitoringSections

    User->>ConfigLoader: Load profile config
    ConfigLoader->>Profile: Parse sections (Check, Prune, Forget, etc.)
    Profile->>GenericSectionWithSchedule: Access command section
    GenericSectionWithSchedule->>GenericSection: Access hooks (run/send)
    GenericSection->>SendMonitoringSections: Access monitoring hooks
    Note right of SendMonitoringSections: Monitoring HTTP requests grouped (before/after/finally)
Loading

Assessment against linked issues

Objective Addressed Explanation
Support run-before on check operation in config file version 2 (#492)

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 9b79782 and 0a77fe4.

📒 Files selected for processing (2)
  • config/profile.go (6 hunks)
  • config/send.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • config/send.go
  • config/profile.go
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build
  • GitHub Check: Build and test (1.24, windows-latest)
  • GitHub Check: Analyze (go)
  • GitHub Check: Build and test (1.24, ubuntu-latest)
  • GitHub Check: Build and test (1.24, macos-latest)
✨ Finishing Touches
  • 📝 Generate Docstrings

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 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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
config/send.go (2)

11-17: Minor efficiency / clarity nit: avoid copying slices in nested loops

range s.getAllSendMonitoringSections() returns a copy of each slice header. While modifying elements via indexing is safe, the double dereference is a little opaque. Using a pointer to the slice (or moving the inner loop into a helper) would improve readability:

for _, sections := range s.getAllSendMonitoringSections() {
    for i := range sections {
        sections[i].BodyTemplate = fixPath(
            sections[i].BodyTemplate, expandEnv, expandUserHome, absolutePrefix(rootPath))
    }
}

Functionally identical, but clearer and avoids the extra value variable.


42-44: HTTP-header regex is overly strict

^\w([\w-]+)\w$ rejects many valid HTTP header names (e.g. single-letter names, names starting with “X-”, or containing _).
Consider liberalising to the RFC 9110 token grammar or, at minimum, allowing a single character and the initial “X-” pattern:

- Name  string            `mapstructure:"name" regex:"^\\w([\\w-]+)\\w$" ...`
+ Name  string            `mapstructure:"name" regex:"^[!#$%&'*+\\-.^_`|~0-9A-Za-z]+$" ...`

This provides better standards compliance and avoids false negatives.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 8fd3ddb and 9b79782.

📒 Files selected for processing (11)
  • Makefile (1 hunks)
  • config/profile.go (6 hunks)
  • config/profile_test.go (2 hunks)
  • config/send.go (1 hunks)
  • contrib/templates/reference.gomd (1 hunks)
  • docs/version.toml (1 hunks)
  • go.mod (1 hunks)
  • main.go (1 hunks)
  • monitor/hook/sender_test.go (2 hunks)
  • sonar-project.properties (1 hunks)
  • wrapper_test.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
config/profile_test.go (1)
restic/commands.go (1)
  • CommandNames (515-517)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Build and test (1.24, windows-latest)
  • GitHub Check: Build and test (1.24, macos-latest)
  • GitHub Check: Build and test (1.24, ubuntu-latest)
  • GitHub Check: build
  • GitHub Check: Analyze (go)
🔇 Additional comments (12)
go.mod (1)

3-3: Approve Go version bump
Bumping from Go 1.24.2 to 1.24.3 aligns with the project’s version strategy and matches related version updates in other files.

Makefile (1)

96-96: Approve Hugo tag format update
Adding the leading “v” in --tag v0.145.0 ensures the eget target fetches the correctly tagged Hugo release and maintains consistency with other tools.

contrib/templates/reference.gomd (1)

7-8: Approve new alias in front matter
Introducing the /configuration/reference alias supports seamless redirects in documentation and aligns with the updated configuration reference path.

docs/version.toml (1)

2-2: Approve docs version bump
Updating the version to “v0.31.0” keeps the documentation in sync with the new release.

sonar-project.properties (1)

4-4: Approve Sonar project version bump
Bumping sonar.projectVersion to 0.31.0 aligns the SonarQube configuration with the codebase’s release version for accurate analysis.

main.go (1)

29-29: Version updated appropriately for new feature release

The version bump from 0.30.0-dev to 0.31.0-dev properly reflects the feature enhancement of adding run-* and send-* hooks to all command sections.

monitor/hook/sender_test.go (2)

255-266: Test updated to reflect refactored configuration structure

The test configuration has been properly updated to use the new nested hierarchy where GenericSectionWithSchedule contains a GenericSection with embedded SendMonitoringSections. This reflects the centralisation of monitoring sections in the codebase.


291-305: Test updated to match refactored configuration hierarchy

Similar to the previous test, this test case has been updated to use the new configuration structure which provides a more unified approach to handling monitoring sections across different command types.

wrapper_test.go (1)

1027-1031: Test updated to use refactored configuration types

The test has been properly updated to use GenericSectionWithSchedule{} instead of the previous SectionWithScheduleAndMonitoring{} type, aligning with the new unified structure for command sections. This supports the goal of providing consistent run-* and send-* hooks across all commands.

config/profile_test.go (3)

1396-1398: Test updated to mark 'init' command as monitored

The "init" command is now correctly marked as monitored, and a test case for a non-monitored "other" command has been added. This ensures proper testing of the monitoring section functionality across different command types.


1609-1631: Excellent new test ensuring all commands support run-before hooks

This new test comprehensively verifies that all commands supported by restic can have run-before shell commands configured. It systematically tests each command returned by restic.CommandNames(), ensuring complete coverage of the feature.


1633-1655: Comprehensive test for send-before hooks on all commands

This new test verifies that all restic commands properly support send-before monitoring sections. The test is thorough, checking each command individually and ensuring that the monitoring sections are correctly parsed and accessible.

Comment thread config/profile.go
Comment thread config/profile.go
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.32%. Comparing base (8fd3ddb) to head (0a77fe4).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #504      +/-   ##
==========================================
+ Coverage   79.24%   79.32%   +0.08%     
==========================================
  Files         133      134       +1     
  Lines       13219    13221       +2     
==========================================
+ Hits        10475    10487      +12     
+ Misses       2326     2316      -10     
  Partials      418      418              
Flag Coverage Δ
unittests 79.32% <100.00%> (+0.08%) ⬆️

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.

@sonarqubecloud
Copy link
Copy Markdown

@creativeprojects creativeprojects added the enhancement New feature or request label May 18, 2025
@creativeprojects creativeprojects added this to the v0.31.0 milestone May 18, 2025
@creativeprojects creativeprojects merged commit f7566ac into master May 18, 2025
12 checks passed
@creativeprojects creativeprojects deleted the send-and-command branch May 18, 2025 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

run: does not work for check Config file version 2 does not support run-before on check operation

1 participant