Skip to content

Display name improvements #259

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

Merged
merged 5 commits into from
Apr 3, 2025
Merged

Conversation

brendan-kellam
Copy link
Contributor

@brendan-kellam brendan-kellam commented Apr 3, 2025

This PR does the following:

  • Adds an optional displayName field to the Repos table. This field differs to name in that it does not include the hostUrl as a prefix, and thus is shorter & easier to read. The displayName is also passed along to zoekt via zoekt.display-name. This field replaces needing to create a display name client side.
  • Altered the behaviour in RepoManager::syncGitRepository to always "upsert" the repo's metadata.gitConfig regardless of clone or fetch (previously it only happened on fetch). This makes it s.t., the data in the database (metadata.gitConfig) is eventually consistent with the git config on the repo. This is essential for when we add new fields (like zoekt.display-name in this case).

Summary by CodeRabbit

  • Bug Fixes

    • Resolved formatting issues for repository names (notably for Gerrit), resulting in clearer and more consistent display in the interface.
  • New Features

    • Standardized repository naming across the platform, enabling full names to be displayed reliably in listings and carousels with a dedicated display label for improved user clarity.

Copy link

coderabbitai bot commented Apr 3, 2025

Walkthrough

This pull request introduces a new Visual Studio Code workspace configuration and updates various parts of the backend and frontend. In the backend, git operations have been refactored to separate cloning from configuration updates and now employ Zod for metadata validation. Database migrations and schema definitions have been updated to include a new display name field for repositories, and several UI components and utility functions were adjusted to utilize this new field.

Changes

