Are there any rules for adjudicating a ranged attack fired at a target engaged in melee combat with an ally?

While running a session recently, one of the players chose to “assist” his companion who was in melee with a goblin, by firing an arrow at the pair of them. I couldn’t find any particular rules for this scenario so just had him roll at a disadvantage, counting a miss as a hit on his companion (damage to be ascertained by a second roll).

This seemed to work okay, and became a running joke for the night as the arrow bounced off the companions back, but are there specific rules for this scenario?