Commit becc7af8 authored by Jason Goodman's avatar Jason Goodman Committed by Kamil Trzciński

Fixup name and updated_at in GitHub ReleasesImporter

Populate GitLab release name with GitHub release name
Populate GitLab release updated_at with GitHub created_at
  GitHub api does not provide updated_at
Refactor spec
parent 524eef7d
---
title: Set name and updated_at properly in GitHub ReleaseImporter
merge_request: 17020
author:
type: fixed
...@@ -32,10 +32,11 @@ module Gitlab ...@@ -32,10 +32,11 @@ module Gitlab
def build(release) def build(release)
{ {
name: release.name,
tag: release.tag_name, tag: release.tag_name,
description: description_for(release), description: description_for(release),
created_at: release.created_at, created_at: release.created_at,
updated_at: release.updated_at, updated_at: release.created_at,
released_at: release.published_at, released_at: release.published_at,
project_id: project.id project_id: project.id
} }
......
...@@ -4,17 +4,17 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do ...@@ -4,17 +4,17 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:client) { double(:client) } let(:client) { double(:client) }
let(:importer) { described_class.new(project, client) } let(:importer) { described_class.new(project, client) }
let(:github_release_name) { 'Initial Release' }
let(:created_at) { Time.new(2017, 1, 1, 12, 00) } let(:created_at) { Time.new(2017, 1, 1, 12, 00) }
let(:updated_at) { Time.new(2017, 1, 1, 12, 15) }
let(:released_at) { Time.new(2017, 1, 1, 12, 00) } let(:released_at) { Time.new(2017, 1, 1, 12, 00) }
let(:release) do let(:github_release) do
double( double(
:release, :github_release,
tag_name: '1.0', tag_name: '1.0',
name: github_release_name,
body: 'This is my release', body: 'This is my release',
created_at: created_at, created_at: created_at,
updated_at: updated_at,
published_at: released_at published_at: released_at
) )
end end
...@@ -25,7 +25,7 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do ...@@ -25,7 +25,7 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do
tag_name: '1.0', tag_name: '1.0',
description: 'This is my release', description: 'This is my release',
created_at: created_at, created_at: created_at,
updated_at: updated_at, updated_at: created_at,
released_at: released_at released_at: released_at
} }
...@@ -37,8 +37,8 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do ...@@ -37,8 +37,8 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do
end end
describe '#build_releases' do describe '#build_releases' do
it 'returns an Array containnig release rows' do it 'returns an Array containing release rows' do
expect(importer).to receive(:each_release).and_return([release]) expect(importer).to receive(:each_release).and_return([github_release])
rows = importer.build_releases rows = importer.build_releases
...@@ -49,13 +49,13 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do ...@@ -49,13 +49,13 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do
it 'does not create releases that already exist' do it 'does not create releases that already exist' do
create(:release, project: project, tag: '1.0', description: '1.0') create(:release, project: project, tag: '1.0', description: '1.0')
expect(importer).to receive(:each_release).and_return([release]) expect(importer).to receive(:each_release).and_return([github_release])
expect(importer.build_releases).to be_empty expect(importer.build_releases).to be_empty
end end
it 'uses a default release description if none is provided' do it 'uses a default release description if none is provided' do
expect(release).to receive(:body).and_return('') expect(github_release).to receive(:body).and_return('')
expect(importer).to receive(:each_release).and_return([release]) expect(importer).to receive(:each_release).and_return([github_release])
release = importer.build_releases.first release = importer.build_releases.first
...@@ -64,7 +64,7 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do ...@@ -64,7 +64,7 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do
end end
describe '#build' do describe '#build' do
let(:release_hash) { importer.build(release) } let(:release_hash) { importer.build(github_release) }
it 'returns the attributes of the release as a Hash' do it 'returns the attributes of the release as a Hash' do
expect(release_hash).to be_an_instance_of(Hash) expect(release_hash).to be_an_instance_of(Hash)
...@@ -88,13 +88,17 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do ...@@ -88,13 +88,17 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do
end end
it 'includes the updated timestamp' do it 'includes the updated timestamp' do
expect(release_hash[:updated_at]).to eq(updated_at) expect(release_hash[:updated_at]).to eq(created_at)
end
it 'includes the release name' do
expect(release_hash[:name]).to eq(github_release_name)
end end
end end
end end
describe '#each_release' do describe '#each_release' do
let(:release) { double(:release) } let(:github_release) { double(:github_release) }
before do before do
allow(project).to receive(:import_source).and_return('foo/bar') allow(project).to receive(:import_source).and_return('foo/bar')
...@@ -102,7 +106,7 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do ...@@ -102,7 +106,7 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do
allow(client) allow(client)
.to receive(:releases) .to receive(:releases)
.with('foo/bar') .with('foo/bar')
.and_return([release].to_enum) .and_return([github_release].to_enum)
end end
it 'returns an Enumerator' do it 'returns an Enumerator' do
...@@ -110,19 +114,19 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do ...@@ -110,19 +114,19 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do
end end
it 'yields every release to the Enumerator' do it 'yields every release to the Enumerator' do
expect(importer.each_release.next).to eq(release) expect(importer.each_release.next).to eq(github_release)
end end
end end
describe '#description_for' do describe '#description_for' do
it 'returns the description when present' do it 'returns the description when present' do
expect(importer.description_for(release)).to eq(release.body) expect(importer.description_for(github_release)).to eq(github_release.body)
end end
it 'returns a generated description when one is not present' do it 'returns a generated description when one is not present' do
allow(release).to receive(:body).and_return('') allow(github_release).to receive(:body).and_return('')
expect(importer.description_for(release)).to eq('Release for tag 1.0') expect(importer.description_for(github_release)).to eq('Release for tag 1.0')
end end
end end
end end
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