Skip to content

Instantly share code, notes, and snippets.

@zealot128
Created February 15, 2023 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zealot128/cd22f50b3755ccf0df92cf3d84cf038d to your computer and use it in GitHub Desktop.
Save zealot128/cd22f50b3755ccf0df92cf3d84cf038d to your computer and use it in GitHub Desktop.
Gitlab label priority - fine tuning
# copy script content into ` sudo gitlab-rails console `:
# Gitlab FOSS does only give you the option to Prioritize Labels per project, and only On/Off, no value.
# IT is tiresome to iterate each project and set prioritzed labels, but in the database you can just set an arbitrary Priority Value
# Priority order: Lowest First.
should_be = {
"prio:0" => 5,
"type:bug" => 6,
"prio:1" => 8,
"prio:2" => 9,
}
# ID of the group for which GroupLabel you want to set
group_id = 3
projects = Project.where(namespace_id: group_id, archived: false).reject { |i| i.issues.opened.none? }
should_be.each do |title, priority|
GroupLabel.where(title: title).each do |label|
projects.each do |project|
if current_priority = label.priorities.where(project: project).first
next if current_priority.priority == priority
current_priority.update!(priority: priority)
puts ["Update" , label.title, project.name].join(" ")
next
end
puts ["Add" , label.title, priority, project.name].join(" ")
label.priorities.create!(project: project, priority: priority)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment