-
-
Notifications
You must be signed in to change notification settings - Fork 29
Add manage domains script #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe pull request introduces a new shell script Changes
Sequence DiagramsequenceDiagram
participant User
participant Script as manage_domains.sh
participant ListFile as list
participant InactiveFile as inactive
alt Adding Domain
User->>Script: add newdomain.com
Script->>ListFile: Check if domain exists
alt Domain not in list
Script->>ListFile: Add domain
Script->>ListFile: Sort entries preserving comments
else Domain already exists
Script-->>User: Show existing domain message
end
end
alt Moving Domain
User->>Script: move newdomain.com
Script->>ListFile: Check if domain exists
alt Domain in list
Script->>ListFile: Remove domain
Script->>InactiveFile: Add domain
Script->>InactiveFile: Sort entries preserving first 15 lines
else Domain not found
Script-->>User: Show not found message
end
end
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 3 changed files in this pull request and generated no comments.
Files not reviewed (2)
- manage_domains.sh: Language not supported
- tests/manage_domains_test.sh: Language not supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🧹 Nitpick comments (3)
manage_domains.sh (1)
29-36
: Enhance command-line argument validation.The current argument validation could be more robust by validating the command format and providing more helpful error messages.
+# Validate command format +valid_commands="add move" + if [ "$#" -ne 2 ]; then - echo "Usage: $0 {add|move} domain" + echo "Error: Incorrect number of arguments" + echo "Usage: $(basename "$0") {add|move} domain" + echo "Commands:" + echo " add Add a new domain to the active list" + echo " move Move a domain to the inactive list" exit 1 fi command=$1 domain=$2 + +if [[ ! " $valid_commands " =~ " $command " ]]; then + echo "Error: Invalid command '$command'" + echo "Valid commands are: $valid_commands" + exit 1 +fitests/manage_domains_test.sh (1)
38-40
: Implement safer file restoration.The current file restoration process could be improved to prevent potential data loss.
# Restore original files -mv "$test_list_file" "$list_file" -mv "$test_inactive_file" "$inactive_file" +if ! cmp -s "$test_list_file" "$list_file"; then + cp "$test_list_file" "$list_file" || { + echo "Error: Failed to restore $list_file" + exit 1 + } +fi +if ! cmp -s "$test_inactive_file" "$inactive_file"; then + cp "$test_inactive_file" "$inactive_file" || { + echo "Error: Failed to restore $inactive_file" + exit 1 + } +fiREADME.md (1)
35-51
: Enhance documentation with additional details.The documentation could be improved by:
- Adding examples of successful/error outputs
- Documenting the test script
- Explaining the comment preservation behavior
## Managing Domains -A shell script `manage_domains.sh` is provided to help manage the domains in the `list` and `inactive` files. The script ensures that the files remain sorted and comments are not affected. +A shell script `manage_domains.sh` is provided to help manage the domains in the `list` and `inactive` files. The script: +- Validates domain format +- Maintains file sorting +- Preserves comment headers +- Provides clear success/error messages ### Usage To add a new domain to the list file: ```sh ./manage_domains.sh add <domain> +# Success: Domain example.com added to list. +# Error: Invalid domain format: invalid..domainTo move an inactive domain to the inactive list:
./manage_domains.sh move <domain> +# Success: Domain example.com moved to inactive. +# Error: Domain example.com does not exist in list.
+### Testing
+
+A test scriptmanage_domains_test.sh
is provided to verify the functionality:
+sh +./tests/manage_domains_test.sh +
</blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: CodeRabbit UI** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between fe20514c404b6ce118c2e41a9057d47c8f028cf0 and c9907b0d37be419d1f50e4f0f85458693ee973c2. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `README.md` (1 hunks) * `manage_domains.sh` (1 hunks) * `tests/manage_domains_test.sh` (1 hunks) </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
/review |
PR Reviewer Guide 🔍(Review updated until commit 2e39a4a)Here are some key observations to aid the review process:
|
Persistent review updated to latest commit 0f85d3f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 3 changed files in this pull request and generated no comments.
Files not reviewed (2)
- manage_domains.sh: Language not supported
- tests/manage_domains_test.sh: Language not supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new shell script to manage domains via add and move commands, updates the README with usage guidelines, and adds tests for the domain management functionality.
- Added shell script (manage_domains.sh) for domain management
- Updated README with detailed instructions for adding and moving domains
- Introduced tests to validate domain management operations
Files not reviewed (2)
- manage_domains.sh: Language not supported
- tests/manage_domains_test.sh: Language not supported
0f85d3f
to
678151b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
tests/manage_domains_test.sh (3)
1-2
: Prefer portable shebang
Using/usr/bin/env bash
increases portability across different environments. The strict flags (set -euo pipefail
) are correctly used for robust error handling.-#!/bin/bash +#!/usr/bin/env bash
11-18
: Ensure source domain files exist or fail fast
Currently, copying from non‑existent source files will abort the test without a clear error. Consider adding a pre‑check to validate file paths and provide a helpful message.+if [ ! -f "$list_file" ] || [ ! -f "$inactive_file" ]; then + echo "ERROR: Source domain files not found at $list_file or $inactive_file" >&2 + exit 1 +fi cp "$list_file" "$test_list_file" cp "$inactive_file" "$test_inactive_file"
28-35
: Validate 'add' command behavior
The test correctly verifies that "newdomain.com" is added to the active list. You may also want to assert the exit status of theadd
command itself (e.g., ensure it returns 0 on success and non-zero on invalid input) to catch script failures early.echo -e "${YELLOW}Testing: Add domain${NC}" -"${SCRIPT_DIR}/../manage_domains.sh" add "newdomain.com" +if ! "${SCRIPT_DIR}/../manage_domains.sh" add "newdomain.com"; then + echo -e "${RED}Test add domain (exit status): FAILED${NC}" + failures=$((failures+1)) +fi if grep -q "^newdomain.com$" "$test_list_file"; then echo -e "${GREEN}Test add domain: PASSED${NC}"
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
README.md
(1 hunks)manage_domains.sh
(1 hunks)tests/manage_domains_test.sh
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- README.md
🚧 Files skipped from review as they are similar to previous changes (1)
- manage_domains.sh
🔇 Additional comments (4)
tests/manage_domains_test.sh (4)
4-9
: Isolate and clean up the test environment
Good use ofmktemp -d
to create an isolated directory andtrap
to ensure cleanup on exit, preventing pollution of the working directory.
20-26
: Export environment variables and define color codes
Correctly exportingLIST_FILE
andINACTIVE_FILE
for the script under test, and defining ANSI color codes for clear pass/fail output.
37-45
: Verify 'move' command functionality
The test correctly checks that moving a domain removes it from the active list and adds it to the inactive list.
59-67
: Summarize test outcomes and exit with appropriate status
The summary prints the failure count and exits with that code, which integrates cleanly with CI pipelines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new shell script, manage_domains.sh, to assist in managing domain lists by validating, sorting, and transitioning domains between active and inactive states.
- Added documentation for the new script in the README
- Provided usage examples for adding and moving domains
- Automated tests were added to validate domain management functionality
Files not reviewed (2)
- manage_domains.sh: Language not supported
- tests/manage_domains_test.sh: Language not supported
678151b
to
2e39a4a
Compare
/review |
Persistent review updated to latest commit 2e39a4a |
Summary by CodeRabbit
New Features
Documentation
Tests