Commit 7cb51ba5 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'fix/import-issues-last-updated' into 'master'

Fix issues last update timestamp not preserved after importing a project

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/19689 and https://gitlab.com/gitlab-org/gitlab-ce/issues/19792 (similar, but not the same)

Now `updated_at` should be the time from the original project.

See merge request !5253
parents 50abec8c cc6d3a83
...@@ -94,6 +94,7 @@ v 8.10.0 (unreleased) ...@@ -94,6 +94,7 @@ v 8.10.0 (unreleased)
- Redesign Builds and Pipelines pages - Redesign Builds and Pipelines pages
- Change status color and icon for running builds - Change status color and icon for running builds
- Fix markdown rendering for: consecutive labels references, label references that begin with a digit or contains `.` - Fix markdown rendering for: consecutive labels references, label references that begin with a digit or contains `.`
- Fix last update timestamp on issues not preserved on gitlab.com and project imports
v 8.9.6 v 8.9.6
- Fix importing of events under notes for GitLab projects. !5154 - Fix importing of events under notes for GitLab projects. !5154
......
...@@ -15,32 +15,35 @@ module Gitlab ...@@ -15,32 +15,35 @@ module Gitlab
end end
def execute def execute
project_identifier = CGI.escape(project.import_source) ActiveRecord::Base.no_touching do
project_identifier = CGI.escape(project.import_source)
# Issues && Comments
issues = client.issues(project_identifier) # Issues && Comments
issues = client.issues(project_identifier)
issues.each do |issue|
body = @formatter.author_line(issue["author"]["name"]) issues.each do |issue|
body += issue["description"] body = @formatter.author_line(issue["author"]["name"])
body += issue["description"]
comments = client.issue_comments(project_identifier, issue["id"])
comments = client.issue_comments(project_identifier, issue["id"])
if comments.any?
body += @formatter.comments_header if comments.any?
body += @formatter.comments_header
end
comments.each do |comment|
body += @formatter.comment(comment["author"]["name"], comment["created_at"], comment["body"])
end
project.issues.create!(
iid: issue["iid"],
description: body,
title: issue["title"],
state: issue["state"],
updated_at: issue["updated_at"],
author_id: gl_user_id(project, issue["author"]["id"])
)
end end
comments.each do |comment|
body += @formatter.comment(comment["author"]["name"], comment["created_at"], comment["body"])
end
project.issues.create!(
iid: issue["iid"],
description: body,
title: issue["title"],
state: issue["state"],
author_id: gl_user_id(project, issue["author"]["id"])
)
end end
true true
......
...@@ -12,7 +12,10 @@ module Gitlab ...@@ -12,7 +12,10 @@ module Gitlab
json = IO.read(@path) json = IO.read(@path)
@tree_hash = ActiveSupport::JSON.decode(json) @tree_hash = ActiveSupport::JSON.decode(json)
@project_members = @tree_hash.delete('project_members') @project_members = @tree_hash.delete('project_members')
create_relations
ActiveRecord::Base.no_touching do
create_relations
end
rescue => e rescue => e
@shared.error(e) @shared.error(e)
false false
......
...@@ -30,6 +30,14 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do ...@@ -30,6 +30,14 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do
expect(Event.where.not(data: nil).first.data[:ref]).not_to be_empty expect(Event.where.not(data: nil).first.data[:ref]).not_to be_empty
end end
it 'preserves updated_at on issues' do
restored_project_json
issue = Issue.where(description: 'Aliquam enim illo et possimus.').first
expect(issue.reload.updated_at.to_s).to eq('2016-06-14 15:02:47 UTC')
end
context 'event at forth level of the tree' do context 'event at forth level of the tree' do
let(:event) { Event.where(title: 'test levels').first } let(:event) { Event.where(title: 'test levels').first }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment