GitLab Well Architected
Cookbook navigation
Prompts / Consolidate Duplicate Code

Consolidate Duplicate Code

Code QualityDeveloperDryRefactoringCreateAdvanced

Identify and consolidate duplicate code into reusable components. Apply DRY principles systematically.

For GitLab Duo

prompt

I found duplicate code:

Location 1:
[PASTE CODE]

Location 2:
[PASTE CODE]

Help me:
1. Extract common logic
2. Create reusable function/class
3. Update all call sites
4. Ensure no functionality is lost

Use the prompt

Include the callers as well as the duplicated code. Similar-looking blocks may handle different cases, and those differences matter when deciding what to combine.