Skip to content

Commit 9518b8c

Browse files
authored
Change pattern for new domain
1 parent 3ffb4cf commit 9518b8c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

api/ruby/enterprise/change-domains-in-links.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
# Set up Octokit
1717
Octokit.configure do |kit|
18-
kit.api_endpoint = "#{hostname}/api/v3"
18+
kit.api_endpoint = "https://#{hostname}/api/v3"
1919
kit.access_token = access_token
2020
kit.auto_paginate = true
2121
end
@@ -29,10 +29,10 @@
2929
# Extract links to attached files using regexp
3030
# Looks for the raw markdown formatted image link formatted like this:
3131
# [image description](https://media.octodemo.com/user/267/files/e014c3e4-889c-11e6-8637-1f16c810cfe3)
32-
# example pattern = /\[[^\]]*\]\((https:\/\/[a-z]+.octodemo.com[^\)]*\/files\/[^\)]*)\)/
32+
# example pattern = /\[[^\]]*\]\((https:\/\/media.octodemo.com[^\)]*\/files\/[^\)]*)\)/
3333
old_domain = ARGV[0]
3434
new_domain = ARGV[1]
35-
media_pattern = /\[[^\]]*\]\((https:\/\/[a-z]+.#{old_domain}[^\)]*\/user\/\d*\/files\/[^\)]*)\)/
35+
media_pattern = /\[[^\]]*\]\((https:\/\/media.#{old_domain}[^\)]*\/user\/\d*\/files\/[^\)]*)\)/
3636

3737
Octokit.repositories.map{|repo| repo.full_name}.each do |r|
3838
# Extract issues containing links to attached files
@@ -46,7 +46,8 @@
4646
matched_links = issue.body.scan(media_pattern)
4747
matched_links.each do |file|
4848
puts "#{issue.html_url},#{file[0]}"
49-
new_link = file[0].gsub(old_domain, new_domain)
49+
# Rewrite link with "media" subdomain to "/storage" on the new domain
50+
new_link = file[0].gsub("media.#{old_domain}", "#{new_domain}/storage")
5051
new_body = issue.body.gsub(file[0], new_link)
5152
Octokit.update_issue(r, issue.number, :body => new_body)
5253
puts "Updated Issue/PR: #{issue.html_url}"
@@ -64,7 +65,8 @@
6465
matched_links = issue_comment.body.scan(media_pattern)
6566
matched_links.each do |file|
6667
puts "#{issue_comment.html_url},#{file[0]}"
67-
new_link = file[0].gsub(old_domain, new_domain)
68+
# Rewrite link with "media" subdomain to "/storage" on the new domain
69+
new_link = file[0].gsub("media.#{old_domain}", "#{new_domain}/storage")
6870
new_comment = issue_comment.body.gsub(file[0], new_link)
6971
Octokit.update_comment(r, issue_comment.id, new_comment)
7072
puts "Updated Issue/PR Comment: #{issue_comment.html_url}"

0 commit comments

Comments
 (0)