From bd9c3a03ba33d75cccc4cbcd5fa92da32da57f7c Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Mon, 23 Feb 2026 11:39:41 -0800 Subject: [PATCH] AI. Add read_gerrit_cl skill. Change-Id: I70da1371c01d442511e32f8d35e6106cf4db2af7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/481320 Reviewed-by: Kevin Moore Reviewed-by: Slava Egorov Commit-Queue: Konstantin Shcheglov --- .agents/skills/read_gerrit_cl/SKILL.md | 74 +++++++++++++++++++ .../read_gerrit_cl/scripts/read_comments.sh | 30 ++++++++ .../read_gerrit_cl/scripts/read_patch.sh | 38 ++++++++++ 3 files changed, 142 insertions(+) create mode 100644 .agents/skills/read_gerrit_cl/SKILL.md create mode 100755 .agents/skills/read_gerrit_cl/scripts/read_comments.sh create mode 100755 .agents/skills/read_gerrit_cl/scripts/read_patch.sh diff --git a/.agents/skills/read_gerrit_cl/SKILL.md b/.agents/skills/read_gerrit_cl/SKILL.md new file mode 100644 index 00000000000..4df7f676419 --- /dev/null +++ b/.agents/skills/read_gerrit_cl/SKILL.md @@ -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 [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 +``` + +#### 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. diff --git a/.agents/skills/read_gerrit_cl/scripts/read_comments.sh b/.agents/skills/read_gerrit_cl/scripts/read_comments.sh new file mode 100755 index 00000000000..2142afb20f8 --- /dev/null +++ b/.agents/skills/read_gerrit_cl/scripts/read_comments.sh @@ -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 +# Example: ./read_comments.sh 475600 + +CHANGE=${1:-} +if [ -z "$CHANGE" ]; then + echo "Usage: $0 " + 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 '.' diff --git a/.agents/skills/read_gerrit_cl/scripts/read_patch.sh b/.agents/skills/read_gerrit_cl/scripts/read_patch.sh new file mode 100755 index 00000000000..d1a44920120 --- /dev/null +++ b/.agents/skills/read_gerrit_cl/scripts/read_patch.sh @@ -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 [patchset] +# Example: ./read_patch.sh 459740 +# Example: ./read_patch.sh 459740 2 + +CHANGE=${1:-} +if [ -z "$CHANGE" ]; then + echo "Usage: $0 [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