Gerrit Code Review

repository·master·Indexed 22 days ago

https://github.com/gerritcodereview/gerrit

A code review and project management tool for Git-based projects. Documentation covers site maintenance via the gerrit-maintenance CLI and git-gcplus, incremental reindexing strategies for upgrades, and development of browser plugins using the @gerritcodereview/typescript-api. It also includes guidelines for contributing to the polygerrit-ui application, including the use of AppContext for services and the gr-diff component.

Tokens
48.5K
Snippets
115
Records
291
Agent score
78%

What's inside Gerrit

  1. Overview of Git Commit Message & Metadata Standards

    master

    The gerrit-commit-message-review skill defines the engineering standards for formatting, structuring, and preserving metadata within Git commit messages. The standards are divided into four main areas:

    1. Commit Title Conventions: Stylistic and length requirements for the first line to optimize history navigation.
    2. Commit Body Structure & Formatting: Instructions for explaining the "what" and "why" of a patchset with conciseness and precise wrapping.
    3. Metadata Footers & Preservations: Strict enforcement of preserving system-critical integration footers like Change-Id and issue tracking IDs.
    4. Review Feedback & Suggested Commit Message: Requirement for reviewers to provide a complete, fully-compliant, and copy-pasteable revised commit message.
  2. Use the Gerrit TypeScript Plugin API for browser plugins

    master

    The @gerritcodereview/typescript-api package provides the types, interfaces, and enums required to develop browser plugins for the Gerrit Code Review web application.

    While the .ts files contain the full type definitions, the compiled .js files only contain the enums. For JavaScript-only plugins, this package is primarily useful as a source of truth for supported plugin APIs. For TypeScript development, it provides the necessary type safety for interacting with the Gerrit web application.

    For comprehensive guidance on plugin development, refer to the official Gerrit Plugin Development documentation.

  3. Encapsulate proprietary infrastructure in documentation

    master

    When documenting public-facing APIs, Enums, or interface definitions, you must ensure that no proprietary backend paths or internal corporate URLs are leaked. This prevents information leakage and ensures documentation remains accessible to open-source contributors.

    Rules

    T3-01: Omit Proprietary Infrastructure Paths from Enum Documentation

    Always strip internal directory paths (e.g., google3/...) from JSDoc or TSDoc comments when defining public-facing data models like Enums.

    T3-02: Exclude Internal Code Search URIs from Interface Types

    Never include proprietary code search URLs (e.g., source.corp.google.com) when documenting type definitions or payload schemas. Instead, provide descriptive examples of acceptable values.

    // DON'T: Include internal paths
    /**
     * Enum to match the Action proto from CRUAS.
     * google3/path/to/internal/service/proto/file.proto.
     */
    export enum ActionEnum { ... }
    
    // DO: Strip internal paths
    /**
     * Enum to match the Action proto from CRUAS.
     */
    export enum ActionEnum { ... }
    
    // DON'T: Include internal URLs
    // type_id should match the types here: https://source.corp.google.com/piper///depot/google3/...
    type_id: string;
    
    // DO: Use standard application context examples
    // type_id should map to standard application contexts (e.g., 'gerrit_change', 'bug_tracker').
    type_id: string;
  4. Manage NoteDb Serialization and Schema Evolution

    master

    Gerrit uses NoteDb (Git notes) to persist change metadata. To guarantee data integrity during distributed cluster upgrades, follow these strategies:

    • Two-step schema rollouts: Implement changes in stages to ensure compatibility.
    • Decoupled transfer objects: Use dedicated objects for data transfer to separate the persistence model from the application model.
    • Permissive JSON parsing: Ensure parsers can handle evolving schemas without failing.
  5. Manage dependencies with Yarn and pnpm

    master

    The project is in a gradual migration from yarn to pnpm.

    Critical Rules:

    • yarn.lock is the authoritative source of truth.
    • pnpm-lock.yaml is generated via pnpm import and must NOT be edited manually.
    • DO NOT RUN pnpm install, as it creates a different dependency graph than what is expected.

    Standard Workflow:

    1. Edit package.json
    2. Run yarn install
    3. Run bazel build gerrit
    4. If the build indicates the lock file was updated, rerun the build command.
  6. Apply pragmatic tolerance to commit message reviews

    master

    Avoid 'pedantic noise' by adopting a high threshold for flagging issues. Do not suggest rewrites for minor stylistic preferences or trivial variations if the message is already clear, informative, and meets core requirements.

    Do NOT flag:

    • Minor casing differences (e.g., GrepServlet: add ... vs GrepServlet: Add ...).
    • Subjective phrasing or sentence structure preferences.
    • Trivial stylistic points that do not impact readability.

    DO flag:

    • Objective violations: Title > 60 characters, body lines > 72 characters, missing essential context, or corrupted/missing metadata footers.
  7. Initialize Reactive Properties in willUpdate, not firstUpdated

    master

    Initialize base reactive properties during construction or via willUpdate. Avoid using the firstUpdated hook for initial assignments, as it triggers an unnecessary second render cycle and hurts initial paint performance.

    // GOOD: Reactively bound to updates before render
    override willUpdate(changedProperties: PropertyValues) {
      if (!this.hostUrl) {
        this.hostUrl = window.location.origin;
      }
    }
  8. Omission of Redundant Real-User Data in API Payloads (T6-05)

    master

    To conserve bandwidth in objects that support impersonation (such as ReviewerUpdateInfo), you must omit the real_updated_by field if it is identical to the primary updated_by field. Instead of duplicating the user object, set the field to null to signal that no impersonation has occurred.

    Applies to: REST API serialization layers, specifically ChangeJson.java and TypeScript interface definitions.

    // GOOD: Return null to omit the field entirely
    new ReviewerUpdateInfo(
      c.date(),
      accountLoader.get(c.updatedBy()),
      c.realUpdatedBy().map(accountLoader::get).orElse(null),
      ...
    );
  9. Ensure forward-compatible NoteDb JSON parsing

    master

    To ensure system resilience against future metadata schema expansions, all JSON parsers reading NoteDb revision notes must be inherently permissive. They must safely ignore unknown fields during deserialization to avoid Parsing Exceptions when new fields are added to the payload.

    Implementation: Use a permissive JSON parser configuration (e.g., Gson with default settings) that does not throw exceptions when encountering undocumented properties.

    // GOOD: Permissive parsing explicitly ignoring unknown fields + regression tests verifying this behavior
    Gson permissiveGson = new GsonBuilder().create();
    RevisionNoteData data = permissiveGson.fromJson(reader, RevisionNoteData.class);
  10. Bind Event Listeners Declaratively in Lit Templates

    master

    Always bind event listeners directly within the render() template using the @event syntax. Do not use this.addEventListener inside the component constructor, as this disconnects logic from the template and risks memory leaks.

    // Do:
    override render() {
      return html`
        <div class="menu" @mousedown=${this.handleMenuMouseDown}>
          <div class="menu-item">${this.hoverCardText}</div>
        </div>
      `;
    }