Skip to content

feat: add url deduping - #7

Merged
recepgunes1 merged 1 commit into
mainfrom
feat/url_dedupe
Jul 25, 2025
Merged

feat: add url deduping#7
recepgunes1 merged 1 commit into
mainfrom
feat/url_dedupe

Conversation

@recepgunes1

@recepgunes1 recepgunes1 commented Jul 15, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Introduced a command-line tool feature to deduplicate URLs, accepting input via arguments or standard input and outputting unique URLs.
  • Documentation
    • Added a "Deduping Urls" section with usage examples to the README.
  • Chores
    • Removed the Bash test script previously used for validating URL functionalities.
  • Style
    • Cleaned up minor formatting in the command-line encoding feature (no impact on functionality).

@coderabbitai

coderabbitai Bot commented Jul 15, 2025

Copy link
Copy Markdown

Walkthrough

A new CLI command, dedupe, was added to deduplicate URLs based on a normalized signature. The README was updated with usage examples for this feature. An extraneous blank line was removed from the encode command implementation. Additionally, a comprehensive Bash test script for the CLI tool was deleted.

Changes

File(s) Change Summary
README.md Added "Deduping Urls" section with usage examples for the new dedupe command.
internal/cli/dedupe.go Introduced new dedupe CLI command with URL normalization and deduplication logic.
internal/cli/encode.go Removed an unnecessary blank line in the encodeCmd implementation.
test.sh Deleted Bash script containing comprehensive CLI tests for URL parsing, modification, and encoding.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI (dedupeCmd)
    participant URL Normalizer
    participant Output

    User->>CLI (dedupeCmd): Invoke with URLs (args or stdin)
    CLI (dedupeCmd)->>URL Normalizer: Normalize and generate signature for each URL
    URL Normalizer-->>CLI (dedupeCmd): Return normalized signature
    CLI (dedupeCmd)->>CLI (dedupeCmd): Track and filter duplicates
    CLI (dedupeCmd)->>Output: Print deduplicated URLs
Loading

Poem

🐇
A hop, a skip, a dedupe leap,
URLs in piles, no need to keep
The twins and triplets—out they go!
With one clean hop, the list is so
Much lighter, brighter, neat and sweet—
The bunny’s work is now complete!

✨ Finishing Touches
  • 📝 Docstrings were successfully generated. (🔄 Check again to generate docstrings again)

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.

@recepgunes1 recepgunes1 linked an issue Jul 15, 2025 that may be closed by this pull request

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (4)
internal/cli/dedupe.go (4)

52-53: Remove unreachable return statement.

The return statement after os.Exit(1) is unreachable code.

 fmt.Println("Error: No input provided")
 os.Exit(1)
-return

80-95: Handle edge cases in path normalization.

The path normalization logic may not handle all edge cases correctly, particularly with empty paths or paths with only slashes.

Consider improving the path normalization logic:

-pathParts := strings.Split(strings.Trim(u.Path, "/"), "/")
-var normalizedParts []string
-
-for _, part := range pathParts {
-  if part == "" {
-    continue
-  }
-
-  if isNumeric(part) || strings.Contains(part, ".") {
-    normalizedParts = append(normalizedParts, "{param}")
-  } else {
-    normalizedParts = append(normalizedParts, part)
-  }
-}
-
-normalizedPath := "/" + strings.Join(normalizedParts, "/")
+var normalizedPath string
+if u.Path == "" || u.Path == "/" {
+  normalizedPath = "/"
+} else {
+  pathParts := strings.Split(strings.Trim(u.Path, "/"), "/")
+  var normalizedParts []string
+  
+  for _, part := range pathParts {
+    if part == "" {
+      continue
+    }
+    
+    if isNumeric(part) || strings.Contains(part, ".") {
+      normalizedParts = append(normalizedParts, "{param}")
+    } else {
+      normalizedParts = append(normalizedParts, part)
+    }
+  }
+  
+  normalizedPath = "/" + strings.Join(normalizedParts, "/")
+}

111-114: Improve signature construction for better readability.

The signature construction could be made more readable and maintainable.

-signature := base + normalizedPath + "|"
-for _, key := range paramKeys {
-  signature += key + ","
-}
+var sigBuilder strings.Builder
+sigBuilder.WriteString(base)
+sigBuilder.WriteString(normalizedPath)
+sigBuilder.WriteString("|")
+sigBuilder.WriteString(strings.Join(paramKeys, ","))
+signature := sigBuilder.String()

127-134: Consider using strconv.Atoi for numeric validation.

The manual character-by-character check could be replaced with Go's standard library function.

