Commit 2dfd2198 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce

parents c32e5270 3c4f7f50
...@@ -16,7 +16,7 @@ v 7.8.0 (unreleased) ...@@ -16,7 +16,7 @@ v 7.8.0 (unreleased)
- Improve sorting logic in UI and API. Explicitly define what sorting method is used by default - Improve sorting logic in UI and API. Explicitly define what sorting method is used by default
- Allow more variations for commit messages closing issues (Julien Bianchi and Hannes Rosenögger) - Allow more variations for commit messages closing issues (Julien Bianchi and Hannes Rosenögger)
- Fix overflow at sidebar when have several itens - Fix overflow at sidebar when have several itens
- - Add notes for label changes in issue and merge requests
- Show tags in commit view (Hannes Rosenögger) - Show tags in commit view (Hannes Rosenögger)
- Only count a user's vote once on a merge request or issue (Michael Clarke) - Only count a user's vote once on a merge request or issue (Michael Clarke)
- -
......
...@@ -7,7 +7,7 @@ module LabelsHelper ...@@ -7,7 +7,7 @@ module LabelsHelper
label_color = label.color || Label::DEFAULT_COLOR label_color = label.color || Label::DEFAULT_COLOR
text_color = text_color_for_bg(label_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 label.name
end end
end end
......
...@@ -121,6 +121,36 @@ class Note < ActiveRecord::Base ...@@ -121,6 +121,36 @@ class Note < ActiveRecord::Base
}) })
end 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) def create_new_commits_note(noteable, project, author, commits)
commits_text = ActionController::Base.helpers.pluralize(commits.size, 'new commit') commits_text = ActionController::Base.helpers.pluralize(commits.size, 'new commit')
body = "Added #{commits_text}:\n\n" body = "Added #{commits_text}:\n\n"
......
...@@ -10,4 +10,9 @@ class IssuableBaseService < BaseService ...@@ -10,4 +10,9 @@ class IssuableBaseService < BaseService
Note.create_milestone_change_note( Note.create_milestone_change_note(
issuable, issuable.project, current_user, issuable.milestone) issuable, issuable.project, current_user, issuable.milestone)
end 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 end
...@@ -14,10 +14,17 @@ module Issues ...@@ -14,10 +14,17 @@ module Issues
issue.update_nth_task(params[:task_num].to_i, false) issue.update_nth_task(params[:task_num].to_i, false)
end end
old_labels = issue.labels.to_a
if params.present? && issue.update_attributes(params.except(:state_event, if params.present? && issue.update_attributes(params.except(:state_event,
:task_num)) :task_num))
issue.reset_events_cache 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') if issue.previous_changes.include?('milestone_id')
create_milestone_note(issue) create_milestone_note(issue)
end end
......
...@@ -23,11 +23,21 @@ module MergeRequests ...@@ -23,11 +23,21 @@ module MergeRequests
merge_request.update_nth_task(params[:task_num].to_i, false) merge_request.update_nth_task(params[:task_num].to_i, false)
end end
old_labels = merge_request.labels.to_a
if params.present? && merge_request.update_attributes( if params.present? && merge_request.update_attributes(
params.except(:state_event, :task_num) params.except(:state_event, :task_num)
) )
merge_request.reset_events_cache 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') if merge_request.previous_changes.include?('milestone_id')
create_milestone_note(merge_request) create_milestone_note(merge_request)
end end
......
...@@ -92,7 +92,7 @@ module Gitlab ...@@ -92,7 +92,7 @@ module Gitlab
allowed_tags = ActionView::Base.sanitized_allowed_tags allowed_tags = ActionView::Base.sanitized_allowed_tags
sanitize text.html_safe, sanitize text.html_safe,
attributes: allowed_attributes + %w(id class), attributes: allowed_attributes + %w(id class style),
tags: allowed_tags + %w(table tr td th) tags: allowed_tags + %w(table tr td th)
end end
...@@ -128,6 +128,7 @@ module Gitlab ...@@ -128,6 +128,7 @@ module Gitlab
(?<prefix>\W)? # Prefix (?<prefix>\W)? # Prefix
( # Reference ( # Reference
@(?<user>#{NAME_STR}) # User name @(?<user>#{NAME_STR}) # User name
|~(?<label>\d+) # Label ID
|(?<issue>([A-Z\-]+-)\d+) # JIRA Issue ID |(?<issue>([A-Z\-]+-)\d+) # JIRA Issue ID
|#{PROJ_STR}?\#(?<issue>([a-zA-Z\-]+-)?\d+) # Issue ID |#{PROJ_STR}?\#(?<issue>([a-zA-Z\-]+-)?\d+) # Issue ID
|#{PROJ_STR}?!(?<merge_request>\d+) # MR ID |#{PROJ_STR}?!(?<merge_request>\d+) # MR ID
...@@ -138,7 +139,7 @@ module Gitlab ...@@ -138,7 +139,7 @@ module Gitlab
(?<suffix>\W)? # Suffix (?<suffix>\W)? # Suffix
}x.freeze }x.freeze
TYPES = [:user, :issue, :merge_request, :snippet, :commit].freeze TYPES = [:user, :issue, :label, :merge_request, :snippet, :commit].freeze
def parse_references(text, project = @project) def parse_references(text, project = @project)
# parse reference links # parse reference links
...@@ -214,6 +215,19 @@ module Gitlab ...@@ -214,6 +215,19 @@ module Gitlab
end end
end end
def reference_label(identifier, project = @project, _ = nil)
if label = project.labels.find_by(id: identifier)
options = html_options.merge(
class: "gfm gfm-label #{html_options[:class]}"
)
link_to(
render_colored_label(label),
project_issues_path(project, label_name: label.name),
options
)
end
end
def reference_issue(identifier, project = @project, prefix_text = nil) def reference_issue(identifier, project = @project, prefix_text = nil)
if project.default_issues_tracker? if project.default_issues_tracker?
if project.issue_exists? identifier if project.issue_exists? identifier
......
module Gitlab module Gitlab
# Extract possible GFM references from an arbitrary String for further processing. # Extract possible GFM references from an arbitrary String for further processing.
class ReferenceExtractor class ReferenceExtractor
attr_accessor :users, :issues, :merge_requests, :snippets, :commits attr_accessor :users, :labels, :issues, :merge_requests, :snippets, :commits
include Markdown include Markdown
def initialize def initialize
@users, @issues, @merge_requests, @snippets, @commits = [], [], [], [], [] @users, @labels, @issues, @merge_requests, @snippets, @commits =
[], [], [], [], [], []
end end
def analyze(string, project) def analyze(string, project)
...@@ -22,6 +23,12 @@ module Gitlab ...@@ -22,6 +23,12 @@ module Gitlab
end.reject(&:nil?) end.reject(&:nil?)
end end
def labels_for(project = nil)
labels.map do |entry|
project.labels.where(id: entry[:id]).first
end.reject(&:nil?)
end
def issues_for(project = nil) def issues_for(project = nil)
issues.map do |entry| issues.map do |entry|
if should_lookup?(project, entry[:project]) if should_lookup?(project, entry[:project])
......
...@@ -5,6 +5,7 @@ describe Issues::UpdateService do ...@@ -5,6 +5,7 @@ describe Issues::UpdateService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(:issue) { create(:issue) } let(:issue) { create(:issue) }
let(:label) { create(:label) }
before do before do
project.team << [user, :master] project.team << [user, :master]
...@@ -18,7 +19,8 @@ describe Issues::UpdateService do ...@@ -18,7 +19,8 @@ describe Issues::UpdateService do
title: 'New title', title: 'New title',
description: 'Also please fix', description: 'Also please fix',
assignee_id: user2.id, assignee_id: user2.id,
state_event: 'close' state_event: 'close',
label_ids: [label.id]
} }
@issue = Issues::UpdateService.new(project, user, opts).execute(issue) @issue = Issues::UpdateService.new(project, user, opts).execute(issue)
...@@ -29,6 +31,8 @@ describe Issues::UpdateService do ...@@ -29,6 +31,8 @@ describe Issues::UpdateService do
it { @issue.title.should == 'New title' } it { @issue.title.should == 'New title' }
it { @issue.assignee.should == user2 } it { @issue.assignee.should == user2 }
it { @issue.should be_closed } it { @issue.should be_closed }
it { @issue.labels.count.should == 1 }
it { @issue.labels.first.title.should == 'Bug' }
it 'should send email to user2 about assign of new issue' do it 'should send email to user2 about assign of new issue' do
email = ActionMailer::Base.deliveries.last email = ActionMailer::Base.deliveries.last
...@@ -40,6 +44,11 @@ describe Issues::UpdateService do ...@@ -40,6 +44,11 @@ describe Issues::UpdateService do
note = @issue.notes.last note = @issue.notes.last
note.note.should include "Reassigned to \@#{user2.username}" note.note.should include "Reassigned to \@#{user2.username}"
end end
it 'should create system note about issue label edit' do
note = @issue.notes[1]
note.note.should include "Added ~#{label.id} label"
end
end end
end end
end end
...@@ -5,6 +5,7 @@ describe MergeRequests::UpdateService do ...@@ -5,6 +5,7 @@ describe MergeRequests::UpdateService do
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(:merge_request) { create(:merge_request, :simple) } let(:merge_request) { create(:merge_request, :simple) }
let(:project) { merge_request.project } let(:project) { merge_request.project }
let(:label) { create(:label) }
before do before do
project.team << [user, :master] project.team << [user, :master]
...@@ -18,7 +19,8 @@ describe MergeRequests::UpdateService do ...@@ -18,7 +19,8 @@ describe MergeRequests::UpdateService do
title: 'New title', title: 'New title',
description: 'Also please fix', description: 'Also please fix',
assignee_id: user2.id, assignee_id: user2.id,
state_event: 'close' state_event: 'close',
label_ids: [label.id]
} }
end end
...@@ -35,6 +37,8 @@ describe MergeRequests::UpdateService do ...@@ -35,6 +37,8 @@ describe MergeRequests::UpdateService do
it { @merge_request.title.should == 'New title' } it { @merge_request.title.should == 'New title' }
it { @merge_request.assignee.should == user2 } it { @merge_request.assignee.should == user2 }
it { @merge_request.should be_closed } it { @merge_request.should be_closed }
it { @merge_request.labels.count.should == 1 }
it { @merge_request.labels.first.title.should == 'Bug' }
it 'should execute hooks with update action' do it 'should execute hooks with update action' do
expect(service).to have_received(:execute_hooks). expect(service).to have_received(:execute_hooks).
...@@ -51,6 +55,11 @@ describe MergeRequests::UpdateService do ...@@ -51,6 +55,11 @@ describe MergeRequests::UpdateService do
note = @merge_request.notes.last note = @merge_request.notes.last
note.note.should include "Reassigned to \@#{user2.username}" note.note.should include "Reassigned to \@#{user2.username}"
end end
it 'should create system note about merge_request label edit' do
note = @merge_request.notes[1]
note.note.should include "Added ~#{label.id} label"
end
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