The short answer to how to repair stucco is this: identify why the stucco failed, remove loose material, use compatible patch material, blend the texture, and address paint or finish color after the repair cures.
The best way to paint stucco is to repair and clean first. Paint can refresh a stucco exterior, but it should not be used to cover active cracks, loose texture, or trapped moisture.
Learning how to stucco a wall means looking beyond the finish. A durable stucco wall depends on substrate prep, drainage, lath, cement plaster layers, curing, and a compatible finish.