+import (
+  "strconv"
+  // ... other imports
+)

 func isNumeric(s string) bool {
-  for _, char := range s {
-    if char < '0' || char > '9' {
-      return false
-    }
-  }
-  return len(s) > 0
+  _, err := strconv.Atoi(s)
+  return err == nil
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 441a9ad and bf3e228.

📒 Files selected for processing (4)
  • README.md (1 hunks)
  • internal/cli/dedupe.go (1 hunks)
  • internal/cli/encode.go (0 hunks)
  • test.sh (0 hunks)
💤 Files with no reviewable changes (2)
  • internal/cli/encode.go
  • test.sh
🧰 Additional context used
🧬 Code Graph Analysis (1)
internal/cli/dedupe.go (1)
internal/utils/url.go (1)
  • CreateURL (7-16)
🔇 Additional comments (1)
README.md (1)

80-86: Documentation looks good and matches implementation.

The new documentation section clearly demonstrates the dedupe command usage with both direct arguments and piped input examples.

Comment thread internal/cli/dedupe.go
if value == "" {
continue
}
url := utils.CreateURL(value)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for invalid URLs.

The utils.CreateURL() function panics on invalid URLs, but there's no error handling in the dedupe command. This could cause the entire program to crash on invalid input.

Based on the relevant code snippet, utils.CreateURL() panics for invalid URLs. Consider wrapping these calls with error handling:

-url := utils.CreateURL(value)
+url, err := url.Parse(value)
+if err != nil {
+  fmt.Fprintf(os.Stderr, "Warning: Skipping invalid URL: %s (%v)\n", value, err)
+  continue
+}
+if url.Scheme == "" && url.Host == "" {
+  fmt.Fprintf(os.Stderr, "Warning: Skipping invalid URL: %s\n", value)
+  continue
+}

Or alternatively, modify utils.CreateURL() to return an error instead of panicking.

Also applies to: 41-41

🤖 Prompt for AI Agents
In internal/cli/dedupe.go at lines 27 and 41, the calls to utils.CreateURL() can
panic on invalid URLs because there is no error handling. To fix this, wrap
these calls in a way that recovers from panics or check the validity of the URL
before calling CreateURL. Alternatively, modify utils.CreateURL() to return an
error instead of panicking and update the calling code to handle that error
gracefully, preventing the program from crashing on invalid input.

Comment thread internal/cli/dedupe.go
Comment on lines +103 to +109
for i := 0; i < len(paramKeys); i++ {
for j := i + 1; j < len(paramKeys); j++ {
if paramKeys[i] > paramKeys[j] {
paramKeys[i], paramKeys[j] = paramKeys[j], paramKeys[i]
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Replace manual sorting with Go's sort package.

The manual bubble sort implementation is inefficient and unnecessary when Go's sort package is available.

+import (
+  "sort"
+  // ... other imports
+)

-for i := 0; i < len(paramKeys); i++ {
-  for j := i + 1; j < len(paramKeys); j++ {
-    if paramKeys[i] > paramKeys[j] {
-      paramKeys[i], paramKeys[j] = paramKeys[j], paramKeys[i]
-    }
-  }
-}
+sort.Strings(paramKeys)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for i := 0; i < len(paramKeys); i++ {
for j := i + 1; j < len(paramKeys); j++ {
if paramKeys[i] > paramKeys[j] {
paramKeys[i], paramKeys[j] = paramKeys[j], paramKeys[i]
}
}
}
// --- at the top of internal/cli/dedupe.go, merge into your existing import block:
import (
"sort"
// ... other existing imports
)
// ... later in the same function, replace the manual loops:
- for i := 0; i < len(paramKeys); i++ {
- for j := i + 1; j < len(paramKeys); j++ {
- if paramKeys[i] > paramKeys[j] {
- paramKeys[i], paramKeys[j] = paramKeys[j], paramKeys[i]
- }
- }
- }
+ sort.Strings(paramKeys)
🤖 Prompt for AI Agents
In internal/cli/dedupe.go around lines 103 to 109, replace the manual bubble
sort loop sorting paramKeys with a call to Go's built-in sort package. Import
"sort" if not already imported, and use sort.Strings(paramKeys) to efficiently
sort the slice instead of the nested loops.

Comment thread internal/cli/dedupe.go
Comment on lines +22 to +48
if len(args) > 0 {
for _, value := range args {
if value == "" {
continue
}
url := utils.CreateURL(value)
urlStr := url.String()
if !seen[urlStr] {
seen[urlStr] = true
urls = append(urls, url)
}
}
} else {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
value := scanner.Text()
if value == "" {
continue
}
url := utils.CreateURL(value)
urlStr := url.String()
if !seen[urlStr] {
seen[urlStr] = true
urls = append(urls, url)
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove redundant deduplication logic in the command handler.

The command handler implements its own deduplication using url.String() as the key, but then calls dedupeUrls() which performs a different, more sophisticated signature-based deduplication. This creates confusion and redundancy.

Remove the initial deduplication logic and let dedupeUrls() handle all deduplication:

 var urls []*url.URL
-seen := make(map[string]bool)

 if len(args) > 0 {
   for _, value := range args {
     if value == "" {
       continue
     }
     url := utils.CreateURL(value)
-    urlStr := url.String()
-    if !seen[urlStr] {
-      seen[urlStr] = true
-      urls = append(urls, url)
-    }
+    urls = append(urls, url)
   }
 } else {
   scanner := bufio.NewScanner(os.Stdin)
   for scanner.Scan() {
     value := scanner.Text()
     if value == "" {
       continue
     }
     url := utils.CreateURL(value)
-    urlStr := url.String()
-    if !seen[urlStr] {
-      seen[urlStr] = true
-      urls = append(urls, url)
-    }
+    urls = append(urls, url)
   }
 }
🤖 Prompt for AI Agents
In internal/cli/dedupe.go between lines 22 and 48, remove the initial
deduplication logic that uses a map with url.String() as the key inside the
command handler. Instead, keep the code that collects all URLs from args or
stdin without filtering duplicates, and rely solely on the dedupeUrls() function
later to perform the deduplication based on its signature method. This
eliminates redundant and conflicting deduplication steps.

coderabbitai Bot added a commit that referenced this pull request Jul 15, 2025
Docstrings generation was requested by @omarkurt.

* #7 (comment)

The following files were modified:

* `internal/cli/dedupe.go`
@coderabbitai

coderabbitai Bot commented Jul 15, 2025

Copy link
Copy Markdown

Note

Generated docstrings for this pull request at #8

@recepgunes1 recepgunes1 added the enhancement New feature or request label Jul 15, 2025

@omarkurt omarkurt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@recepgunes1
recepgunes1 merged commit 30745b1 into main Jul 25, 2025
4 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Feb 13, 2026
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.

add url dedupe support

2 participants