Skip to content

davefej/gcli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gcli - Gerrit CLI Tool

A lightweight command-line tool for interacting with Gerrit Code Review, written in Rust.

Features

  • 📖 Read comments from Gerrit changes
  • ✍️ Post comments to trigger builds or leave reviews
  • 📊 View diffs for patchsets
  • 🔐 Secure credential storage via ~/.gerritrc
  • 🎯 Auto-detect Change-Id from git commits
  • Fast shortcuts (rc, wc) for common commands

Installation

Prerequisites

  • Rust (1.70+)
  • Git
  • Access to a Gerrit instance

Install from source

# Clone or navigate to the repository
cd /path/to/gcli

# Install system-wide
cargo install --path .

# Verify installation
gcli --help

The binary will be installed to ~/.cargo/bin/gcli, which should be in your PATH.

Update

To update to the latest version:

cd /path/to/gcli
git pull  # if using git
cargo install --path . --force

Configuration

Create a ~/.gerritrc file with your Gerrit credentials:

url = "https://gerrit.example.com"
username = "your_username"
password = "your_http_password"

Important: Set secure permissions:

chmod 600 ~/.gerritrc

Getting your HTTP password

  1. Log in to your Gerrit instance
  2. Go to Settings → HTTP Credentials
  3. Generate or copy your HTTP password (not your regular password)

Usage

Read Comments

# Read comments for a specific change
gcli read-comments 12345
gcli rc 12345              # shortcut

# Auto-detect from current git commit
gcli rc

Post Comments

# Post a comment
gcli comment "Looks good to me!" -c 12345
gcli wc "LGTM" -c 12345    # shortcut

# Post to current commit (auto-detected)
gcli wc "Approved"

# Trigger Jenkins builds
gcli wc "__TRIGGER_CANVAS_LMS__"

View Diffs

# View diff for a specific change
gcli diff 12345

# Auto-detect from current git commit
gcli diff

# Specific revision/patchset
gcli diff 12345 -r 3

Commands

Command Shortcut Description
read-comments [CHANGE_ID] rc Fetch all comments for a change
comment <MESSAGE> wc Post a comment/review message
diff [CHANGE_ID] - Download code changes (diff)

Command Options

All commands support:

  • -c, --change-id <ID> - Specify change ID (optional if in git repo)
  • -r, --revision <NUM> - Specific revision/patchset (default: "current")

Global options:

  • -s, --url <URL> - Override Gerrit URL
  • -u, --username <USER> - Override username
  • -p, --password <PASS> - Override password

Examples

# Read comments from current commit
gcli rc

# Post approval comment
gcli wc "Ship it!" -c 12345

# View what changed in patchset 2
gcli diff 12345 -r 2

# Use different Gerrit server
gcli -s https://other-gerrit.com rc 12345

How It Works

Auto-detection

If you don't provide a CHANGE_ID, gcli will:

  1. Read your current git commit message
  2. Extract the Change-Id: I... line
  3. Use that for the Gerrit API call

Authentication

gcli uses HTTP Basic Auth with your Gerrit HTTP password (from ~/.gerritrc). This is the same authentication method used by git when pushing to Gerrit.

Troubleshooting

"No Change-Id found in current commit message"

Make sure your commit has a Change-Id: line. If using Gerrit's commit-msg hook, this should be added automatically.

"URL not provided"

Either:

  • Create ~/.gerritrc with your credentials
  • Pass credentials via flags: gcli -s <url> -u <user> -p <pass> <command>

"Failed to send request"

Check:

  • Your Gerrit URL is correct
  • Your HTTP password is valid (not your login password)
  • You have network access to the Gerrit server

Development

Built with:

License

MIT

About

Gerrit Cli

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages