Sanctuary is pretty close
It's not guaranteed, but the spell sanctuary has a pretty close mechanic for this:
You ward a creature within range against attack. Until the spell ends, any creature who targets the warded creature with an attack or a harmful spell must first make a Wisdom saving throw. On a failed save, the creature must choose a new target or lose the attack or spell.
Bad news is that it's limited to Clerics and a couple of Paladin oaths, and, of course, the ever awesome Bard who can use Magical Secrets to get it.
And granting the Raven the ability to cast this spell and cast it on you is kinda problematic.
The Ready action also wouldn't be helpful
The mechanic that you suggested has some problems:
Maybe something with readied actions? "I ready the raven's action to fly in between me and my attacker when they attack me."
Unfortunately, ravens aren't very big. And moving in between you and the attacker wouldn't change the target. Additionally, because the raven is unlikely to cover half your body, it's movement in between also wouldn't give you a +2 AC bonus that cover generally provides.
Not only that, but typically the Ready action triggers occurs after the trigger event. You'd already have been attacked (thanks gandalfmeansme!)
No general method for any creature to do this
While sanctuary is close to fitting the bill, and the Redemption Paladin's 7th level feature Oath of the Guardian provide mechanics that get close - neither are available for any creature. And neither are options for the Raven.
Unless you houserule something (and given the workaround you're trying to create to get advantage), it'll be up to your DM to decide if they want to carve out a mechanic allowing you to do this.