Commit e37b3d15 authored by Stan Hu's avatar Stan Hu

GitHub import: Handle nil published_at dates

GitHub releases will have a null `published_at` field if they are in
the draft state. If no date is available in the release, just fill
it in with today's date since our database schema requires this.

Closes https://gitlab.com/gitlab-org/gitlab/issues/33732
parent 307af045
---
title: 'GitHub import: Handle nil published_at dates'
merge_request: 18355
author:
type: fixed
...@@ -37,7 +37,8 @@ module Gitlab ...@@ -37,7 +37,8 @@ module Gitlab
description: description_for(release), description: description_for(release),
created_at: release.created_at, created_at: release.created_at,
updated_at: release.created_at, updated_at: release.created_at,
released_at: release.published_at, # Draft releases will have a null published_at
released_at: release.published_at || Time.current,
project_id: project.id project_id: project.id
} }
end end
......
...@@ -10,7 +10,8 @@ module Gitlab ...@@ -10,7 +10,8 @@ module Gitlab
name: raw_data.name, name: raw_data.name,
description: raw_data.body, description: raw_data.body,
created_at: raw_data.created_at, created_at: raw_data.created_at,
released_at: raw_data.published_at, # Draft releases will have a null published_at
released_at: raw_data.published_at || Time.current,
updated_at: raw_data.created_at updated_at: raw_data.created_at
} }
end end
......
...@@ -34,6 +34,22 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do ...@@ -34,6 +34,22 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do
importer.execute importer.execute
end end
it 'imports draft releases' do
release_double = double(
name: 'Test',
body: 'This is description',
tag_name: '1.0',
description: 'This is my release',
created_at: created_at,
updated_at: created_at,
published_at: nil
)
expect(importer).to receive(:each_release).and_return([release_double])
expect { importer.execute }.to change { Release.count }.by(1)
end
end end
describe '#build_releases' do describe '#build_releases' do
......
...@@ -37,6 +37,14 @@ describe Gitlab::LegacyGithubImport::ReleaseFormatter do ...@@ -37,6 +37,14 @@ describe Gitlab::LegacyGithubImport::ReleaseFormatter do
expect(release.attributes).to eq(expected) expect(release.attributes).to eq(expected)
end end
context 'with a nil published_at date' do
let(:published_at) { nil }
it 'inserts a timestamp for released_at' do
expect(release.attributes[:released_at]).to be_a(Time)
end
end
end end
describe '#valid' do describe '#valid' do
......
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