Laminar-to-turbulent transition of pipe flows through puffs and slugs