|
| 1 | +--- |
| 2 | +allowed-tools: Bash(git:*), Read, Write, Edit |
| 3 | +argument-hint: <target-branch> [commit-hash] |
| 4 | +description: Backport a feature or fix to a release branch with dependency adaptation |
| 5 | +--- |
| 6 | + |
| 7 | +# Backport Feature to Release Branch |
| 8 | + |
| 9 | +## Context |
| 10 | + |
| 11 | +- Current branch: !`git branch --show-current` |
| 12 | +- Target branch: $1 |
| 13 | +- Commit to backport: $2 (or HEAD if not specified) |
| 14 | +- Latest commit info: !`git log -1 --format="%H %s"` |
| 15 | +- Changed files: !`git show --name-only HEAD | tail -n +7` |
| 16 | + |
| 17 | +## Dependency Version Differences |
| 18 | + |
| 19 | +| Dependency | Main (Latest) | release-4.21 | release-4.20 | release-4.19 | release-4.18 | release-4.17 | release-coo-0.5 | release-coo-0.4 | |
| 20 | +| ------------ | ------------- | ------------ | ------------ | ------------ | ------------ | ------------ | --------------- | --------------- | |
| 21 | +| PatternFly | v6.x | v6.x | v6.x | v6.x | v5.x | v4.x | v6.x | v5.x | |
| 22 | +| React Router | v6 compat | v6 compat | v6 compat | v6 compat | v5 | v5 | v6 compat | v5 | |
| 23 | +| Console SDK | 4.19+ | 4.19 | 4.19 | 4.19 | 1.6.0 | 1.6.0 | 4.19 | 1.6.0 | |
| 24 | + |
| 25 | +## Project Structure Differences |
| 26 | + |
| 27 | +| Branch | Frontend Location | Go Backend | Notes | |
| 28 | +| --------------- | ----------------- | ---------- | --------------------------------- | |
| 29 | +| release-4.14 | Root (`src/`) | No | Frontend-only plugin | |
| 30 | +| release-4.15 | Root (`src/`) | No | Frontend-only plugin | |
| 31 | +| release-4.16 | Root (`src/`) | No | Frontend-only plugin | |
| 32 | +| release-4.17+ | `web/` | Yes | Added Go backend (`pkg/`, `cmd/`) | |
| 33 | +| release-coo-0.x | `web/` | Yes | Same structure as 4.17+ | |
| 34 | + |
| 35 | +> **Note**: When backporting to release-4.16 or earlier, file paths must be adjusted from `web/src/` to `src/`. |
| 36 | +
|
| 37 | +## PatternFly v6 → v5 Transformations |
| 38 | + |
| 39 | +When targeting release-4.18 or earlier (or release-coo-0.4): |
| 40 | + |
| 41 | +```typescript |
| 42 | +// v6 Dropdown (main) |
| 43 | +import { Dropdown, DropdownItem, MenuToggle } from "@patternfly/react-core"; |
| 44 | + |
| 45 | +<Dropdown |
| 46 | + isOpen={isOpen} |
| 47 | + onOpenChange={setIsOpen} |
| 48 | + toggle={(toggleRef) => ( |
| 49 | + <MenuToggle ref={toggleRef} onClick={() => setIsOpen(!isOpen)}> |
| 50 | + {selected} |
| 51 | + </MenuToggle> |
| 52 | + )} |
| 53 | +> |
| 54 | + <DropdownItem>Option 1</DropdownItem> |
| 55 | +</Dropdown>; |
| 56 | + |
| 57 | +// v5 Dropdown (release branches) |
| 58 | +import { Dropdown, DropdownItem, DropdownToggle } from "@patternfly/react-core"; |
| 59 | + |
| 60 | +<Dropdown |
| 61 | + isOpen={isOpen} |
| 62 | + onSelect={() => setIsOpen(false)} |
| 63 | + toggle={<DropdownToggle onToggle={setIsOpen}>{selected}</DropdownToggle>} |
| 64 | + dropdownItems={[<DropdownItem key="1">Option 1</DropdownItem>]} |
| 65 | +/>; |
| 66 | +``` |
| 67 | + |
| 68 | +Common v6 → v5 changes: |
| 69 | +| v6 (main) | v5 (release) | Notes | |
| 70 | +| ---------------------- | ------------------- | ---------------------------- | |
| 71 | +| `<Panel>` | `<Card>` | Different wrapper components | |
| 72 | +| `MenuToggle` | `DropdownToggle` | Dropdown API changed | |
| 73 | +| `Dropdown` (new API) | `Dropdown` (legacy) | Props differ significantly | |
| 74 | +| `Select` (typeahead) | `Select` (legacy) | Selection handling differs | |
| 75 | +| `onOpenChange` | `onToggle` | Event handler naming | |
| 76 | + |
| 77 | +## React Router v6 → v5 Transformations |
| 78 | + |
| 79 | +When targeting release-4.18 or earlier (or release-coo-0.4): |
| 80 | + |
| 81 | +```typescript |
| 82 | +// v6 Navigation (main - using compat layer) |
| 83 | +import { |
| 84 | + useNavigate, |
| 85 | + useLocation, |
| 86 | + useSearchParams, |
| 87 | +} from "react-router-dom-v5-compat"; |
| 88 | +
|
| 89 | +const navigate = useNavigate(); |
| 90 | +navigate("/alerts"); |
| 91 | +
|
| 92 | +const [searchParams, setSearchParams] = useSearchParams(); |
| 93 | +const filter = searchParams.get("filter"); |
| 94 | +
|
| 95 | +// v5 Navigation (release branches) |
| 96 | +import { useHistory, useLocation } from "react-router-dom"; |
| 97 | +
|
| 98 | +const history = useHistory(); |
| 99 | +history.push("/alerts"); |
| 100 | +
|
| 101 | +const location = useLocation(); |
| 102 | +const params = new URLSearchParams(location.search); |
| 103 | +const filter = params.get("filter"); |
| 104 | +``` |
| 105 | + |
| 106 | +Common v6 → v5 changes: |
| 107 | +| v6 (main) | v5 (release) | Notes | |
| 108 | +| -------------------- | ----------------------- | --------------- | |
| 109 | +| `useNavigate()` | `useHistory()` | Navigation hook | |
| 110 | +| `navigate('/path')` | `history.push('/path')` | Navigation call | |
| 111 | +| `useParams<Type>()` | `useParams()` + casting | Type handling | |
| 112 | +| `<Routes>` | `<Switch>` | Route wrapper | |
| 113 | +| `<Route element={}>` | `<Route component={}>` | Route rendering | |
| 114 | +| `useSearchParams()` | `useLocation()` + parse | Query params | |
| 115 | + |
| 116 | +## Your Task |
| 117 | + |
| 118 | +Backport the specified commit to the target branch `$1`. Follow these steps: |
| 119 | + |
| 120 | +### 1. Analyze the Commit |
| 121 | + |
| 122 | +- Identify all changed files from the commit |
| 123 | +- Categorize by type (components, hooks, translations, backend, etc.) |
| 124 | +- Note any PatternFly, React Router, or Console SDK usage |
| 125 | + |
| 126 | +### 2. Check Target Branch Dependencies |
| 127 | + |
| 128 | +Run this command to compare versions: |
| 129 | + |
| 130 | +```bash |
| 131 | +git show $1:web/package.json | grep -E 'patternfly.react-core|react-router|dynamic-plugin-sdk":' |
| 132 | +``` |
| 133 | + |
| 134 | +### 3. Identify Required Transformations |
| 135 | + |
| 136 | +Based on the dependency differences table above: |
| 137 | + |
| 138 | +- PatternFly v6 → v5 transformations (if targeting 4.18 or earlier, or coo-0.4) |
| 139 | +- React Router v6 → v5 transformations (if targeting 4.18 or earlier, or coo-0.4) |
| 140 | +- Path adjustments for 4.16 or earlier (web/src/ → src/) |
| 141 | + |
| 142 | +### 4. Create Backport Branch and Apply Changes |
| 143 | + |
| 144 | +```bash |
| 145 | +git checkout $1 |
| 146 | +git checkout -b backport-<feature>-to-$1 |
| 147 | +``` |
| 148 | + |
| 149 | +### 5. Reinstall Dependencies |
| 150 | + |
| 151 | +After switching branches, always reinstall: |
| 152 | + |
| 153 | +```bash |
| 154 | +cd web && rm -rf node_modules && npm install |
| 155 | +``` |
| 156 | + |
| 157 | +### 6. Apply the Backport |
| 158 | + |
| 159 | +Either cherry-pick (if clean) or manually apply with transformations: |
| 160 | + |
| 161 | +```bash |
| 162 | +# Clean cherry-pick |
| 163 | +git cherry-pick <commit-hash> |
| 164 | +
|
| 165 | +# Or with conflicts - resolve manually then: |
| 166 | +git cherry-pick --continue |
| 167 | +
|
| 168 | +# Abort if needed |
| 169 | +git cherry-pick --abort |
| 170 | +``` |
| 171 | + |
| 172 | +### 7. Verify |
| 173 | + |
| 174 | +Run these commands to validate: |
| 175 | + |
| 176 | +```bash |
| 177 | +cd web |
| 178 | +npm run lint |
| 179 | +npm run lint:tsc |
| 180 | +npm run test:unit |
| 181 | +cd .. && make test-translations |
| 182 | +make test-backend |
| 183 | +``` |
| 184 | + |
| 185 | +### 8. Report Summary |
| 186 | + |
| 187 | +Provide a summary of: |
| 188 | + |
| 189 | +- Files modified |
| 190 | +- Transformations applied (PF v6→v5, Router v6→v5, path changes) |
| 191 | +- Any issues encountered |
| 192 | +- Commands to push and create PR: |
| 193 | + |
| 194 | +```bash |
| 195 | +git push origin backport-<feature>-to-$1 |
| 196 | +# Then create PR targeting $1 branch |
| 197 | +``` |
| 198 | + |
| 199 | +## File Categorization by Complexity |
| 200 | + |
| 201 | +| Category | Path Pattern | Backport Complexity | |
| 202 | +| ------------- | ------------------------ | ---------------------------------- | |
| 203 | +| Components | `web/src/components/**` | Medium-High (dependency sensitive) | |
| 204 | +| Hooks | `web/src/hooks/**` | Medium | |
| 205 | +| Store/Redux | `web/src/store/**` | Low-Medium | |
| 206 | +| Contexts | `web/src/contexts/**` | Low-Medium | |
| 207 | +| Translations | `web/locales/**` | Low | |
| 208 | +| Backend (Go) | `pkg/**`, `cmd/**` | Low | |
| 209 | +| Cypress Tests | `web/cypress/**` | Medium | |
| 210 | +| Config | `web/*.json`, `Makefile` | High (version specific) | |
| 211 | + |
| 212 | +## Release Branch Ownership |
| 213 | + |
| 214 | +| Branch Pattern | Managed By | Use Case | |
| 215 | +| ----------------- | ---------- | ------------------------------ | |
| 216 | +| `release-4.x` | CMO | OpenShift core monitoring | |
| 217 | +| `release-coo-x.y` | COO | Cluster Observability Operator | |
| 218 | + |
| 219 | +## Common Backport Scenarios |
| 220 | + |
| 221 | +### Simple Bug Fix |
| 222 | + |
| 223 | +- Usually clean cherry-pick |
| 224 | +- No dependency changes |
| 225 | +- Just run tests |
| 226 | + |
| 227 | +### New Component Feature |
| 228 | + |
| 229 | +- Check for PatternFly component usage |
| 230 | +- Verify console-extensions.json compatibility |
| 231 | +- May need v6→v5 PatternFly transformations |
| 232 | + |
| 233 | +### Dashboard/Perses Changes |
| 234 | + |
| 235 | +- High dependency sensitivity |
| 236 | +- Check @perses-dev/\* versions in target |
| 237 | +- ECharts version compatibility |
| 238 | + |
| 239 | +### Alerting/Incident Changes |
| 240 | + |
| 241 | +- Check Alertmanager API compatibility |
| 242 | +- Verify any new console extension types |
| 243 | + |
| 244 | +### Translation Updates |
| 245 | + |
| 246 | +- Usually clean backport |
| 247 | +- Verify i18next key compatibility |
| 248 | +- Run `make test-translations` |
| 249 | + |
| 250 | +## Troubleshooting |
| 251 | + |
| 252 | +### "Module not found" after backport |
| 253 | + |
| 254 | +- Check if imported module exists in target branch version |
| 255 | +- Verify package.json dependencies match |
| 256 | + |
| 257 | +### TypeScript errors after adaptation |
| 258 | + |
| 259 | +- Check type definitions between versions |
| 260 | +- Use explicit typing where inference differs |
| 261 | + |
| 262 | +### Test failures after backport |
| 263 | + |
| 264 | +- Compare test utilities between versions |
| 265 | +- Check for mock/fixture differences |
| 266 | + |
| 267 | +### Build failures |
| 268 | + |
| 269 | +- Verify webpack config compatibility |
| 270 | +- Check for console plugin SDK breaking changes |
| 271 | + |
| 272 | +## Backport PR Template |
| 273 | + |
| 274 | +When creating the PR, use this template: |
| 275 | + |
| 276 | +```markdown |
| 277 | +## Backport of #<original-PR-number> |
| 278 | +
|
| 279 | +### Original Change |
| 280 | +
|
| 281 | +<Brief description of the feature or fix> |
| 282 | +
|
| 283 | +### Backport Target |
| 284 | +
|
| 285 | +- Branch: `$1` |
| 286 | +- OpenShift Version: 4.x / COO x.y |
| 287 | +
|
| 288 | +### Adaptations Made |
| 289 | +
|
| 290 | +- [ ] PatternFly v6 → v5 components adapted |
| 291 | +- [ ] React Router v6 → v5 hooks adapted |
| 292 | +- [ ] Console SDK API adjustments |
| 293 | +- [ ] No adaptations needed (clean cherry-pick) |
| 294 | +
|
| 295 | +### Testing |
| 296 | +
|
| 297 | +- [ ] `make lint-frontend` passes |
| 298 | +- [ ] `make test-backend` passes |
| 299 | +- [ ] `npm run test:unit` passes |
| 300 | +- [ ] `make test-translations` passes |
| 301 | +- [ ] Manual testing performed |
| 302 | +
|
| 303 | +### Notes |
| 304 | +
|
| 305 | +<Any additional context about the backport> |
| 306 | +``` |
| 307 | + |
| 308 | +## Quick Reference Commands |
| 309 | + |
| 310 | +```bash |
| 311 | +# View commit to backport |
| 312 | +git show <commit-hash> |
| 313 | +
|
| 314 | +# Compare file between branches |
| 315 | +git diff $1:web/src/<file> main:web/src/<file> |
| 316 | +
|
| 317 | +# Check dependency versions in target |
| 318 | +git show $1:web/package.json | grep -A 5 "patternfly" |
| 319 | +
|
| 320 | +# Interactive cherry-pick with edit |
| 321 | +git cherry-pick -e <commit-hash> |
| 322 | +``` |
0 commit comments