summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-12-21 14:47:27 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-12-21 14:47:27 +0000
commit545a943468c4a178eaedb13a9aed5d3afdaecd05 (patch)
treec45108109efe7b819fcd3f95088cb3b55ea1e2c1 /db
parent4b4cbf0ce4925e22a635e4432e7ac8602199fa5b (diff)
parentf177aaa5fa789654dc440d6ec4ae3546544c1401 (diff)
downloadgitlab-ce-545a943468c4a178eaedb13a9aed5d3afdaecd05.tar.gz
Merge branch 'backport_jira' into 'master'
Backport JIRA service Fixes #3839 Move EE JIRA functionality back to CE. - [x] Make it function in manual testing - [x] Migrate JIRA-specific tests - [x] Tests pass - [x] Migrate documentation - [x] Rollback to previous CE JIRA integration locally, activate on a project then try to migrate db and see if integration still works. - [x] Final EE search for JIRA references See merge request !2146
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20151012173029_set_jira_service_api_url.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/db/migrate/20151012173029_set_jira_service_api_url.rb b/db/migrate/20151012173029_set_jira_service_api_url.rb
new file mode 100644
index 00000000000..2af99e0db0b
--- /dev/null
+++ b/db/migrate/20151012173029_set_jira_service_api_url.rb
@@ -0,0 +1,50 @@
+class SetJiraServiceApiUrl < ActiveRecord::Migration
+ # This migration can be performed online without errors, but some Jira API calls may be missed
+ # when doing so because api_url is not yet available.
+
+ def build_api_url_from_project_url(project_url, api_version)
+ # this is the exact logic previously used to build the Jira API URL from project_url
+ server = URI(project_url)
+ default_ports = [80, 443].include?(server.port)
+ server_url = "#{server.scheme}://#{server.host}"
+ server_url.concat(":#{server.port}") unless default_ports
+ "#{server_url}/rest/api/#{api_version}"
+ end
+
+ def get_api_version_from_api_url(api_url)
+ match = /\/rest\/api\/(?<api_version>\w+)$/.match(api_url)
+ match && match['api_version']
+ end
+
+ def change
+ reversible do |dir|
+ select_all("SELECT id, properties FROM services WHERE services.type IN ('JiraService')").each do |jira_service|
+ id = jira_service["id"]
+ properties = JSON.parse(jira_service["properties"])
+ properties_was = properties.clone
+
+ dir.up do
+ # remove api_version and set api_url
+ if properties['api_version'].present? && properties['project_url'].present?
+ begin
+ properties['api_url'] ||= build_api_url_from_project_url(properties['project_url'], properties['api_version'])
+ rescue
+ # looks like project_url was not a valid URL. Do nothing.
+ end
+ end
+ properties.delete('api_version') if properties.include?('api_version')
+ end
+
+ dir.down do
+ # remove api_url and set api_version (default to '2')
+ properties['api_version'] ||= get_api_version_from_api_url(properties['api_url']) || '2'
+ properties.delete('api_url') if properties.include?('api_url')
+ end
+
+ if properties != properties_was
+ execute("UPDATE services SET properties = '#{quote_string(properties.to_json)}' WHERE id = #{id}")
+ end
+ end
+ end
+ end
+end