Thanks to visit codestin.com
Credit goes to github.com

Skip to content

catgrep/zed-gerrit-provider-tasks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tasks for Copying Gitiles Permalinks and Opening Gerrit Reviews

At the time of writing, the only Gerrit provider Zed implicitly supports is the Chromium Gerrit provider for stuff like copying permalinks and opening the review link for a "PR" when drilling down into commits.

Its hardcoded to use Chromium's Gerrit URLs, which are https://chromium-review.googlesource.com for the Gerrit UI, and https://chromium.googlesource.com for the Gerrit repo.

As git_hosting_providers exists today, there's not a simple way to extend the model without introducing Gerrit-specifc params into the configuration.

As a workaround, we can leverage Zed's tasks configuration. Zed tasks allow access to some Zed state during runtime (like selected text, current file, etc.).

That means its possible to add some key bindings to trigger shell-based tasks for creating permalinks or opening reviews from highlighted Change-Id's.

How to install

You can copy over the zed-gerrit-provider.sh script to ~/.local/bin and the zed/ configs to your ~/.config/zed.

Or do a one-line install:

curl -fsSL https://raw.githubusercontent.com/catgrep/zed-gerrit-provider-tasks/main/install.sh | sh

The install.sh script is idempotent, so its safe to re-run it. It will:

  1. Download the zed-gerrit-provider.sh script to ~/.local/bin/zed-gerrit-provider.sh and mark it executable
  2. Download zed/tasks.json and zed/keymap.json to ~/.config/zed (and merge them if those files already exist)

You should probably change the default key bindings post-installation.

They don't conflict with Zed's MacOS or Linux defaults, but might with your profile or system.

Copy a Gitiles permalink

To copy a permalink to the current file and line, enter:

  • ctrl-cmd-k (Darwin)
  • alt-shift-c (Linux)

You'll see a terminal window pop-up with some basic logging, like:

Copied: /plugins/gitiles/k8s-gerrit/+/$COMMIT_SHA/Jenkinsfile#1

⏵ Task `gerrit_copy_permalink` finished successfully
⏵ Command: /bin/zsh -i -c '~/.local/bin/zed-gerrit-provider.sh'

Open a Gerrit review

For opening a review, hover over a line to show the git blame modal and click the branch symbol with the commit hash in the lower right-hand corner.

git_blame_modal

This opens up the commit message and diff.

Select the Change-Id with your cursor:

git_blame_change_id

To open the Gerrit review in your browser, enter:

  • ctrl-cmd-g (Darwin)
  • alt-shift-g (Linux)

You'll see a terminal window pop-up with some basic logging, like:

Opened: https://gerrit-review.googlesource.com/q/$CHANGE_ID

⏵ Task `gerrit_open_review` finished successfully
⏵ Command: /bin/zsh -i -c '~/.local/bin/zed-gerrit-provider.sh'

How it works

There are two tasks provided by zed/tasks.json:

  • gerrit_open_review: a task for opening a Gerrit review url generated from a highlighted Change-Id
  • gerrit_copy_permalink: a task for generating and copying a Gerrit Gitiles permalink line to your clipboard

These tasks can be trigged by either running task: spawn from the Command Pallete or by the keyboard shortcuts in zed/keymap.json:

  • ctrl+cmd+g: runs gerrit_open_review when highlighting the Change-Id in a commit message (or anywhere in the Workspace)
  • ctrl+cmd+k: runs gerrit_copy_permalink when the cursor is on a line (or anywhere in the Workspace)

The tasks have an overrideable field ZED_GERRIT_REVIEW_URL that can be set from the environment, or in the tasks.json. You won't need to touch this unless your Gerrit UI has a different domain than your Gerrit repository.

About

Rudimentary support for copying Gerrit Gitiles permalinks and opening Gerrit reviews in Zed

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages