The mechanics of harvesting governance tokens can be found on the relevant smart contracts corresponding to the originator (e.g. CompoundController.sol for Compound) and its relevant interface IController.sol. Please refer to the code in the Github repository for references made throughout this page.
The smart contract can harvest() governance tokens earned from underlying originators (such as COMP tokens for Compound) by selling them on Uniswap at their spot price. Currently, the maximum acceptable cost of harvesting HARVEST_COST is set to 4% (see IController.sol) and will revert if governance tokens value accrued is less than cost.