Skip to content

feat: add update-refs skill#70

Open
juandspy wants to merge 5 commits into
masterfrom
skill-update-refs
Open

feat: add update-refs skill#70
juandspy wants to merge 5 commits into
masterfrom
skill-update-refs

Conversation

@juandspy
Copy link
Copy Markdown
Contributor

@juandspy juandspy commented Apr 16, 2026

Description

Adding a skill to update the repo refs in app-interface.

Type of change

  • Configuration update

Testing steps

tested in https://gitlab.cee.redhat.com/service/app-interface/-/merge_requests/183901 (before fixing the git add . that was too wide)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6e4a4c11-e99b-4634-b681-ddb5e3844009

📥 Commits

Reviewing files that changed from the base of the PR and between 41e98a1 and a7d1ca6.

📒 Files selected for processing (1)
  • skills/update-refs/scripts/update_refs.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • skills/update-refs/scripts/update_refs.sh

Summary by CodeRabbit

  • New Features
    • Added a skill with documentation and a CLI tool to update YAML ref fields to the latest commit SHAs from repositories' default branches.
    • Supports dry-run mode, selective repository filtering, reusing a local checkout, skips protected refs (e.g., internal/main/master), and reports a concise change summary and per-repo logging.

Walkthrough

Adds a new skill document and a Bash CLI script that scan YAML under data/services/insights/ccx-data-pipeline in an app-interface checkout and update ref: values to each repo’s default-branch latest commit SHA, with dry-run, repo filtering, and local-checkout reuse options. (48 words)

Changes

Cohort / File(s) Summary
Skill doc
skills/update-refs/SKILL.md
New documentation describing purpose, prerequisites, usage (./scripts/update_refs.sh), flags (--dry-run, repeatable --repo, --local-folder), expected workflow, and constraints (VPN/network, skip internal/main/master).
Update script
skills/update-refs/scripts/update_refs.sh
New Bash CLI that clones or reuses app-interface (default git@gitlab.cee.redhat.com:service/app-interface.git into /tmp/app-interface), scans data/services/insights/ccx-data-pipeline YAMLs, tracks preceding url: context, resolves each repo’s default branch and latest SHA via git ls-remote --symref, caches lookups, skips `ref: internal

Sequence Diagram(s)

sequenceDiagram
  participant User as User
  participant Script as Update Script
  participant Local as Local app-interface (fs)
  participant Remote as Git Remote (gitlab)
  rect rgba(200,220,255,0.5)
  User->>Script: run ./scripts/update_refs.sh [--dry-run] [--repo] [--local-folder]
  end
  Script->>Local: ensure repo checkout (clone or reuse)
  Script->>Local: scan YAMLs under data/services/insights/ccx-data-pipeline
  loop per referenced repo URL
    Script->>Remote: git ls-remote --symref <repo-url> (resolve default branch)
    Remote-->>Script: default branch ref
    Script->>Remote: git ls-remote <repo-url> <default-branch>
    Remote-->>Script: latest commit SHA
    Script->>Local: replace `ref:` lines (or report if dry-run)
  end
  Script->>User: summary of changes, per-file counts
  alt not dry-run
    Script->>Local: commit to timestamped branch and output next steps
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add update-refs skill' directly and concisely summarizes the main change: adding a new skill for updating repository references, which matches the changeset content.
Description check ✅ Passed The description is related to the changeset, explaining that a skill is being added to update repo refs in app-interface and noting testing performed in a related GitLab MR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch skill-update-refs

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread skills/update-refs/scripts/update_refs.sh
Comment thread skills/update-refs/scripts/update_refs.sh
Comment thread skills/update-refs/scripts/update_refs.sh Outdated
Comment thread skills/update-refs/scripts/update_refs.sh
@juandspy juandspy force-pushed the skill-update-refs branch from 1eca385 to 548d08a Compare April 16, 2026 10:14
@juandspy juandspy marked this pull request as ready for review April 16, 2026 10:15
@juandspy juandspy requested a review from a team as a code owner April 16, 2026 10:15
@juandspy juandspy marked this pull request as draft April 16, 2026 10:16
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

♻️ Duplicate comments (1)
skills/update-refs/scripts/update_refs.sh (1)

90-111: ⚠️ Potential issue | 🟠 Major

current_url can leak across YAML objects and rewrite the wrong ref.

current_url is sticky until another url: appears. A later unrelated ref: key can be incorrectly paired with a stale URL and updated to the wrong SHA.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@skills/update-refs/scripts/update_refs.sh` around lines 90 - 111, The bug is
that current_url is sticky across YAML objects and can pair with later unrelated
ref lines; fix by tracking the URL's indentation and scoping so refs only match
when at the same indentation (or reset current_url on dedent/blank). Modify the
url regex handling to capture and save the leading whitespace as url_indent (in
addition to current_url), update the ref-match check to capture the ref's
leading whitespace and only proceed when that indent equals url_indent (or when
current_url is non-empty and repo_matches "$current_url" and indent matches),
and also clear current_url/url_indent when a line with less indentation or an
empty/top-level line is seen so later refs won't reuse a stale URL (refer to
variables current_url, url_indent, prefix, old_ref and functions repo_matches
and get_latest_sha).
🧹 Nitpick comments (1)
skills/update-refs/SKILL.md (1)

