Commit 23b78718 authored by James Lopez's avatar James Lopez

Merge branch '19128-add-system-note-metadata-for-import-export' into 'master'

gitlab import/export: add support for system note metadata

See merge request gitlab-org/gitlab!27853
parents 1503495e f683c580
---
title: "Add support for system note metadata in project Import/Export"
merge_request: 27853
author: Melvin Vermeeren
type: added
......@@ -17,6 +17,7 @@ tree:
- notes:
- :author
- :award_emoji
- :system_note_metadata
- events:
- :push_event_payload
- label_links:
......@@ -47,6 +48,7 @@ tree:
- notes:
- :author
- :award_emoji
- :system_note_metadata
- events:
- :push_event_payload
- :suggestions
......@@ -323,6 +325,9 @@ excluded_attributes:
epic_issue:
- :epic_id
- :issue_id
system_note_metadata:
- :description_version_id
- :note_id
methods:
notes:
- :type
......
......@@ -2492,6 +2492,84 @@
"merge_user_id": null,
"merge_commit_sha": null,
"notes": [
{
"id": 669,
"note": "added 3 commits\n\n<ul><li>16ea4e20...074a2a32 - 2 commits from branch <code>master</code></li><li>ca223a02 - readme: fix typos</li></ul>\n\n[Compare with previous version](/group/project/merge_requests/1/diffs?diff_id=1189&start_sha=16ea4e207fb258fe4e9c73185a725207c9a4f3e1)",
"noteable_type": "MergeRequest",
"author_id": 26,
"created_at": "2020-03-28T12:47:33.461Z",
"updated_at": "2020-03-28T12:47:33.461Z",
"project_id": 5,
"attachment": {
"url": null
},
"line_code": null,
"commit_id": null,
"system": true,
"st_diff": null,
"updated_by_id": null,
"position": null,
"original_position": null,
"resolved_at": null,
"resolved_by_id": null,
"discussion_id": null,
"change_position": null,
"resolved_by_push": null,
"confidential": null,
"type": null,
"author": {
"name": "User 4"
},
"award_emoji": [],
"system_note_metadata": {
"id": 4789,
"commit_count": 3,
"action": "commit",
"created_at": "2020-03-28T12:47:33.461Z",
"updated_at": "2020-03-28T12:47:33.461Z"
},
"events": [],
"suggestions": []
},
{
"id": 670,
"note": "unmarked as a **Work In Progress**",
"noteable_type": "MergeRequest",
"author_id": 26,
"created_at": "2020-03-28T12:48:36.951Z",
"updated_at": "2020-03-28T12:48:36.951Z",
"project_id": 5,
"attachment": {
"url": null
},
"line_code": null,
"commit_id": null,
"system": true,
"st_diff": null,
"updated_by_id": null,
"position": null,
"original_position": null,
"resolved_at": null,
"resolved_by_id": null,
"discussion_id": null,
"change_position": null,
"resolved_by_push": null,
"confidential": null,
"type": null,
"author": {
"name": "User 4"
},
"award_emoji": [],
"system_note_metadata": {
"id": 4790,
"commit_count": null,
"action": "title",
"created_at": "2020-03-28T12:48:36.951Z",
"updated_at": "2020-03-28T12:48:36.951Z"
},
"events": [],
"suggestions": []
},
{
"id": 671,
"note": "Sit voluptatibus eveniet architecto quidem.",
......
......@@ -98,6 +98,46 @@
"priorities": []
}
}
],
"notes": [
{
"id": 20,
"note": "created merge request !1 to address this issue",
"noteable_type": "Issue",
"author_id": 1,
"created_at": "2020-03-28T01:37:42.307Z",
"updated_at": "2020-03-28T01:37:42.307Z",
"project_id": 8,
"attachment": {
"url": null
},
"line_code": null,
"commit_id": null,
"system": true,
"st_diff": null,
"updated_by_id": null,
"position": null,
"original_position": null,
"resolved_at": null,
"resolved_by_id": null,
"discussion_id": null,
"change_position": null,
"resolved_by_push": null,
"confidential": null,
"type": null,
"author": {
"name": "Author"
},
"award_emoji": [],
"system_note_metadata": {
"id": 21,
"commit_count": null,
"action": "merge",
"created_at": "2020-03-28T01:37:42.307Z",
"updated_at": "2020-03-28T01:37:42.307Z"
},
"events": []
}
]
}
],
......
......@@ -38,6 +38,7 @@ issues:
- vulnerability_links
- related_vulnerabilities
- user_mentions
- system_note_metadata
events:
- author
- project
......@@ -152,6 +153,7 @@ merge_requests:
- deployment_merge_requests
- deployments
- user_mentions
- system_note_metadata
external_pull_requests:
- project
merge_request_diff:
......@@ -620,3 +622,6 @@ epic:
epic_issue:
- epic
- issue
system_note_metadata:
- note
- description_version
......@@ -2,6 +2,10 @@
require 'spec_helper'
def match_mr1_note(content_regex)
MergeRequest.find_by(title: 'MR1').notes.select { |n| n.note.match(/#{content_regex}/)}.first
end
describe Gitlab::ImportExport::Project::TreeRestorer do
include ImportExport::CommonUtil
......@@ -74,10 +78,30 @@ describe Gitlab::ImportExport::Project::TreeRestorer do
context 'for a Merge Request' do
it 'does not import note_html' do
note_content = 'Sit voluptatibus eveniet architecto quidem'
merge_request_note = MergeRequest.find_by(title: 'MR1').notes.select { |n| n.note.match(/#{note_content}/)}.first
merge_request_note = match_mr1_note(note_content)
expect(merge_request_note.note_html).to match(/#{note_content}/)
end
context 'merge request system note metadata' do
it 'restores title action for unmark wip' do
merge_request_note = match_mr1_note('unmarked as a \\*\\*Work In Progress\\*\\*')
expect(merge_request_note.noteable_type).to eq('MergeRequest')
expect(merge_request_note.system).to eq(true)
expect(merge_request_note.system_note_metadata.action).to eq('title')
expect(merge_request_note.system_note_metadata.commit_count).to be_nil
end
it 'restores commit action and commit count for pushing 3 commits' do
merge_request_note = match_mr1_note('added 3 commits')
expect(merge_request_note.noteable_type).to eq('MergeRequest')
expect(merge_request_note.system).to eq(true)
expect(merge_request_note.system_note_metadata.action).to eq('commit')
expect(merge_request_note.system_note_metadata.commit_count).to eq(3)
end
end
end
end
......@@ -373,7 +397,8 @@ describe Gitlab::ImportExport::Project::TreeRestorer do
context 'notes' do
it 'has award emoji' do
award_emoji = MergeRequest.find_by_title('MR1').notes.first.award_emoji.first
merge_request_note = match_mr1_note('Sit voluptatibus eveniet architecto quidem')
award_emoji = merge_request_note.award_emoji.first
expect(award_emoji.name).to eq('tada')
end
......@@ -507,6 +532,16 @@ describe Gitlab::ImportExport::Project::TreeRestorer do
first_issue_labels: 1,
services: 1
it 'issue system note metadata restored successfully' do
note_content = 'created merge request !1 to address this issue'
note = project.issues.first.notes.select { |n| n.note.match(/#{note_content}/)}.first
expect(note.noteable_type).to eq('Issue')
expect(note.system).to eq(true)
expect(note.system_note_metadata.action).to eq('merge')
expect(note.system_note_metadata.commit_count).to be_nil
end
context 'when there is an existing build with build token' do
before do
create(:ci_build, token: 'abcd')
......
......@@ -113,6 +113,12 @@ describe Gitlab::ImportExport::Project::TreeSaver do
expect(saved_project_json['issues'].first['notes'].first['author']).not_to be_empty
end
it 'has system note metadata on issue comments' do
metadata = saved_project_json['issues'].first['notes'].first['system_note_metadata']
expect(metadata['action']).to eq('description')
end
it 'has project members' do
expect(saved_project_json['project_members']).not_to be_empty
end
......@@ -137,6 +143,13 @@ describe Gitlab::ImportExport::Project::TreeSaver do
expect(saved_project_json['merge_requests'].first['notes'].first['author']).not_to be_empty
end
it 'has system note metadata on merge requests comments' do
metadata = saved_project_json['merge_requests'].first['notes'].first['system_note_metadata']
expect(metadata['commit_count']).to eq(1)
expect(metadata['action']).to eq('commit')
end
it 'has pipeline stages' do
expect(saved_project_json.dig('ci_pipelines', 0, 'stages')).not_to be_empty
end
......@@ -314,14 +327,17 @@ describe Gitlab::ImportExport::Project::TreeSaver do
create(:commit_status, project: project, pipeline: ci_build.pipeline)
create(:milestone, project: project)
create(:discussion_note, noteable: issue, project: project)
create(:note, noteable: merge_request, project: project)
discussion_note = create(:discussion_note, noteable: issue, project: project)
mr_note = create(:note, noteable: merge_request, project: project)
create(:note, noteable: snippet, project: project)
create(:note_on_commit,
author: user,
project: project,
commit_id: ci_build.pipeline.sha)
create(:system_note_metadata, action: 'description', note: discussion_note)
create(:system_note_metadata, commit_count: 1, action: 'commit', note: mr_note)
create(:resource_label_event, label: project_label, issue: issue)
create(:resource_label_event, label: group_label, merge_request: merge_request)
......
......@@ -848,3 +848,9 @@ Epic:
EpicIssue:
- id
- relative_position
SystemNoteMetadata:
- id
- commit_count
- action
- created_at
- updated_at
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