Skip to content
GitLab
Next
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • GitLab GitLab
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 44,761
    • Issues 44,761
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 1,332
    • Merge requests 1,332
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.orgGitLab.org
  • GitLabGitLab
  • Issues
  • #231472
Closed
Open
Issue created Jul 24, 2020 by charlie ablett@cablett🛠Maintainer

Modify label promote logic to avoid label duplicate when group label already exists

The following discussion from !37148 (merged) should be addressed:

I see there's a test failure in the PromoteService in the case that the project label is being promoted and a group label with that title already exists.

We actually handle this scenario in Labels::PromoteService albeit in an odd way that doesn't work when this constraint is added.

I remember adding the doc for this in https://docs.gitlab.com/ee/user/project/labels.html#promote-a-project-label-to-a-group-label:

If a group label with the same title exists, it will also be merged.

This is the relevant section of the code in Labels::PromoteService:

new_label = clone_label_to_group_label(label)

label_ids_for_merge(new_label).find_in_batches(batch_size: BATCH_SIZE) do |batched_ids|
  update_old_label_relations(new_label, batched_ids)
  destroy_project_labels(batched_ids)
end
  1. clone_label_to_group_label creates a group label with the same name
  2. label_ids_for_merge(new_label) would include that old group label with the same name
  3. the block would then update all objects to reference this new label
  4. destroy_project_labels deletes the old group label with the same name (The method name is not accurate 🙂)

I think we could be smarter here and not create a duplicate label if we know that a group label of the same name already exists. We should just update the references to that existing label.

That way we also won't need to update other objects assigned to that old group label.

Edited Oct 15, 2020 by charlie ablett
Assignee
Assign to
Time tracking