Last active 1749811126

These snippets allow you to search and replace either just your Gitlab / Github URL or whole group / project URLs if needed. Proceed with care, you cannot undo this operation.

github_replace_old_url_with_new.rb Raw
1# URLs below can contain project / group URLs, but have to fit as this script
2# does a very simple search and replace.
3# Backup first
4old_github_url = 'https://git.my-old.domain/'
5new_github_url = 'https://git.my-new.domain/'
6
7Ticket.where("preferences LIKE '%github%'").find_in_batches.each do |b|
8 b.each do |t|
9 next if t.preferences[:github][:issue_links].count.zero?
10
11 # Evaluate array for current data
12 no_issue_links = t.preferences[:github][:issue_links].count
13 issue_link_hits = 0
14
15 t.preferences[:github][:issue_links].each do |p|
16 next unless p.include? new_github_url
17
18 issue_link_hits += 1
19 puts "issue_link_hits #{issue_link_hits} / #{no_issue_links}"
20 end
21
22 next if issue_link_hits == no_issue_links
23
24 # Move fast, break everything
25 puts "Touching Ticket# #{t.number} ..."
26 t.preferences[:github][:issue_links].each do |p|
27 next unless p.include? old_github_url
28
29 old_url = p
30 new_url = p.sub!(old_github_url, new_github_url)
31
32 puts "... Changed #{old_url} to #{new_url}"
33 end
34
35 t.save!
36 end
37end; nil
38
gitlab_replace_old_url_with_new.rb Raw
1# URLs below can contain project / group URLs, but have to fit as this script
2# does a very simple search and replace.
3# Backup first
4old_gitlab_url = 'https://git.my-old.domain/'
5new_gitlab_url = 'https://git.my-new.domain/'
6
7Ticket.where("preferences LIKE '%gitlab%'").find_in_batches.each do |b|
8 b.each do |t|
9 next if t.preferences[:gitlab][:issue_links].count.zero?
10
11 # Evaluate array for current data
12 no_issue_links = t.preferences[:gitlab][:issue_links].count
13 issue_link_hits = 0
14
15 t.preferences[:gitlab][:issue_links].each do |p|
16 next unless p.include? new_gitlab_url
17
18 issue_link_hits += 1
19 puts "issue_link_hits #{issue_link_hits} / #{no_issue_links}"
20 end
21
22 next if issue_link_hits == no_issue_links
23
24 # Move fast, break everything
25 puts "Touching Ticket# #{t.number} ..."
26 t.preferences[:gitlab][:issue_links].each do |p|
27 next unless p.include? old_gitlab_url
28
29 old_url = p
30 new_url = p.sub!(old_gitlab_url, new_gitlab_url)
31
32 puts "... Changed #{old_url} to #{new_url}"
33 end
34
35 t.save!
36 end
37end; nil
38