65-69: Use a full timestamp in branch example to avoid collisions.

date +%Y%m%d can collide on repeated runs the same day. Prefer including time (for example %Y%m%d%H%M%S).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@skills/update-refs/SKILL.md` around lines 65 - 69, The branch example uses a
date format that can collide; update the BRANCH assignment and the example
checkout in the SKILL.md snippet (the lines setting BRANCH="update-refs-$(date
+%Y%m%d)" and git checkout -b $BRANCH) to use a full timestamp format such as
%Y%m%d%H%M%S to ensure unique branch names (e.g., change the date command to
date +%Y%m%d%H%M%S).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@skills/update-refs/scripts/update_refs.sh`:
- Around line 29-43: The script update_refs.sh currently cd's into
PATH_TO_APP_INTERFACE and runs git fetch/checkout/pull without verifying the
target is the intended repo, risking mutations of an unrelated repository;
before executing git operations (the cd and the git fetch origin master / git
checkout master / git pull origin master sequence), validate
PATH_TO_APP_INTERFACE is a valid git repo and points to the expected remote
(e.g., check that "$PATH_TO_APP_INTERFACE/.git" exists and that git -C
"$PATH_TO_APP_INTERFACE" remote get-url origin matches the expected
git@gitlab.cee.redhat.com:service/app-interface.git), abort with an error if
validation fails, and only then perform the cd and git commands.

In `@skills/update-refs/SKILL.md`:
- Around line 18-19: The README prerequisites claim HTTPS Git access but the
script update_refs.sh performs an SSH clone using the git@... transport;
reconcile them by either updating the SKILL.md prerequisite to require
SSH/key-based access and mention the git@gitlab.cee.redhat.com clone style, or
change the clone invocation in update_refs.sh to use the HTTPS URL
(https://gitlab.cee.redhat.com/service/app-interface.git) so the documentation
and the script match; locate the SSH clone invocation in update_refs.sh (the git
clone git@gitlab.cee.redhat.com:... command) or the prerequisites list in
SKILL.md and make the corresponding edit.
- Around line 83-85: Update the wording in the SKILL.md section that currently
reads "Clones (or reuses) app-interface to `/tmp/app-interface`" so it no longer
contradicts the documented --local-folder behavior: explicitly state that when
--local-folder is provided the tool reuses the specified path, otherwise it
clones into /tmp (or uses `/tmp/app-interface` by default). Reference the phrase
"Clones (or reuses) app-interface to `/tmp/app-interface`" and the option name
"--local-folder" when making the change so the intent and behavior are clear and
consistent.

---

Duplicate comments:
In `@skills/update-refs/scripts/update_refs.sh`:
- Around line 90-111: The bug is that current_url is sticky across YAML objects
and can pair with later unrelated ref lines; fix by tracking the URL's
indentation and scoping so refs only match when at the same indentation (or
reset current_url on dedent/blank). Modify the url regex handling to capture and
save the leading whitespace as url_indent (in addition to current_url), update
the ref-match check to capture the ref's leading whitespace and only proceed
when that indent equals url_indent (or when current_url is non-empty and
repo_matches "$current_url" and indent matches), and also clear
current_url/url_indent when a line with less indentation or an empty/top-level
line is seen so later refs won't reuse a stale URL (refer to variables
current_url, url_indent, prefix, old_ref and functions repo_matches and
get_latest_sha).

