AI. Add read_gerrit_cl skill.

Change-Id: I70da1371c01d442511e32f8d35e6106cf4db2af7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/481320
Reviewed-by: Kevin Moore <kevmoo@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov
2026-02-23 11:39:41 -08:00
committed by Commit Queue
parent f5949231ce
commit bd9c3a03ba
3 changed files with 142 additions and 0 deletions
+74
View File
@@ -0,0 +1,74 @@
---
name: read_gerrit_cl
description: Fetch and display the full patch/diff or comments for a Gerrit CL.
---
# Instructions
Use this skill to inspect a Gerrit Change List (CL).
This is useful for reviewing code changes, understanding the scope of a modification, checking comments.
## Requirements
The following command-line tools are required:
- `curl`: For making HTTP requests.
- `jq`: For parsing JSON (needed for comments).
- `base64`: For decoding patch content (needed for patches).
## Scripts
### 1. Read Patch
Run the `read_patch.sh` script to fetch the unified diff of a CL.
#### Usage
```bash
./scripts/read_patch.sh <change_number> [patchset]
```
#### Arguments
1. `change_number`: The numeric ID of the Gerrit change (e.g., `12345`).
2. `patchset` (optional): The patchset number or `current` (default).
#### Example
To fetch the patch for CL 12345 (latest revision):
```bash
./scripts/read_patch.sh 12345
```
To fetch a specific revision (e.g. patchset 2):
```bash
./scripts/read_patch.sh 12345 2
```
The output will be the unified diff format of the patch.
### 2. Read Comments
Run the `read_comments.sh` script to fetch the comments on a CL.
#### Usage
```bash
./scripts/read_comments.sh <change_number>
```
#### Arguments
1. `change_number`: The numeric ID of the Gerrit change (e.g., `12345`).
#### Example
To fetch comments for CL 12345:
```bash
./scripts/read_comments.sh 12345
```
The output will be a JSON object containing the comments.
+30
View File
@@ -0,0 +1,30 @@
#!/bin/bash
# Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
set -euo pipefail
# Usage: ./read_comments.sh <change_number>
# Example: ./read_comments.sh 475600
CHANGE=${1:-}
if [ -z "$CHANGE" ]; then
echo "Usage: $0 <change_number>"
exit 1
fi
if [[ ! "$CHANGE" =~ ^[0-9]+$ ]]; then
echo "Error: change_number must be numeric" >&2
exit 1
fi
command -v curl >/dev/null || { echo "Error: curl is required" >&2; exit 127; }
command -v jq >/dev/null || { echo "Error: jq is required" >&2; exit 127; }
GERRIT='https://dart-review.googlesource.com'
URL="$GERRIT/changes/$CHANGE/comments"
# 1. 'curl -fSsL' fetches data, follows redirects, and fails on server errors.
# 2. 'sed 1d' strips Gerrit's XSSI prefix (the magic ')]}' string) to make it valid JSON.
# 3. 'jq' parses the cleaned string, validates it, and pretty-prints it for readability.
curl -fSsL "$URL" | sed '1d' | jq '.'
+38
View File
@@ -0,0 +1,38 @@
#!/bin/bash
# Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
set -euo pipefail
# Usage: ./read_patch.sh <change_number> [patchset]
# Example: ./read_patch.sh 459740
# Example: ./read_patch.sh 459740 2
CHANGE=${1:-}
if [ -z "$CHANGE" ]; then
echo "Usage: $0 <change_number> [patchset]"
exit 1
fi
if [[ ! "$CHANGE" =~ ^[0-9]+$ ]]; then
echo "Error: change_number must be numeric" >&2
exit 1
fi
PATCHSET=${2:-current}
if [[ "$PATCHSET" != "current" && ! "$PATCHSET" =~ ^[0-9]+$ ]]; then
echo "Error: patchset must be 'current' or numeric" >&2
exit 1
fi
command -v curl >/dev/null || { echo "Error: curl is required" >&2; exit 127; }
command -v base64 >/dev/null || { echo "Error: base64 is required" >&2; exit 127; }
GERRIT='https://dart-review.googlesource.com'
URL="$GERRIT/changes/$CHANGE/revisions/$PATCHSET/patch"
# 1. 'curl -fSsL' fetches data, follows redirects, and fails on server errors.
# 2. Gerrit API /patch endpoint returns base64 encoded content.
# 3. 'base64 --decode' decodes it back to the original unified diff text.
curl -fSsL "$URL" | base64 --decode