Wars don't come suddenly unless you're attacked by a rogue. There're always tell tale signs if your alliance will be involved in a war. But I agree on how wars can be destructive in a improvement swapping cycle.
Goto the nation you want to donate and click "make donation" at the top, just underneath all the tabs.
Make sure you liaise with that nation regarding your donation.