File(s) Change Summary
.vscode/sourcebot.code-workspace New workspace configuration with defined folder paths and file associations (json → jsonc mapping).
CHANGELOG.md Added a note for fixing repository display name formatting for Gerrit (#259).
packages/backend/src/git.ts, .../repoCompileUtils.ts, .../repoManager.ts, .../types.ts, .../zoekt.ts Removed gitConfig from cloneRepository; added upsertGitConfig; introduced Zod-based repoMetadataSchema; updated repository naming, metadata validation, and command construction.
packages/db/prisma/migrations/20250402232401_add_display_name_to_repo/migration.sql, packages/db/prisma/schema.prisma Added a new displayName column/field to the Repo model and updated metadata field comment to reference repoMetadataSchema.
packages/web/src/actions.ts, .../components/repositoryCarousel.tsx, .../repos/repositoryTable.tsx, .../lib/schemas.ts, .../lib/utils.ts Added repoDisplayName in API responses and revised UI components and utility functions to use the new repository display name field.

Sequence Diagram(s)

sequenceDiagram
  participant RM as Repo Manager
  participant CR as Clone Repository
  participant UG as Upsert Git Config

  RM->>CR: cloneRepository(cloneURL, path, onProgress)
  Note right of CR: Clones repository without gitConfig
  RM->>UG: If metadata.gitConfig exists, call upsertGitConfig(path, gitConfig, onProgress)
Loading

Suggested reviewers

  • msukkari

Poem

I'm a rabbit hopping through the code,
Celebrating changes on this vibrant road.
Workspace set and metadata clear,
Git configs now perfectly near.
With each leap, our project grows—
In every line, a fresh wind blows!
Happy coding, from your little bunny!

✨ 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.
    • 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 plan to trigger planning for file edits and PR creation.
  • @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.

@brendan-kellam brendan-kellam requested a review from msukkari April 3, 2025 00:36
@brendan-kellam brendan-kellam marked this pull request as ready for review April 3, 2025 00:37
@brendan-kellam brendan-kellam force-pushed the bkellam/display-name-improvements branch from e95d7bd to 5db4d26 Compare April 3, 2025 00:40
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: 0

🧹 Nitpick comments (2)
packages/backend/src/repoCompileUtils.ts (1)

281-281: Handle potential null webUrl value.

The webUrl value could be null based on the conditional assignment in line 243, but it's used here without a null check which could result in 'zoekt.web-url' being set to an empty string.

-                    'zoekt.web-url': webUrl ?? '',
+                    'zoekt.web-url': webUrl ?? hostUrl,

This ensures a reasonable fallback value if webUrl is null.

packages/web/src/lib/utils.ts (1)

54-56: Improved display name handling with fallback.

The code now uses repo.RawConfig['display-name'] with a fallback to repo.RawConfig['name'], ensuring a display name is always available if repo.RawConfig exists. The TODO comment about using Zod for validation is a good reminder for future work.

Consider tracking the TODO comment about using Zod for config schema validation as a separate task to ensure it's not forgotten.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d55bf83 and 5db4d26.

📒 Files selected for processing (14)
  • .vscode/sourcebot.code-workspace (1 hunks)
  • CHANGELOG.md (1 hunks)
  • packages/backend/src/git.ts (2 hunks)
  • packages/backend/src/repoCompileUtils.ts (12 hunks)
  • packages/backend/src/repoManager.ts (4 hunks)
  • packages/backend/src/types.ts (2 hunks)
  • packages/backend/src/zoekt.ts (3 hunks)
  • packages/db/prisma/migrations/20250402232401_add_display_name_to_repo/migration.sql (1 hunks)
  • packages/db/prisma/schema.prisma (1 hunks)
  • packages/web/src/actions.ts (1 hunks)
  • packages/web/src/app/[domain]/components/repositoryCarousel.tsx (1 hunks)
  • packages/web/src/app/[domain]/repos/repositoryTable.tsx (1 hunks)
  • packages/web/src/lib/schemas.ts (1 hunks)
  • packages/web/src/lib/utils.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
packages/web/src/lib/utils.ts (1)
packages/web/src/lib/types.ts (1)
  • RepositoryQuery (21-21)
packages/backend/src/repoManager.ts (2)
packages/backend/src/types.ts (1)
  • repoMetadataSchema (26-43)
packages/backend/src/git.ts (2)
  • cloneRepository (3-22)
  • upsertGitConfig (51-63)
packages/backend/src/zoekt.ts (1)
packages/backend/src/types.ts (1)
  • repoMetadataSchema (26-43)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (34)
packages/db/prisma/migrations/20250402232401_add_display_name_to_repo/migration.sql (1)

1-2: Proper implementation for the display name feature

The migration correctly adds a nullable displayName TEXT column to the Repo table. This aligns with the PR objective to introduce an optional display name field for repositories.

packages/web/src/lib/schemas.ts (1)

171-171: Good schema update for the new display name field

Adding the optional repoDisplayName field to the repositoryQuerySchema is consistent with the database migration and properly marked as optional with z.string().optional().

CHANGELOG.md (1)

12-12: Well-documented changelog entry

Good job documenting the fix for repository display name formatting issues, with specific mention of Gerrit repositories and a proper link to this PR.

.vscode/sourcebot.code-workspace (1)

1-16: Nice developer experience improvement

This VS Code workspace configuration is well-structured with:

  1. Two folder paths correctly defined (root and zoekt vendor directory)
  2. Appropriate file associations for JSON files

This will help maintain consistent development environments across the team.

packages/web/src/app/[domain]/components/repositoryCarousel.tsx (1)

76-76: Simplification of display name logic

The code now directly uses repo.repoName for the display name instead of potentially using a shortened version. This change aligns with the PR objective of improving repository display names.

packages/web/src/app/[domain]/repos/repositoryTable.tsx (1)

42-42: Improved repository name display logic

The code now prioritizes the new repoDisplayName field when available, falling back to repoName when it's not. This is a more flexible approach that properly leverages the new display name field introduced in this PR.

packages/web/src/actions.ts (1)

432-432: Added repository display name to return object

This change exposes the optional displayName field from the repository model to the client through the repoDisplayName property, enabling the UI components to utilize this new field. This is a necessary adaptation to make the display name improvements work end-to-end.

packages/db/prisma/schema.prisma (2)

41-41: Added optional displayName field to Repo model

This is the database schema change that implements the core functionality described in the PR objectives. Making the field optional ensures backward compatibility with existing repositories that don't have a display name set.


47-47: Improved metadata field documentation

The added comment clarifies where the schema definition for the metadata field can be found, which improves code maintainability. This is a good practice that helps developers understand the structure of the data stored in this JSON field.

packages/backend/src/types.ts (4)

2-2: Good addition of Zod for schema validation.

Adding Zod for schema validation is an excellent approach to ensure runtime type safety and validation for the repository metadata.


20-25: Good documentation with important warnings.

The comments clearly indicate the importance of backward compatibility when modifying the schema, which is crucial for database schemas. The reference to the schema.prisma comment is also helpful for maintainability.


26-43: Well-structured schema definition.

The schema properly defines the repository metadata structure with appropriate validation rules. Each field has good documentation explaining its purpose, and the use of optional fields maintains flexibility.


45-45: Good type inference approach.

Using z.infer to derive the TypeScript type from the Zod schema ensures consistency between runtime validation and compile-time type checking.

packages/backend/src/zoekt.ts (3)

2-2: Improved import structure.

Updated imports to include the new repoMetadataSchema instead of directly importing RepoMetadata type, which aligns with the schema-based validation approach.


20-20: Enhanced metadata validation.

Changed from type casting to schema validation using repoMetadataSchema.parse(), which provides better runtime validation and error handling for repository metadata.


60-70: Improved command construction readability.

Refactored command construction to use an array of strings joined together instead of a single template string. This improves readability and makes future modifications easier.

packages/backend/src/repoCompileUtils.ts (9)

11-11: Good addition of path module.

Adding the path module is appropriate for handling URL path construction, particularly for joining the repository name root with display names.


33-36: Well-implemented display name handling for GitHub repositories.

The code now extracts the repository name root from the host URL and properly constructs both the full repository name and a shorter display name, which aligns with the PR objectives.

Also applies to: 38-40


49-49: Consistent implementation of display name for GitHub repositories.

The display name is properly added to both the repository record and the metadata configuration for zoekt, ensuring consistency across the system.

Also applies to: 75-75


102-105: Well-implemented display name handling for GitLab repositories.

Similar to the GitHub implementation, the code properly extracts the name root and sets up the display name for GitLab repositories.

Also applies to: 110-111


120-120: Consistent implementation of display name for GitLab repositories.

The display name is properly added to both the repository record and the metadata configuration for zoekt, ensuring consistency across the system.

Also applies to: 144-144


171-174: Well-implemented display name handling for Gitea repositories.

Same pattern is consistently applied for Gitea repositories, maintaining a uniform approach across different repository types.

Also applies to: 177-178


187-187: Consistent implementation of display name for Gitea repositories.

The display name is properly added to both the repository record and the metadata configuration for zoekt, ensuring consistency.

Also applies to: 209-209


232-240: Well-implemented display name handling for Gerrit repositories.

The pattern for handling display names is consistently applied to Gerrit repositories as well.


265-265: Consistent implementation of display name for Gerrit repositories.

The display name is properly added to both the repository record and the metadata configuration for zoekt, maintaining consistency with other repository types.

Also applies to: 286-286

packages/web/src/lib/utils.ts (2)

50-52: Simplified null checking.

The code now immediately returns undefined if repo.RawConfig doesn't exist, which is cleaner than the previous implementation.


61-63:

❓ Verification inconclusive

Parameter type change may impact existing code.

The function parameter was changed from optional repo?: RepositoryQuery to required repo: RepositoryQuery. While the display name handling improvement is good, this change could break existing code that might pass undefined.


🏁 Script executed:

#!/bin/bash
# Check if there are any call sites passing undefined to getRepoQueryCodeHostInfo
rg -A 5 'getRepoQueryCodeHostInfo\(\s*\)' --glob='*.ts' --glob='*.tsx'
rg -A 5 'getRepoQueryCodeHostInfo\(\s*undefined' --glob='*.ts' --glob='*.tsx'

Length of output: 152


Action Required: Verify Call Sites for getRepoQueryCodeHostInfo Usage

The function’s parameter type was updated from optional to required, and our initial automated search did not yield any explicit instances of call sites passing undefined. However, the output was inconclusive. Please manually verify that no callers are relying on the previous optional behavior (i.e., passing or defaulting to undefined). Confirm that all invocations of getRepoQueryCodeHostInfo supply a valid RepositoryQuery object.

  • Review Target: All references in TypeScript files (i.e., *.ts and *.tsx) that invoke getRepoQueryCodeHostInfo.
  • Action: Ensure no call site passes undefined or omits the argument under the assumption of the optional parameter.
packages/backend/src/repoManager.ts (5)

6-6: Good improvement using Zod schema validation

The change from using RepoMetadata type to using repoMetadataSchema for validation provides stronger runtime type checking and better error handling, which aligns with modern TypeScript practices.


8-8: Importing upsertGitConfig aligns with the new architecture

Adding upsertGitConfig to the imports supports the new approach of separating git operations, which improves code maintainability.


203-203: Good use of schema validation

Using repoMetadataSchema.parse() instead of type casting ensures runtime validation of the repository metadata, providing better error handling if the data structure doesn't match expectations.


242-242: Improved separation of concerns

Removing the metadata.gitConfig parameter from the cloneRepository call properly separates the concerns of cloning and configuration. This makes the code more maintainable and follows the single responsibility principle.


251-256: Great enhancement to ensure consistent git configuration

This new block ensures that the git configuration is always up to date with what's stored in the database, regardless of whether it's a clone or fetch operation. This maintains eventual consistency between the database and the git repository, which directly addresses one of the PR objectives.

packages/backend/src/git.ts (2)

3-3: Good simplification of the cloneRepository function

Removing the gitConfig parameter simplifies the function signature and makes the code more focused on just cloning the repository, supporting better separation of concerns.


45-63: Well-implemented upsertGitConfig function with clear documentation

The new function is well-documented and properly implements the logic for updating git configurations. It handles error cases appropriately and maintains the existing keys that are not in the provided gitConfig.

Regarding the state question from the previous review: The git.addConfig(key, value) call modifies the local repository configuration (not global git config). Each call to addConfig is isolated to the repository at the specified path, as the cwd(path) method sets the working directory for the git commands.

@brendan-kellam brendan-kellam merged commit bbd8b22 into main Apr 3, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants