def GetFlakeIssue(flake):
  """Returns the associated flake issue to a flake.

  Tries to use the flake's issue's merge_destination, and falls back to the
    issue itself if it doesn't merge into any other ones.

  Args:
    flake: A Flake Model entity.

  Returns:
    A FlakeIssue entity if it exists, otherwise None. This entity should be the
      final merging destination issue.
  """
  if not flake:
    return None

  return flake.GetIssue(up_to_date=True)