Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

PeterDaveHello
Copy link
Owner

@PeterDaveHello PeterDaveHello commented Jan 4, 2025

Summary by CodeRabbit

  • New Features

    • Added a shell script to manage domains between active and inactive lists with validation and sorting
    • Enabled adding new domains and moving domains to inactive status through simple commands
    • Created automated tests to ensure domain management functionality and file integrity
  • Documentation

    • Updated README with a new "Managing Domains" section and usage instructions for the domain management script
  • Tests

    • Introduced a test script that verifies adding, moving, sorting, and comment preservation in domain lists

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jan 4, 2025
Copy link

coderabbitai bot commented Jan 4, 2025

📝 Walkthrough

Walkthrough

The pull request introduces a new shell script manage_domains.sh for managing domain entries between active and inactive lists. The script supports adding domains to the active list and moving domains to the inactive list, validating domain formats, preserving comments, and maintaining sorted order. A new "Managing Domains" section with usage instructions is added to the README.md. Additionally, a test script manage_domains_test.sh is provided to automate verification of the script’s functionality, including domain addition, moving, sorting, and comment preservation.

Changes

File Change Summary
README.md Added "Managing Domains" section with usage instructions for manage_domains.sh
manage_domains.sh New script implementing add_domain() and move_domain() functions for domain list management
tests/manage_domains_test.sh New test script automating tests for domain addition, moving, sorting, and comment preservation

Sequence Diagram

sequenceDiagram
    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
Loading

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 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 678151b and 2e39a4a.

📒 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 as they are similar to previous changes (3)
  • README.md
  • tests/manage_domains_test.sh
  • manage_domains.sh

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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

@PeterDaveHello PeterDaveHello requested a review from Copilot January 4, 2025 12:13
Copy link

@Copilot Copilot AI left a 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

@dosubot dosubot bot added documentation Improvements or additions to documentation enhancement New feature or request labels Jan 4, 2025
Copy link

@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: 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
+fi
tests/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
+    }
+fi
README.md (1)

35-51: Enhance documentation with additional details.

The documentation could be improved by:

  1. Adding examples of successful/error outputs
  2. Documenting the test script
  3. 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..domain

To 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 script manage_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 -->

@PeterDaveHello
Copy link
Owner Author

/review

Copy link

qodo-merge-pro-for-open-source bot commented Jan 15, 2025

PR Reviewer Guide 🔍

(Review updated until commit 2e39a4a)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Sorting Logic

The sorting logic for the inactive file is different from the active file. The inactive file preserves the first 15 lines and sorts the rest, while the active file preserves only comments. This inconsistency could lead to unexpected behavior.

(head -n 15 "$INACTIVE_FILE" && tail -n +16 "$INACTIVE_FILE" | sort) > "$INACTIVE_FILE.tmp" && mv "$INACTIVE_FILE.tmp" "$INACTIVE_FILE"
echo "Domain $domain moved to $INACTIVE_FILE."
Error Handling

The script doesn't check if the temporary files were created successfully before moving them. This could lead to data loss if the sort operation fails but the move still happens.

(grep '^#' "$LIST_FILE"; grep -v '^#' "$LIST_FILE" | sort) > "$LIST_FILE.tmp" && mv "$LIST_FILE.tmp" "$LIST_FILE"
echo "Domain $domain added to $LIST_FILE."
Test Logic

The test for "graceful handling of non-existent domain" has inverted logic. It passes when it should fail and vice versa, as indicated by the conditional structure.

if "${SCRIPT_DIR}/../manage_domains.sh" move "nonexistentdomain.com" 2>/dev/null; then
    run_test "graceful handling of non-existent domain" "$( ! grep -q "^nonexistentdomain.com$" "$test_inactive_file"; echo $?)"
else
    run_test "graceful handling of non-existent domain" 1
fi

Copy link

Persistent review updated to latest commit 0f85d3f

@PeterDaveHello PeterDaveHello requested a review from Copilot April 6, 2025 09:26
Copy link

@Copilot Copilot AI left a 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

@PeterDaveHello PeterDaveHello requested a review from Copilot April 19, 2025 17:12
Copy link

@Copilot Copilot AI left a 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

Copy link

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

📥 Commits

Reviewing files that changed from the base of the PR and between c9907b0 and 678151b.

📒 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 of mktemp -d to create an isolated directory and trap to ensure cleanup on exit, preventing pollution of the working directory.


20-26: Export environment variables and define color codes
Correctly exporting LIST_FILE and INACTIVE_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.

@PeterDaveHello PeterDaveHello requested a review from Copilot April 19, 2025 18:36
Copy link

@Copilot Copilot AI left a 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

@PeterDaveHello
Copy link
Owner Author

/review

Persistent review updated to latest commit 2e39a4a

@PeterDaveHello PeterDaveHello removed the documentation Improvements or additions to documentation label Apr 20, 2025
@PeterDaveHello PeterDaveHello self-assigned this Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Review effort 2/5 size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant