Skip to content

Conversation

vihar
Copy link
Contributor

@vihar vihar commented Sep 10, 2025

Summary

  • add formatURLForDisplay helper to strip protocol and trailing slash from URLs

Testing

  • pnpm --filter=@plane/utils check:lint
  • pnpm --filter=@plane/utils check:types (fails: Cannot find module '@plane/types')
  • pnpm --filter=@plane/utils check:format
  • pnpm --filter=@plane/utils test (no tests found)

https://chatgpt.com/codex/tasks/task_e_68c1e070b158832a8f20c8484496c613

Summary by CodeRabbit

  • New Features
    • Introduced a utility to format URLs for display, producing cleaner, readable hosts and gracefully handling invalid inputs.
  • Documentation
    • Expanded guidance and examples for top-level domain extraction to clarify behavior and usage.

@Copilot Copilot AI review requested due to automatic review settings September 10, 2025 20:38
Copy link
Contributor

coderabbitai bot commented Sep 10, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Introduces a new exported helper formatURLForDisplay in packages/utils/src/url.ts to present URLs without protocol, using URL.host when valid and extractHostname as fallback; returns empty string for falsy input. Also expands JSDoc for extractTLD; no functional changes to other utilities.

Changes

Cohort / File(s) Summary
URL utilities update
packages/utils/src/url.ts
Added formatURLForDisplay(url: string): string with protocol stripping and fallback to extractHostname; returns empty string for falsy inputs. Enhanced JSDoc for extractTLD; no logic changes to existing functions.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant URLUtils as url.ts

  Caller->>URLUtils: formatURLForDisplay(url)
  alt url is falsy
    URLUtils-->>Caller: ""
  else url is valid URL
    URLUtils->>URL: new URL(url)
    URLUtils-->>Caller: parsed.host
  else url invalid (throws)
    URLUtils->>URLUtils: extractHostname(url)
    URLUtils-->>Caller: hostname
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • prateekshourya29
  • sriramveeraghanta

Poem

A rabbit nibbles code by night,
Trims the schemes, keeps hosts in sight.
If URLs wobble, fear no plight—
Hostnames hop in, tidy and bright.
Docs now clearer; all feels right.
Thump-thump! Another concise byte. 🐇✨

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The current description does not follow the repository’s required template: it uses a “## Summary” heading instead of the “### Description” section, omits the Type of Change checkboxes, lacks a Screenshots and Media section, does not clearly separate Test Scenarios from generic testing commands, and has no References section. Please revise the PR description to match the provided template by adding the “### Description” section with detailed changes, including the Type of Change checklist, a Screenshots and Media section if applicable, properly formatted Test Scenarios detailing expected results, and a References section linking related issues.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title Check ✅ Passed The title clearly and succinctly describes the primary change of adding a URL display formatter in the utils package, aligning with conventional commit style and avoiding extraneous details, making it easy to understand the pull request’s intent.
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/add-formaturlfordisplay-function

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@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 adds a new utility function formatURLForDisplay that creates a clean, user-friendly representation of URLs by stripping the protocol and trailing slashes.

  • Adds formatURLForDisplay function that returns the host portion of valid URLs or falls back to hostname extraction for invalid URLs
  • Uses the existing extractHostname helper as a fallback when URL parsing fails
  • Includes comprehensive JSDoc documentation explaining the function's behavior and purpose

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +101 to +103
* Returns a readable representation of a URL by stripping the protocol
* and any trailing slash. For valid URLs, only the host is returned.
* Invalid URLs are sanitized by removing the protocol and trailing slash.
Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

The documentation mentions 'stripping trailing slash' but the implementation doesn't actually handle trailing slashes. The new URL(url).host property and extractHostname function don't remove trailing slashes from the host portion. Consider updating the documentation to accurately reflect what the function does, or implement trailing slash removal if that's the intended behavior.

Copilot uses AI. Check for mistakes.

* Invalid URLs are sanitized by removing the protocol and trailing slash.
*
* @param url - The URL string to format
* @returns The formatted domain for display
Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

The return description says 'formatted domain' but the function returns the host (which includes port numbers if present). Consider changing this to 'The formatted host for display' to be more accurate, since new URL(url).host includes both hostname and port.

Suggested change
* @returns The formatted domain for display
* @returns The formatted host for display

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (1)
packages/utils/src/url.ts (1)

100-116: Confirm intent: function currently drops path/query; PR description says only strip protocol and trailing slash

If the goal is to keep the path (minus a trailing slash) and just remove the scheme, this implementation is too aggressive (it returns only the host). Suggest updating the function to preserve pathname for display, trim input, and safely handle non-URL strings (including credentials) in the fallback.

-export function formatURLForDisplay(url: string): string {
-  if (!url) return "";
-
-  try {
-    return new URL(url).host;
-  } catch (_error) {
-    return extractHostname(url);
-  }
-}
+export function formatURLForDisplay(url: string): string {
+  if (!url) return "";
+  const input = url.trim();
+  if (!input) return "";
+
+  try {
+    const u = new URL(input);
+    // Keep email address for mailto: links; otherwise show host plus pathname (no trailing slash).
+    if (u.protocol === MAILTO_PROTOCOL) return u.pathname;
+    const path = u.pathname === "/" ? "" : u.pathname.replace(/\/+$/, "");
+    return u.host + path;
+  } catch {
+    // Fallback for strings without a valid URL object: remove protocol, strip credentials, and trailing slash.
+    let s = input.replace(PROTOCOL_REGEX, "");
+    const at = s.indexOf("@");
+    if (at !== -1) s = s.substring(at + 1);
+    return s.replace(/\/+$/, "");
+  }
+}

Quick test cases to confirm expected behavior:

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f7bfdd and 4283f43.

📒 Files selected for processing (1)
  • packages/utils/src/url.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build and lint web apps
  • GitHub Check: Analyze (javascript)

@vihar vihar changed the title feat(utils): add URL display formatter [WEB-4881] feat(utils): add URL display formatter Sep 10, 2025
Copy link

makeplane bot commented Sep 10, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants