|
15 | 15 |
|
16 | 16 | # Set up Octokit
|
17 | 17 | Octokit.configure do |kit|
|
18 |
| - kit.api_endpoint = "#{hostname}/api/v3" |
| 18 | + kit.api_endpoint = "https://#{hostname}/api/v3" |
19 | 19 | kit.access_token = access_token
|
20 | 20 | kit.auto_paginate = true
|
21 | 21 | end
|
|
29 | 29 | # Extract links to attached files using regexp
|
30 | 30 | # Looks for the raw markdown formatted image link formatted like this:
|
31 | 31 | # [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\/[^\)]*)\)/ |
33 | 33 | old_domain = ARGV[0]
|
34 | 34 | 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\/[^\)]*)\)/ |
36 | 36 |
|
37 | 37 | Octokit.repositories.map{|repo| repo.full_name}.each do |r|
|
38 | 38 | # Extract issues containing links to attached files
|
|
46 | 46 | matched_links = issue.body.scan(media_pattern)
|
47 | 47 | matched_links.each do |file|
|
48 | 48 | 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") |
50 | 51 | new_body = issue.body.gsub(file[0], new_link)
|
51 | 52 | Octokit.update_issue(r, issue.number, :body => new_body)
|
52 | 53 | puts "Updated Issue/PR: #{issue.html_url}"
|
|
64 | 65 | matched_links = issue_comment.body.scan(media_pattern)
|
65 | 66 | matched_links.each do |file|
|
66 | 67 | 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") |
68 | 70 | new_comment = issue_comment.body.gsub(file[0], new_link)
|
69 | 71 | Octokit.update_comment(r, issue_comment.id, new_comment)
|
70 | 72 | puts "Updated Issue/PR Comment: #{issue_comment.html_url}"
|
|
0 commit comments