Add system note on description change of issue/merge request

This commit is contained in:
blackst0ne 2017-04-29 10:54:37 +11:00
parent 4faa65d838
commit 323596f68e
8 changed files with 47 additions and 3 deletions

View File

@ -1,6 +1,7 @@
module SystemNoteHelper
ICON_NAMES_BY_ACTION = {
'commit' => 'icon_commit',
'description' => 'icon_edit',
'merge' => 'icon_merge',
'merged' => 'icon_merged',
'opened' => 'icon_status_open',

View File

@ -1,6 +1,6 @@
class SystemNoteMetadata < ActiveRecord::Base
ICON_TYPES = %w[
commit merge confidential visible label assignee cross_reference
commit description merge confidential visible label assignee cross_reference
title time_tracking branch milestone discussion task moved opened closed merged
].freeze

View File

@ -24,6 +24,10 @@ class IssuableBaseService < BaseService
issuable, issuable.project, current_user, old_title)
end
def create_description_change_note(issuable)
SystemNoteService.change_description(issuable, issuable.project, current_user)
end
def create_branch_change_note(issuable, branch_type, old_branch, new_branch)
SystemNoteService.change_branch(
issuable, issuable.project, current_user, branch_type,
@ -289,6 +293,10 @@ class IssuableBaseService < BaseService
create_title_change_note(issuable, issuable.previous_changes['title'].first)
end
if issuable.previous_changes.include?('description')
create_description_change_note(issuable)
end
if issuable.previous_changes.include?('description') && issuable.tasks?
create_task_status_note(issuable)
end

View File

@ -261,6 +261,23 @@ module SystemNoteService
create_note(NoteSummary.new(noteable, project, author, body, action: 'title'))
end
# Called when the description of a Noteable is changed
#
# noteable - Noteable object that responds to `description`
# project - Project owning noteable
# author - User performing the change
#
# Example Note text:
#
# "changed the description"
#
# Returns the created Note object
def change_description(noteable, project, author)
body = "changed the description"
create_note(NoteSummary.new(noteable, project, author, body, action: 'description'))
end
# Called when the confidentiality changes
#
# issue - Issue object

View File

@ -61,7 +61,7 @@
= markdown_field(@issue, :description)
%textarea.hidden.js-task-list-field
= @issue.description
= edited_time_ago_with_tooltip(@issue, placement: 'bottom', html_class: 'issue_edited_ago')
= edited_time_ago_with_tooltip(@issue, placement: 'bottom', html_class: 'issue_edited_ago', include_author: true)
#merge-requests{ data: { url: referenced_merge_requests_namespace_project_issue_url(@project.namespace, @project, @issue) } }
// This element is filled in using JavaScript.

View File

@ -10,4 +10,4 @@
%textarea.hidden.js-task-list-field
= @merge_request.description
= edited_time_ago_with_tooltip(@merge_request, placement: 'bottom')
= edited_time_ago_with_tooltip(@merge_request, placement: 'bottom', include_author: true)

View File

@ -0,0 +1,4 @@
---
title: Add system note on description change of issue/merge request
merge_request: 10392
author: blackst0ne

View File

@ -292,6 +292,20 @@ describe SystemNoteService, services: true do
end
end
describe '.change_description' do
subject { described_class.change_description(noteable, project, author) }
context 'when noteable responds to `description`' do
it_behaves_like 'a system note' do
let(:action) { 'description' }
end
it 'sets the note text' do
expect(subject.note).to eq 'changed the description'
end
end
end
describe '.change_issue_confidentiality' do
subject { described_class.change_issue_confidentiality(noteable, project, author) }