Created
February 15, 2023 07:49
-
-
Save zealot128/cd22f50b3755ccf0df92cf3d84cf038d to your computer and use it in GitHub Desktop.
Gitlab label priority - fine tuning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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