github_replace_old_url_with_new.rb
                        
                             · 1.1 KiB · Ruby
                        
                    
                    
                      
                        Raw
                      
                    
                      
                    
                        
                          
                        
                    
                    
                
                
                
            # URLs below can contain project / group URLs, but have to fit as this script
# does a very simple search and replace.
# Backup first
old_github_url = 'https://git.my-old.domain/'
new_github_url = 'https://git.my-new.domain/'
Ticket.where("preferences LIKE '%github%'").find_in_batches.each do |b|
   b.each do |t|
      next if t.preferences[:github][:issue_links].count.zero?
      # Evaluate array for current data
      no_issue_links = t.preferences[:github][:issue_links].count
      issue_link_hits = 0
      t.preferences[:github][:issue_links].each do |p|
         next unless p.include? new_github_url
         issue_link_hits += 1
         puts "issue_link_hits #{issue_link_hits} / #{no_issue_links}"
      end
      next if issue_link_hits == no_issue_links
      # Move fast, break everything
      puts "Touching Ticket# #{t.number} ..."
      t.preferences[:github][:issue_links].each do |p|
         next unless p.include? old_github_url
         old_url = p
         new_url = p.sub!(old_github_url, new_github_url)
         puts "...  Changed #{old_url} to #{new_url}"
      end
      t.save!
   end
end; nil
                | 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 | 
| 4 | old_github_url = 'https://git.my-old.domain/' | 
| 5 | new_github_url = 'https://git.my-new.domain/' | 
| 6 | |
| 7 | Ticket.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 | 
| 37 | end; nil | 
| 38 | 
                    
                        
                        gitlab_replace_old_url_with_new.rb
                        
                             · 1.1 KiB · Ruby
                        
                    
                    
                      
                        Raw
                      
                    
                      
                    
                        
                          
                        
                    
                    
                
                
                
            # URLs below can contain project / group URLs, but have to fit as this script
# does a very simple search and replace.
# Backup first
old_gitlab_url = 'https://git.my-old.domain/'
new_gitlab_url = 'https://git.my-new.domain/'
Ticket.where("preferences LIKE '%gitlab%'").find_in_batches.each do |b|
   b.each do |t|
      next if t.preferences[:gitlab][:issue_links].count.zero?
      # Evaluate array for current data
      no_issue_links = t.preferences[:gitlab][:issue_links].count
      issue_link_hits = 0
      t.preferences[:gitlab][:issue_links].each do |p|
         next unless p.include? new_gitlab_url
         issue_link_hits += 1
         puts "issue_link_hits #{issue_link_hits} / #{no_issue_links}"
      end
      next if issue_link_hits == no_issue_links
      # Move fast, break everything
      puts "Touching Ticket# #{t.number} ..."
      t.preferences[:gitlab][:issue_links].each do |p|
         next unless p.include? old_gitlab_url
         old_url = p
         new_url = p.sub!(old_gitlab_url, new_gitlab_url)
         puts "...  Changed #{old_url} to #{new_url}"
      end
      t.save!
   end
end; nil
                | 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 | 
| 4 | old_gitlab_url = 'https://git.my-old.domain/' | 
| 5 | new_gitlab_url = 'https://git.my-new.domain/' | 
| 6 | |
| 7 | Ticket.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 | 
| 37 | end; nil | 
| 38 |