Some labels have both project_id and group_id

During !45122 (merged) it was overlooked that label logic elsewhere assumes no labels with both project_id and group_id. However, the promotion logic doesn't remove the project_id.

We're still not sure where this comes from (imports?) but some project labels have both project_id and group_id. See !37148 (comment 462004235) for more context.

Possible Workaround

From (internal) https://gitlab.zendesk.com/agent/tickets/272277 where label filtering resulted in 0 issues after import.

If all the labels in the project are supposed to be project labels:

p = Project.find <id>
p.labels.each do |l|
  label =  Label.find l.id
  label.group_id = nil
  label.type = 'ProjectLabel'
  label.save
end

If some of them should be group labels use:

group_labels = [<coma separated id number>] # example group_labels = [1,3,5]
group_labels.each do |label|
  label.project_id = nil
  label.type = 'GroupLabel'
  label.save
end

Then do the same for the rest and set as project labels.

Edited by Cynthia "Arty" Ng