summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/helpers/labels_helper.rb2
-rw-r--r--app/models/note.rb30
-rw-r--r--app/services/issuable_base_service.rb5
-rw-r--r--app/services/issues/update_service.rb7
-rw-r--r--app/services/merge_requests/update_service.rb10
5 files changed, 53 insertions, 1 deletions
diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb
index 19d688c4bb8..add0fef512e 100644
--- a/app/helpers/labels_helper.rb
+++ b/app/helpers/labels_helper.rb
@@ -7,7 +7,7 @@ module LabelsHelper
label_color = label.color || Label::DEFAULT_COLOR
text_color = text_color_for_bg(label_color)
- content_tag :span, class: 'label color-label', style: "background:#{label_color};color:#{text_color}" do
+ content_tag :span, class: 'label color-label', style: "background-color:#{label_color};color:#{text_color}" do
label.name
end
end
diff --git a/app/models/note.rb b/app/models/note.rb
index 39fe421fd7a..ccd9783e7d4 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -121,6 +121,36 @@ class Note < ActiveRecord::Base
})
end
+ def create_labels_change_note(noteable, project, author, added_labels, removed_labels)
+ labels_count = added_labels.count + removed_labels.count
+ added_labels = added_labels.map{ |label| "~#{label.id}" }.join(' ')
+ removed_labels = removed_labels.map{ |label| "~#{label.id}" }.join(' ')
+ message = ''
+
+ if added_labels.present?
+ message << "added #{added_labels}"
+ end
+
+ if added_labels.present? && removed_labels.present?
+ message << ' and '
+ end
+
+ if removed_labels.present?
+ message << "removed #{removed_labels}"
+ end
+
+ message << ' ' << 'label'.pluralize(labels_count)
+ body = "_#{message.capitalize}_"
+
+ create(
+ noteable: noteable,
+ project: project,
+ author: author,
+ note: body,
+ system: true
+ )
+ end
+
def create_new_commits_note(noteable, project, author, commits)
commits_text = ActionController::Base.helpers.pluralize(commits.size, 'new commit')
body = "Added #{commits_text}:\n\n"
diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb
index e3371ec3c1b..5e1906ad2ae 100644
--- a/app/services/issuable_base_service.rb
+++ b/app/services/issuable_base_service.rb
@@ -10,4 +10,9 @@ class IssuableBaseService < BaseService
Note.create_milestone_change_note(
issuable, issuable.project, current_user, issuable.milestone)
end
+
+ def create_labels_note(issuable, added_labels, removed_labels)
+ Note.create_labels_change_note(
+ issuable, issuable.project, current_user, added_labels, removed_labels)
+ end
end
diff --git a/app/services/issues/update_service.rb b/app/services/issues/update_service.rb
index 83e413d7248..c61d67a7893 100644
--- a/app/services/issues/update_service.rb
+++ b/app/services/issues/update_service.rb
@@ -14,10 +14,17 @@ module Issues
issue.update_nth_task(params[:task_num].to_i, false)
end
+ old_labels = issue.labels.to_a
+
if params.present? && issue.update_attributes(params.except(:state_event,
:task_num))
issue.reset_events_cache
+ if issue.labels != old_labels
+ create_labels_note(
+ issue, issue.labels - old_labels, old_labels - issue.labels)
+ end
+
if issue.previous_changes.include?('milestone_id')
create_milestone_note(issue)
end
diff --git a/app/services/merge_requests/update_service.rb b/app/services/merge_requests/update_service.rb
index 10c401756eb..870b50bb60d 100644
--- a/app/services/merge_requests/update_service.rb
+++ b/app/services/merge_requests/update_service.rb
@@ -23,11 +23,21 @@ module MergeRequests
merge_request.update_nth_task(params[:task_num].to_i, false)
end
+ old_labels = merge_request.labels.to_a
+
if params.present? && merge_request.update_attributes(
params.except(:state_event, :task_num)
)
merge_request.reset_events_cache
+ if merge_request.labels != old_labels
+ create_labels_note(
+ merge_request,
+ merge_request.labels - old_labels,
+ old_labels - merge_request.labels
+ )
+ end
+
if merge_request.previous_changes.include?('milestone_id')
create_milestone_note(merge_request)
end