1
1
---
2
2
name : 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
4
4
parameters :
5
5
- 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
8
8
---
9
9
10
10
# Output Format Requirements
@@ -26,49 +26,109 @@ You MUST use this EXACT format for ALL review feedback:
26
26
** Explanation:** [ Why this change is needed]
27
27
28
28
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 .
30
30
31
- ## Step 1: Pre-flight checks and branch management
31
+ ## Step 1: Pre-flight checks and determine review mode
32
32
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 :
34
34
35
35
``` bash
36
36
# Save current branch
37
37
CURRENT_BRANCH=$( git branch --show-current)
38
38
echo " 📍 Current branch: $CURRENT_BRANCH "
39
39
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
46
79
fi
47
-
48
- echo " ✅ No uncommitted changes detected. Safe to proceed."
49
80
```
50
81
51
- ## Step 2: Extract PR number and checkout PR
82
+ ## Step 2: Get changed files based on review mode
52
83
53
84
``` 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
57
103
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 "
61
106
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
65
114
```
66
115
67
- ## Step 3: Run linting checks on PR changes
116
+ ## Step 3: Run linting checks on changes
68
117
69
118
``` bash
70
- echo " ⏳ Running linting checks on PR changes..."
119
+ echo " ⏳ Running linting checks on changes..."
71
120
make 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."
72
132
```
73
133
74
134
## Step 4: Documentation validation
@@ -104,20 +164,34 @@ I'll provide a comprehensive report showing:
104
164
105
165
The review will fail if any documentation requirements are not met for the changed files.
106
166
107
- ## Step 6: Switch back to original branch
167
+ ## Step 6: Switch back to original branch (PR mode only)
108
168
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:
110
170
111
171
``` 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
115
179
```
116
180
117
181
** CRITICAL WORKFLOW REQUIREMENTS:**
182
+
183
+ ** For PR Review Mode:**
118
184
1 . MUST check for uncommitted changes before starting
119
185
2 . MUST abort if uncommitted changes are detected
120
186
3 . MUST save current branch name before switching
121
187
4 . MUST checkout the PR before running ` make lint `
122
188
5 . MUST switch back to original branch when complete
123
189
6 . 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