---

Nitpick comments:
In `@skills/update-refs/SKILL.md`:
- Around line 65-69: The branch example uses a date format that can collide;
update the BRANCH assignment and the example checkout in the SKILL.md snippet
(the lines setting BRANCH="update-refs-$(date +%Y%m%d)" and git checkout -b
$BRANCH) to use a full timestamp format such as %Y%m%d%H%M%S to ensure unique
branch names (e.g., change the date command to date +%Y%m%d%H%M%S).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 893c097d-a72d-486e-a21d-5942a94489e5

📥 Commits

Reviewing files that changed from the base of the PR and between 45fbaa9 and d1ada66.

📒 Files selected for processing (2)
  • skills/update-refs/SKILL.md
  • skills/update-refs/scripts/update_refs.sh

Comment thread skills/update-refs/scripts/update_refs.sh
Comment thread skills/update-refs/SKILL.md
Comment thread skills/update-refs/SKILL.md
@juandspy juandspy marked this pull request as ready for review April 22, 2026 12:44
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
skills/update-refs/scripts/update_refs.sh (1)

29-43: ⚠️ Potential issue | 🔴 Critical

Harden repo targeting and handle cd failure before mutating anything.

Line 38–42 can still operate on the wrong repository, and Line 38 is also the current ShellCheck blocker (SC2164). Validate --local-folder is the intended app-interface repo, and fail immediately if cd fails.

Proposed hardening
 if [[ -z "$PATH_TO_APP_INTERFACE" ]]; then
     PATH_TO_APP_INTERFACE="/tmp/app-interface"
     if [[ -d "$PATH_TO_APP_INTERFACE/.git" ]]; then
         echo "App-interface repo already exists at $PATH_TO_APP_INTERFACE, skipping clone."
     else
         git clone --depth 1 git@gitlab.cee.redhat.com:service/app-interface.git "$PATH_TO_APP_INTERFACE"
     fi
 fi

-cd "$PATH_TO_APP_INTERFACE"
+if ! git -C "$PATH_TO_APP_INTERFACE" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
+    echo "ERROR: $PATH_TO_APP_INTERFACE is not a git repository" >&2
+    exit 1
+fi
+origin_url="$(git -C "$PATH_TO_APP_INTERFACE" remote get-url origin 2>/dev/null || true)"
+if [[ "$origin_url" != *"service/app-interface.git" && "$origin_url" != *"service/app-interface" ]]; then
+    echo "ERROR: $PATH_TO_APP_INTERFACE is not app-interface (origin=$origin_url)" >&2
+    exit 1
+fi
+cd "$PATH_TO_APP_INTERFACE" || exit 1

 git fetch origin master
 git checkout master
-git pull origin master
+git pull --ff-only origin master
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@skills/update-refs/scripts/update_refs.sh`:
- Line 7: The script currently uses "set -uo pipefail" which doesn't abort on
failing commands; update the shell options in the update_refs.sh startup (the
set invocation) to enable errexit as well (e.g., include -e or --errexit) so the
script fails fast on any command error, ensuring git/network errors stop
execution and prevent partial/stale updates.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 86852d3a-c64e-4761-afca-e8857f050578

📥 Commits

Reviewing files that changed from the base of the PR and between d1ada66 and 41e98a1.

📒 Files selected for processing (1)
  • skills/update-refs/scripts/update_refs.sh

Comment thread skills/update-refs/scripts/update_refs.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants