11---
22name : api-review
3- description : Run strict OpenShift API review workflow for PR changes
3+ description : Run strict OpenShift API review workflow for PR changes or local changes
44parameters :
55 - name : pr_url
6- description : GitHub PR URL to review
7- required : true
6+ description : GitHub PR URL to review (optional - if not provided, reviews local changes against upstream master)
7+ required : false
88---
99
1010# Output Format Requirements
@@ -26,49 +26,109 @@ You MUST use this EXACT format for ALL review feedback:
2626** Explanation:** [ Why this change is needed]
2727
2828
29- I'll run a comprehensive API review for the OpenShift API changes in the specified GitHub PR.
29+ I'll run a comprehensive API review for OpenShift API changes. This can review either a specific GitHub PR or local changes against upstream master .
3030
31- ## Step 1: Pre-flight checks and branch management
31+ ## Step 1: Pre-flight checks and determine review mode
3232
33- First, I'll check for uncommitted changes and save the current branch :
33+ First, I'll check the arguments and determine whether to review a PR or local changes :
3434
3535``` bash
3636# Save current branch
3737CURRENT_BRANCH=$( git branch --show-current)
3838echo " 📍 Current branch: $CURRENT_BRANCH "
3939
40- # Check for uncommitted changes
41- if ! git diff --quiet || ! git diff --cached --quiet; then
42- echo " ❌ ERROR: Uncommitted changes detected. Cannot proceed with API review."
43- echo " Please commit or stash your changes before running the API review."
44- git status --porcelain
45- exit 1
40+ # Check if a PR URL was provided
41+ if [ -n " $ARGUMENTS " ] && [[ " $ARGUMENTS " =~ github\. com.* pull ]]; then
42+ REVIEW_MODE=" pr"
43+ PR_NUMBER=$( echo " $ARGUMENTS " | grep -oE ' [0-9]+$' )
44+ echo " 🔍 PR review mode: Reviewing PR #$PR_NUMBER "
45+
46+ # For PR review, check for uncommitted changes
47+ if ! git diff --quiet || ! git diff --cached --quiet; then
48+ echo " ❌ ERROR: Uncommitted changes detected. Cannot proceed with PR review."
49+ echo " Please commit or stash your changes before running the API review."
50+ git status --porcelain
51+ exit 1
52+ fi
53+ echo " ✅ No uncommitted changes detected. Safe to proceed with PR review."
54+ else
55+ REVIEW_MODE=" local"
56+ echo " 🔍 Local review mode: Reviewing local changes against upstream master"
57+
58+ # Find a remote pointing to openshift/api repository
59+ OPENSHIFT_REMOTE=" "
60+ for remote in $( git remote) ; do
61+ remote_url=$( git remote get-url " $remote " 2> /dev/null || echo " " )
62+ if [[ " $remote_url " =~ github\. com[/:]openshift/api(\. git)? $ ]]; then
63+ OPENSHIFT_REMOTE=" $remote "
64+ echo " ✅ Found OpenShift API remote: '$remote ' -> $remote_url "
65+ break
66+ fi
67+ done
68+
69+ # If no existing remote found, add upstream
70+ if [ -z " $OPENSHIFT_REMOTE " ]; then
71+ echo " ⚠️ No remote pointing to openshift/api found. Adding upstream remote..."
72+ git remote add upstream https://github.com/openshift/api.git
73+ OPENSHIFT_REMOTE=" upstream"
74+ fi
75+
76+ # Fetch latest changes from the OpenShift API remote
77+ echo " 🔄 Fetching latest changes from $OPENSHIFT_REMOTE ..."
78+ git fetch " $OPENSHIFT_REMOTE " master
4679fi
47-
48- echo " ✅ No uncommitted changes detected. Safe to proceed."
4980```
5081
51- ## Step 2: Extract PR number and checkout PR
82+ ## Step 2: Get changed files based on review mode
5283
5384``` bash
54- # Extract PR number from URL
55- PR_NUMBER=$( echo " $ARGUMENTS " | grep -oE ' [0-9]+$' )
56- echo " 🔍 Reviewing PR #$PR_NUMBER "
85+ if [ " $REVIEW_MODE " = " pr" ]; then
86+ # PR Review: Checkout the PR and get changed files
87+ echo " 🔄 Checking out PR #$PR_NUMBER ..."
88+ gh pr checkout " $PR_NUMBER "
89+
90+ echo " 📁 Analyzing changed files in PR..."
91+ CHANGED_FILES=$( gh pr view " $PR_NUMBER " --json files --jq ' .files[].path' | grep ' \.go$' | grep -E ' /(v1|v1alpha1|v1beta1)/' )
92+ else
93+ # Local Review: Get changed files compared to openshift remote master
94+ echo " 📁 Analyzing locally changed files compared to $OPENSHIFT_REMOTE /master..."
95+ CHANGED_FILES=$( git diff --name-only " $OPENSHIFT_REMOTE /master...HEAD" | grep ' \.go$' | grep -E ' /(v1|v1alpha1|v1beta1)/' )
96+
97+ # Also include staged changes
98+ STAGED_FILES=$( git diff --cached --name-only | grep ' \.go$' | grep -E ' /(v1|v1alpha1|v1beta1)/' || true)
99+ if [ -n " $STAGED_FILES " ]; then
100+ CHANGED_FILES=$( echo -e " $CHANGED_FILES \n$STAGED_FILES " | sort -u)
101+ fi
102+ fi
57103
58- # Checkout the PR
59- echo " 🔄 Checking out PR #$PR_NUMBER ..."
60- gh pr checkout " $PR_NUMBER "
104+ echo " Changed API files:"
105+ echo " $CHANGED_FILES "
61106
62- # Get changed Go files in API directories
63- echo " 📁 Analyzing changed files..."
64- gh pr view " $PR_NUMBER " --json files --jq ' .files[].path' | grep ' \.go$' | grep -E ' /(v1|v1alpha1|v1beta1)/'
107+ if [ -z " $CHANGED_FILES " ]; then
108+ echo " ℹ️ No API files changed. Nothing to review."
109+ if [ " $REVIEW_MODE " = " pr" ]; then
110+ git checkout " $CURRENT_BRANCH "
111+ fi
112+ exit 0
113+ fi
65114```
66115
67- ## Step 3: Run linting checks on PR changes
116+ ## Step 3: Run linting checks on changes
68117
69118``` bash
70- echo " ⏳ Running linting checks on PR changes..."
119+ echo " ⏳ Running linting checks on changes..."
71120make lint
121+
122+ if [ $? -ne 0 ]; then
123+ echo " ❌ Linting checks failed. Please fix the issues before proceeding."
124+ if [ " $REVIEW_MODE " = " pr" ]; then
125+ echo " 🔄 Switching back to original branch: $CURRENT_BRANCH "
126+ git checkout " $CURRENT_BRANCH "
127+ fi
128+ exit 1
129+ fi
130+
131+ echo " ✅ Linting checks passed."
72132```
73133
74134## Step 4: Documentation validation
@@ -104,20 +164,34 @@ I'll provide a comprehensive report showing:
104164
105165The review will fail if any documentation requirements are not met for the changed files.
106166
107- ## Step 6: Switch back to original branch
167+ ## Step 6: Switch back to original branch (PR mode only)
108168
109- After completing the review, I'll switch back to the original branch:
169+ After completing the review, if we were reviewing a PR, I'll switch back to the original branch:
110170
111171``` bash
112- echo " 🔄 Switching back to original branch: $CURRENT_BRANCH "
113- git checkout " $CURRENT_BRANCH "
114- echo " ✅ API review complete. Back on branch: $( git branch --show-current) "
172+ if [ " $REVIEW_MODE " = " pr" ]; then
173+ echo " 🔄 Switching back to original branch: $CURRENT_BRANCH "
174+ git checkout " $CURRENT_BRANCH "
175+ echo " ✅ API review complete. Back on branch: $( git branch --show-current) "
176+ else
177+ echo " ✅ Local API review complete."
178+ fi
115179```
116180
117181** CRITICAL WORKFLOW REQUIREMENTS:**
182+
183+ ** For PR Review Mode:**
1181841 . MUST check for uncommitted changes before starting
1191852 . MUST abort if uncommitted changes are detected
1201863 . MUST save current branch name before switching
1211874 . MUST checkout the PR before running ` make lint `
1221885 . MUST switch back to original branch when complete
1231896 . If any step fails, MUST attempt to switch back to original branch before exiting
190+
191+ ** For Local Review Mode:**
192+ 1 . MUST detect existing remotes pointing to openshift/api repository (supports any remote name)
193+ 2 . MUST add upstream remote only if no existing openshift/api remote is found
194+ 3 . MUST fetch latest changes from the detected openshift/api remote
195+ 4 . MUST compare against the detected remote's master branch
196+ 5 . MUST include both committed and staged changes in analysis
197+ 6 . No branch switching required since we're reviewing local changes
0 commit comments