Skip to content

Instantly share code, notes, and snippets.

@zealot128
Created September 10, 2020 08: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/034cf8bad50d13f20af38149cf04ab1d to your computer and use it in GitHub Desktop.
Save zealot128/034cf8bad50d13f20af38149cf04ab1d to your computer and use it in GitHub Desktop.
Gitlab: Move all issues on a (closed) milestone to a new one
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'gitlab'
gem 'pastel'
gem 'tty-prompt'
end
require 'tty-prompt'
require 'pastel'
require 'gitlab'
Gitlab.endpoint = URL
Gitlab.private_token = TOKEN
# Milestones from this group will be scoped
TARGET_GROUP = 'developers'
p = Pastel.new
milestones = Gitlab.group_milestones(TARGET_GROUP, state: 'active').sort_by(&:due_date)
prompt = TTY::Prompt.new
choosen = prompt.select("Issues of which milestone should be transfered?") do |menu|
milestones.each do |ms|
menu.choice name: ms.title, value: ms
end
end
puts " loading issues..."
issues = Gitlab.group_milestone_issues(TARGET_GROUP, choosen.id).
auto_paginate.
sort_by(&:web_url).
select { |i| i.state == 'opened' }
unassigned = issues.select { |i| i.assignee.blank? }
puts "#{p.red(issues.count).to_s} open Issues found."
puts "#{p.red(unassigned.count).to_s} open issues without assignee."
target = prompt.select("Where should the issues be transfered to? ") do |menu|
milestones.each do |ms|
next if ms.id == choosen.id
menu.choice name: ms.title, value: ms
end
end
def issue_list(issue)
p = Pastel.new
url = sprintf("%-65s", issue.web_url)
puts "- #{p.blue(url)} #{issue.title}"
end
puts "Transfering unassigned issues"
unassigned.each do |issue|
issue_list(issue)
Gitlab.edit_issue(issue.project_id, issue.iid, milestone_id: target.id)
end
puts ""
puts "Transfering assgined issues:"
issues_per_user = issues.group_by { |i| i.assignee.username }
issues_per_user.each do |username, issues|
puts p.red(username)
issues.each do |issue|
issue_list(issue)
Gitlab.edit_issue(issue.project_id, issue.iid, milestone_id: target.id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment