Skip to content
Snippets Groups Projects
Commit 0875e792 authored by Bala Kumar's avatar Bala Kumar :two:
Browse files

Fix gitlab project imports releases having nil authors

Changelog: fixed
parent 13c20643
No related branches found
No related tags found
1 merge request!91994Fix gitlab project import from creating releases with empty authors
......@@ -89,6 +89,7 @@ def setup_models
when :'Ci::PipelineSchedule' then setup_pipeline_schedule
when :'ProtectedBranch::MergeAccessLevel' then setup_protected_branch_access_level
when :'ProtectedBranch::PushAccessLevel' then setup_protected_branch_access_level
when :releases then setup_release
end
update_project_references
......@@ -150,6 +151,14 @@ def setup_issue
@relation_hash['relative_position'] = compute_relative_position
end
def setup_release
# When author is not present for source release set the author as ghost user.
if @relation_hash['author_id'].blank?
@relation_hash['author_id'] = User.select(:id).ghost.id
end
end
def setup_pipeline_schedule
@relation_hash['active'] = false
end
......
......@@ -2361,14 +2361,53 @@
"releases": [
{
"id": 1,
"tag": "release-1.0",
"description": "Some release notes",
"project_id": 5,
"created_at": "2019-12-25T10:17:14.621Z",
"updated_at": "2019-12-25T10:17:14.621Z",
"author_id": null,
"name": "release-1.0",
"sha": "902de3a8bd5573f4a049b1457d28bc1592baaa2e",
"released_at": "2019-12-25T10:17:14.615Z",
"links": [
{
"id": 1,
"release_id": 1,
"url": "http://localhost/namespace6/project6/-/jobs/140463678/artifacts/download",
"name": "release-1.0.dmg",
"created_at": "2019-12-25T10:17:14.621Z",
"updated_at": "2019-12-25T10:17:14.621Z"
}
],
"milestone_releases": [
{
"milestone_id": 1349,
"release_id": 9172,
"milestone": {
"id": 1,
"title": "test milestone",
"project_id": 8,
"description": "test milestone",
"due_date": null,
"created_at": "2016-06-14T15:02:04.415Z",
"updated_at": "2016-06-14T15:02:04.415Z",
"state": "active",
"iid": 1
}
}
]
},
{
"id": 2,
"tag": "release-1.1",
"description": "Some release notes",
"project_id": 5,
"created_at": "2019-12-26T10:17:14.621Z",
"updated_at": "2019-12-26T10:17:14.621Z",
"author_id": 1,
"author_id": 16,
"name": "release-1.1",
"sha": "901de3a8bd5573f4a049b1457d28bc1592ba6bf9",
"sha": "902de3a8bd5573f4a049b1457d28bc1592ba6bg9",
"released_at": "2019-12-26T10:17:14.615Z",
"links": [
{
......@@ -2397,6 +2436,45 @@
}
}
]
},
{
"id": 3,
"tag": "release-1.2",
"description": "Some release notes",
"project_id": 5,
"created_at": "2019-12-27T10:17:14.621Z",
"updated_at": "2019-12-27T10:17:14.621Z",
"author_id": 1,
"name": "release-1.2",
"sha": "903de3a8bd5573f4a049b1457d28bc1592ba6bf9",
"released_at": "2019-12-27T10:17:14.615Z",
"links": [
{
"id": 1,
"release_id": 1,
"url": "http://localhost/namespace6/project6/-/jobs/140463678/artifacts/download",
"name": "release-1.2.dmg",
"created_at": "2019-12-27T10:17:14.621Z",
"updated_at": "2019-12-27T10:17:14.621Z"
}
],
"milestone_releases": [
{
"milestone_id": 1349,
"release_id": 9172,
"milestone": {
"id": 1,
"title": "test milestone",
"project_id": 8,
"description": "test milestone",
"due_date": null,
"created_at": "2016-06-14T15:02:04.415Z",
"updated_at": "2016-06-14T15:02:04.415Z",
"state": "active",
"iid": 1
}
}
]
}
],
"project_members": [
......
{"id":1,"tag":"release-1.1","description":"Some release notes","project_id":5,"created_at":"2019-12-26T10:17:14.621Z","updated_at":"2019-12-26T10:17:14.621Z","author_id":1,"name":"release-1.1","sha":"901de3a8bd5573f4a049b1457d28bc1592ba6bf9","released_at":"2019-12-26T10:17:14.615Z","links":[{"id":1,"release_id":1,"url":"http://localhost/namespace6/project6/-/jobs/140463678/artifacts/download","name":"release-1.1.dmg","created_at":"2019-12-26T10:17:14.621Z","updated_at":"2019-12-26T10:17:14.621Z"}],"milestone_releases":[{"milestone_id":1349,"release_id":9172,"milestone":{"id":1,"title":"test milestone","project_id":8,"description":"test milestone","due_date":null,"created_at":"2016-06-14T15:02:04.415Z","updated_at":"2016-06-14T15:02:04.415Z","state":"active","iid":1}}]}
{"id":1,"tag":"release-1.0","description":"Some release notes","project_id":5,"created_at":"2019-12-25T10:17:14.621Z","updated_at":"2019-12-25T10:17:14.621Z","author_id":null,"name":"release-1.0","sha":"901de3a8bd5573f4a049b1457d28bc1592baaa2e","released_at":"2019-12-25T10:17:14.615Z","links":[{"id":1,"release_id":1,"url":"http://localhost/namespace6/project6/-/jobs/140463678/artifacts/download","name":"release-1.0.dmg","created_at":"2019-12-25T10:17:14.621Z","updated_at":"2019-12-25T10:17:14.621Z"}],"milestone_releases":[{"milestone_id":1349,"release_id":9172,"milestone":{"id":1,"title":"test milestone","project_id":8,"description":"test milestone","due_date":null,"created_at":"2016-06-14T15:02:04.415Z","updated_at":"2016-06-14T15:02:04.415Z","state":"active","iid":1}}]}
{"id":2,"tag":"release-1.1","description":"Some release notes","project_id":5,"created_at":"2019-12-26T10:17:14.621Z","updated_at":"2019-12-26T10:17:14.621Z","author_id":16,"name":"release-1.1","sha":"902de3a8bd5573f4a049b1457d28bc1592ba6bg9","released_at":"2019-12-26T10:17:14.615Z","links":[{"id":1,"release_id":1,"url":"http://localhost/namespace6/project6/-/jobs/140463678/artifacts/download","name":"release-1.1.dmg","created_at":"2019-12-26T10:17:14.621Z","updated_at":"2019-12-26T10:17:14.621Z"}],"milestone_releases":[{"milestone_id":1349,"release_id":9172,"milestone":{"id":1,"title":"test milestone","project_id":8,"description":"test milestone","due_date":null,"created_at":"2016-06-14T15:02:04.415Z","updated_at":"2016-06-14T15:02:04.415Z","state":"active","iid":1}}]}
{"id":3,"tag":"release-1.2","description":"Some release notes","project_id":5,"created_at":"2019-12-27T10:17:14.621Z","updated_at":"2019-12-27T10:17:14.621Z","author_id":1,"name":"release-1.2","sha":"903de3a8bd5573f4a049b1457d28bc1592ba6bf9","released_at":"2019-12-27T10:17:14.615Z","links":[{"id":1,"release_id":1,"url":"http://localhost/namespace6/project6/-/jobs/140463678/artifacts/download","name":"release-1.2.dmg","created_at":"2019-12-27T10:17:14.621Z","updated_at":"2019-12-27T10:17:14.621Z"}],"milestone_releases":[{"milestone_id":1349,"release_id":9172,"milestone":{"id":1,"title":"test milestone","project_id":8,"description":"test milestone","due_date":null,"created_at":"2016-06-14T15:02:04.415Z","updated_at":"2016-06-14T15:02:04.415Z","state":"active","iid":1}}]}
......@@ -383,21 +383,52 @@ def match_mr1_note(content_regex)
end
end
it 'restores releases with links & milestones' do
release = @project.releases.last
link = release.links.last
context 'restores releases' do
it 'with links & milestones' do
release = @project.releases.last
link = release.links.last
aggregate_failures do
expect(release.tag).to eq('release-1.2')
expect(release.description).to eq('Some release notes')
expect(release.name).to eq('release-1.2')
expect(release.sha).to eq('903de3a8bd5573f4a049b1457d28bc1592ba6bf9')
expect(release.released_at).to eq('2019-12-27T10:17:14.615Z')
expect(release.milestone_releases.count).to eq(1)
expect(release.milestone_releases.first.milestone.title).to eq('test milestone')
expect(link.url).to eq('http://localhost/namespace6/project6/-/jobs/140463678/artifacts/download')
expect(link.name).to eq('release-1.2.dmg')
end
end
aggregate_failures do
expect(release.tag).to eq('release-1.1')
expect(release.description).to eq('Some release notes')
expect(release.name).to eq('release-1.1')
expect(release.sha).to eq('901de3a8bd5573f4a049b1457d28bc1592ba6bf9')
expect(release.released_at).to eq('2019-12-26T10:17:14.615Z')
expect(release.milestone_releases.count).to eq(1)
expect(release.milestone_releases.first.milestone.title).to eq('test milestone')
expect(link.url).to eq('http://localhost/namespace6/project6/-/jobs/140463678/artifacts/download')
expect(link.name).to eq('release-1.1.dmg')
context 'with author' do
it 'as ghost user when imported release author is empty' do
release = @project.releases.first
aggregate_failures do
expect(release.tag).to eq('release-1.0')
expect(release.author_id).to eq(User.select(:id).ghost.id)
end
end
it 'as existing member when imported release author is matched with existing user' do
release = @project.releases.second
aggregate_failures do
expect(release.tag).to eq('release-1.1')
expect(release.author_id).to eq(@existing_members.first.id)
end
end
it 'as import user when imported release author cannot be matched' do
release = @project.releases.last
aggregate_failures do
expect(release.tag).to eq('release-1.2')
expect(release.author_id).to eq(@user.id)
end
end
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment