Commit Status API breaks when ref is ambiguous
Related to Commit Status API only creates branch pipelines... (#589315)
While testing the fix for the above issue I noted that detecting the ref type by using tag_exists?(ref) only works when the ref is unambiguous, if there's also a branch then we don't know if we should be creating a pipeline for the branch or tag.
The existing protected_for?(ref) check also breaks when the ref type is ambiguous.
The logic in https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/services/ci/create_commit_status_service.rb def create_pipeline needs to be modified to better detect the ref type.
Proposed solutions
- We need to add a new parameter to the API to allow uses to specify the
ref_typewhich can beheadsortags. - Project#protected_for needs to add
ref_typeso we can prevent the ambiguous error - If the ref_type is passed then we can use this ref type to populate protected and tag
- If no ref_type is passed then we need to first check if the ref is ambiguous and then return an error message if it is (not 500)
Edited by Joe Woodward