Tech debt: Extract labels_as_hash logic into a concern
In https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/6195 two copies of labels_as_hash
was introduced. This should be extracted as a concern so future changes will not cause inconsistencies between the two places using this logic.