A Unified Picture of Short and Long Gamma-Ray Bursts from Compact Binary Mergers