diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-07-30 14:35:33 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-07-30 14:35:33 +0400 |
commit | 0d715bcd812ca6c99884e117f28a400669aa8e57 (patch) | |
tree | 5690fa43c790af40c51441425b9d8be068d4139d /app | |
parent | 4f07a6a99cab8f8ae3ad0a786a6cc9a837955c08 (diff) | |
parent | 4d373005968b8269a8d2fe56b7776820396127a4 (diff) |
Merge branch 'mr-on-fork' of https://github.com/karlhungus/gitlabhq into karlhungus-mr-on-fork
Conflicts:
app/views/projects/commit/show.html.haml
app/views/projects/compare/show.html.haml
app/views/projects/merge_requests/branch_from.js.haml
Diffstat (limited to 'app')
47 files changed, 410 insertions, 209 deletions
diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index abbd6871008..2b3382dd8bb 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -400,6 +400,18 @@ img.emoji { margin-bottom: 10px; } +.label-project { + @include border-radius(4px); + padding: 2px 4px; + border: none; + font-size: 14px; + background: #474D57; + color: #fff; + font-family: $monospace_font; + text-shadow: 0 1px 1px #111; + font-weight: normal; +} + .group-name { font-size: 14px; line-height: 24px; diff --git a/app/contexts/filter_context.rb b/app/contexts/filter_context.rb index 401d19b31c8..e7f80e1a4e4 100644 --- a/app/contexts/filter_context.rb +++ b/app/contexts/filter_context.rb @@ -12,7 +12,7 @@ class FilterContext def apply_filter items if params[:project_id] - items = items.where(project_id: params[:project_id]) + items = items.by_project(params[:project_id]) end if params[:search].present? diff --git a/app/contexts/merge_requests_load_context.rb b/app/contexts/merge_requests_load_context.rb index fd44572c0eb..9eba81295a9 100644 --- a/app/contexts/merge_requests_load_context.rb +++ b/app/contexts/merge_requests_load_context.rb @@ -14,7 +14,7 @@ class MergeRequestsLoadContext < BaseContext end merge_requests = merge_requests.page(params[:page]).per(20) - merge_requests = merge_requests.includes(:author, :project).order("created_at desc") + merge_requests = merge_requests.includes(:author, :source_project, :target_project).order("created_at desc") # Filter by specific assignee_id (or lack thereof)? if params[:assignee_id].present? diff --git a/app/contexts/search_context.rb b/app/contexts/search_context.rb index 22cda709f69..4b1be84a2e1 100644 --- a/app/contexts/search_context.rb +++ b/app/contexts/search_context.rb @@ -19,7 +19,7 @@ class SearchContext if params[:search_code].present? result[:blobs] = project.repository.search_files(query, params[:repository_ref]) unless project.empty_repo? else - result[:merge_requests] = MergeRequest.where(project_id: project_ids).search(query).limit(10) + result[:merge_requests] = MergeRequest.in_projects(project_ids).search(query).limit(10) result[:issues] = Issue.where(project_id: project_ids).search(query).limit(10) result[:wiki_pages] = [] end diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 33c1a1feff7..dd1f8cee873 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -24,8 +24,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController format.html format.js - format.diff { render text: @merge_request.to_diff } - format.patch { render text: @merge_request.to_patch } + format.diff { render text: @merge_request.to_diff(current_user) } + format.patch { render text: @merge_request.to_patch(current_user) } end end @@ -33,27 +33,37 @@ class Projects::MergeRequestsController < Projects::ApplicationController @commit = @merge_request.last_commit @comments_allowed = @reply_allowed = true - @comments_target = { noteable_type: 'MergeRequest', - noteable_id: @merge_request.id } + @comments_target = {noteable_type: 'MergeRequest', + noteable_id: @merge_request.id} @line_notes = @merge_request.notes.where("line_code is not null") end def new - @merge_request = @project.merge_requests.new(params[:merge_request]) + @merge_request = MergeRequest.new(params[:merge_request]) + @merge_request.source_project = @project unless @merge_request.source_project + @merge_request.target_project = @project unless @merge_request.target_project + @target_branches = @merge_request.target_project.nil? ? [] : @merge_request.target_project.repository.branch_names + @source_project = @merge_request.source_project + @merge_request end def edit + @source_project = @merge_request.source_project + @target_project = @merge_request.target_project + @target_branches = @merge_request.target_project.repository.branch_names end def create - @merge_request = @project.merge_requests.new(params[:merge_request]) + @merge_request = MergeRequest.new(params[:merge_request]) @merge_request.author = current_user - + @target_branches ||= [] if @merge_request.save @merge_request.reload_code - redirect_to [@project, @merge_request], notice: 'Merge request was successfully created.' + redirect_to [@merge_request.target_project, @merge_request], notice: 'Merge request was successfully created.' else - render "new" + @source_project = @merge_request.source_project + @target_project = @merge_request.target_project + render action: "new" end end @@ -61,7 +71,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController if @merge_request.update_attributes(params[:merge_request].merge(author_id_of_changes: current_user.id)) @merge_request.reload_code @merge_request.mark_as_unchecked - redirect_to [@project, @merge_request], notice: 'Merge request was successfully updated.' + redirect_to [@merge_request.target_project, @merge_request], notice: 'Merge request was successfully updated.' else render "edit" end @@ -89,22 +99,35 @@ class Projects::MergeRequestsController < Projects::ApplicationController end def branch_from + #This is always source + @source_project = @merge_request.nil? ? @project : @merge_request.source_project @commit = @repository.commit(params[:ref]) end def branch_to - @commit = @repository.commit(params[:ref]) + @target_project = selected_target_project + @commit = @target_project.repository.commit(params[:ref]) + end + + def update_branches + @target_project = selected_target_project + @target_branches = @target_project.repository.branch_names + @target_branches end def ci_status status = project.gitlab_ci_service.commit_status(merge_request.last_commit.sha) - response = { status: status } + response = {status: status} render json: response end protected + def selected_target_project + ((@project.id.to_s == params[:target_project_id]) || @project.forked_project_link.nil?) ? @project : @project.forked_project_link.forked_from_project + end + def merge_request @merge_request ||= @project.merge_requests.find(params[:id]) end @@ -123,11 +146,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController def validates_merge_request # Show git not found page if target branch doesn't exist - return invalid_mr unless @project.repository.branch_names.include?(@merge_request.target_branch) + return invalid_mr unless @merge_request.target_project.repository.branch_names.include?(@merge_request.target_branch) # Show git not found page if source branch doesn't exist # and there is no saved commits between source & target branch - return invalid_mr if !@project.repository.branch_names.include?(@merge_request.source_branch) && @merge_request.commits.blank? + return invalid_mr if !@merge_request.source_project.repository.branch_names.include?(@merge_request.source_branch) && @merge_request.commits.blank? end def define_show_vars diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index 111e1cda19c..20a2443f523 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -108,8 +108,8 @@ module CommitsHelper end end - def commit_to_html commit - escape_javascript(render 'projects/commits/commit', commit: commit) + def commit_to_html commit, project + escape_javascript(render 'projects/commits/commit', commit: commit, project: project) unless commit.nil? end def diff_line_content(line) diff --git a/app/helpers/merge_requests_helper.rb b/app/helpers/merge_requests_helper.rb index 05ffec066f8..4ba48aa4339 100644 --- a/app/helpers/merge_requests_helper.rb +++ b/app/helpers/merge_requests_helper.rb @@ -2,14 +2,27 @@ module MergeRequestsHelper def new_mr_path_from_push_event(event) new_project_merge_request_path( event.project, - merge_request: { - source_branch: event.branch_name, - target_branch: event.project.repository.root_ref, - title: event.branch_name.titleize - } + new_mr_from_push_event(event, event.project) ) end + def new_mr_path_for_fork_from_push_event(event) + new_project_merge_request_path( + event.project, + new_mr_from_push_event(event, event.project.forked_from_project) + ) + end + + def new_mr_from_push_event(event, target_project) + return :merge_request => { + source_project_id: event.project.id, + target_project_id: target_project.id, + source_branch: event.branch_name, + target_branch: target_project.repository.root_ref, + title: event.branch_name.titleize + } + end + def mr_css_classes mr classes = "merge-request" classes << " closed" if mr.closed? @@ -18,6 +31,14 @@ module MergeRequestsHelper end def ci_build_details_path merge_request - merge_request.project.gitlab_ci_service.build_page(merge_request.last_commit.sha) + merge_request.source_project.gitlab_ci_service.build_page(merge_request.last_commit.sha) + end + + def merge_path_description(merge_request, separator) + if merge_request.for_fork? + "Project:Branches: #{@merge_request.source_project.path_with_namespace}:#{@merge_request.source_branch} #{separator} #{@merge_request.target_project.path_with_namespace}:#{@merge_request.target_branch}" + else + "Branches: #{@merge_request.source_branch} #{separator} #{@merge_request.target_branch}" + end end end diff --git a/app/mailers/emails/merge_requests.rb b/app/mailers/emails/merge_requests.rb index de47903c0d4..cf6950966e1 100644 --- a/app/mailers/emails/merge_requests.rb +++ b/app/mailers/emails/merge_requests.rb @@ -2,28 +2,65 @@ module Emails module MergeRequests def new_merge_request_email(recipient_id, merge_request_id) @merge_request = MergeRequest.find(merge_request_id) - @project = @merge_request.project mail(to: recipient(recipient_id), subject: subject("new merge request !#{@merge_request.id}", @merge_request.title)) end def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id) @merge_request = MergeRequest.find(merge_request_id) @previous_assignee = User.find_by_id(previous_assignee_id) if previous_assignee_id - @project = @merge_request.project mail(to: recipient(recipient_id), subject: subject("changed merge request !#{@merge_request.id}", @merge_request.title)) end def closed_merge_request_email(recipient_id, merge_request_id, updated_by_user_id) @merge_request = MergeRequest.find(merge_request_id) - @project = @merge_request.project @updated_by = User.find updated_by_user_id mail(to: recipient(recipient_id), subject: subject("Closed merge request !#{@merge_request.id}", @merge_request.title)) end def merged_merge_request_email(recipient_id, merge_request_id) @merge_request = MergeRequest.find(merge_request_id) - @project = @merge_request.project mail(to: recipient(recipient_id), subject: subject("Accepted merge request !#{@merge_request.id}", @merge_request.title)) end end + + # Over rides default behavour to show source/target + # Formats arguments into a String suitable for use as an email subject + # + # extra - Extra Strings to be inserted into the subject + # + # Examples + # + # >> subject('Lorem ipsum') + # => "GitLab Merge Request | Lorem ipsum" + # + # # Automatically inserts Project name: + # Forked MR + # => source project => <Project id: 1, name: "Ruby on Rails", path: "ruby_on_rails", ...> + # => target project => <Project id: 2, name: "My Ror", path: "ruby_on_rails", ...> + # => source branch => source + # => target branch => target + # >> subject('Lorem ipsum') + # => "GitLab Merge Request | Ruby on Rails:source >> My Ror:target | Lorem ipsum " + # + # Non Forked MR + # => source project => <Project id: 1, name: "Ruby on Rails", path: "ruby_on_rails", ...> + # => target project => <Project id: 1, name: "Ruby on Rails", path: "ruby_on_rails", ...> + # => source branch => source + # => target branch => target + # >> subject('Lorem ipsum') + # => "GitLab Merge Request | Ruby on Rails | source >> target | Lorem ipsum " + # # Accepts multiple arguments + # >> subject('Lorem ipsum', 'Dolor sit amet') + # => "GitLab Merge Request | Lorem ipsum | Dolor sit amet" + def subject(*extra) + subject = "GitLab Merge Request |" + if @merge_request.for_fork? + subject << "#{@merge_request.source_project.name_with_namespace}:#{merge_request.source_branch} >> #{@merge_request.target_project.name_with_namespace}:#{merge_request.target_branch}" + else + subject << "#{@merge_request.source_project.name_with_namespace} | #{merge_request.source_branch} >> #{merge_request.target_branch}" + end + subject << " | " + extra.join(' | ') if extra.present? + subject + end + end diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb index a5aa97ab13d..7890ca7793b 100644 --- a/app/mailers/notify.rb +++ b/app/mailers/notify.rb @@ -6,6 +6,7 @@ class Notify < ActionMailer::Base add_template_helper ApplicationHelper add_template_helper GitlabMarkdownHelper + add_template_helper MergeRequestsHelper default_url_options[:host] = Gitlab.config.gitlab.host default_url_options[:protocol] = Gitlab.config.gitlab.protocol diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 8868e818daa..88de1a037aa 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -9,19 +9,14 @@ module Issuable include Mentionable included do - belongs_to :project belongs_to :author, class_name: "User" belongs_to :assignee, class_name: "User" belongs_to :milestone has_many :notes, as: :noteable, dependent: :destroy - validates :project, presence: true validates :author, presence: true validates :title, presence: true, length: { within: 0..255 } - scope :opened, -> { with_state(:opened) } - scope :closed, -> { with_state(:closed) } - scope :of_group, ->(group) { where(project_id: group.project_ids) } scope :assigned_to, ->(u) { where(assignee_id: u.id)} scope :recent, -> { order("created_at DESC") } scope :assigned, -> { where("assignee_id IS NOT NULL") } diff --git a/app/models/issue.rb b/app/models/issue.rb index f56928891dc..c171941928c 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -17,8 +17,18 @@ # class Issue < ActiveRecord::Base + include Issuable + belongs_to :project + validates :project, presence: true + + scope :of_group, ->(group) { where(project_id: group.project_ids) } + scope :of_user_team, ->(team) { where(project_id: team.project_ids, assignee_id: team.member_ids) } + scope :opened, -> { with_state(:opened) } + scope :closed, -> { with_state(:closed) } + scope :by_project, ->(project_id) {where(project_id:project_id)} + attr_accessible :title, :assignee_id, :position, :description, :milestone_id, :label_list, :author_id_of_changes, :state_event diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 2a476355404..703032649b9 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -2,30 +2,35 @@ # # Table name: merge_requests # -# id :integer not null, primary key -# target_branch :string(255) not null -# source_branch :string(255) not null -# project_id :integer not null -# author_id :integer -# assignee_id :integer -# title :string(255) -# created_at :datetime -# updated_at :datetime -# st_commits :text(2147483647) -# st_diffs :text(2147483647) -# milestone_id :integer -# state :string(255) -# merge_status :string(255) +# id :integer not null, primary key +# target_project_id :integer not null +# target_branch :string(255) not null +# source_project_id :integer not null +# source_branch :string(255) not null +# author_id :integer +# assignee_id :integer +# title :string(255) +# created_at :datetime +# updated_at :datetime +# st_commits :text(2147483647) +# st_diffs :text(2147483647) +# milestone_id :integer +# state :string(255) +# merge_status :string(255) # require Rails.root.join("app/models/commit") require Rails.root.join("lib/static_model") class MergeRequest < ActiveRecord::Base + include Issuable - attr_accessible :title, :assignee_id, :target_branch, :source_branch, :milestone_id, - :author_id_of_changes, :state_event + belongs_to :target_project, foreign_key: :target_project_id, class_name: "Project" + belongs_to :source_project, foreign_key: :source_project_id, class_name: "Project" + + attr_accessible :title, :assignee_id, :source_project_id, :source_branch, :target_project_id, :target_branch, :milestone_id, :author_id_of_changes, :state_event + attr_accessor :should_remove_source_branch @@ -74,30 +79,37 @@ class MergeRequest < ActiveRecord::Base serialize :st_commits serialize :st_diffs + validates :source_project, presence: true validates :source_branch, presence: true + validates :target_project, presence: true validates :target_branch, presence: true - validate :validate_branches + validate :validate_branches + scope :of_group, ->(group) { where("source_project_id in (:group_project_ids) OR target_project_id in (:group_project_ids)", group_project_ids: group.project_ids) } + scope :of_user_team, ->(team) { where("(source_project_id in (:team_project_ids) OR target_project_id in (:team_project_ids) AND assignee_id in (:team_member_ids))", team_project_ids: team.project_ids, team_member_ids: team.member_ids) } + scope :opened, -> { with_state(:opened) } + scope :closed, -> { with_state(:closed) } scope :merged, -> { with_state(:merged) } - scope :by_branch, ->(branch_name) { where("source_branch LIKE :branch OR target_branch LIKE :branch", branch: branch_name) } + scope :by_branch, ->(branch_name) { where("(source_branch LIKE :branch) OR (target_branch LIKE :branch)", branch: branch_name) } scope :cared, ->(user) { where('assignee_id = :user OR author_id = :user', user: user.id) } scope :by_milestone, ->(milestone) { where(milestone_id: milestone) } - + scope :by_project, ->(project_id) { where("source_project_id = :project_id OR target_project_id = :project_id", project_id: project_id) } + scope :in_projects, ->(project_ids) { where("source_project_id in (:project_ids) OR target_project_id in (:project_ids)", project_ids: project_ids) } # Closed scope for merge request should return # both merged and closed mr's scope :closed, -> { with_states(:closed, :merged) } def validate_branches - if target_branch == source_branch - errors.add :branch_conflict, "You can not use same branch for source and target branches" + if target_project==source_project && target_branch == source_branch + errors.add :branch_conflict, "You can not use same project/branch for source and target" end if opened? || reopened? - similar_mrs = self.project.merge_requests.where(source_branch: source_branch, target_branch: target_branch).opened + similar_mrs = self.target_project.merge_requests.where(source_branch: source_branch, target_branch: target_branch, source_project_id: source_project.id).opened similar_mrs = similar_mrs.where('id not in (?)', self.id) if self.id if similar_mrs.any? - errors.add :base, "There is already an open merge request for this branches" + errors.add :base, "Cannot Create: This merge request already exists: #{similar_mrs.pluck(:title)}" end end end @@ -137,7 +149,13 @@ class MergeRequest < ActiveRecord::Base end def unmerged_diffs - project.repository.diffs_between(source_branch, target_branch) + if for_fork? + diffs = Gitlab::Satellite::MergeAction.new(author, self).diffs_between_satellite + else + diffs = target_project.repository.diffs_between(source_branch, target_branch) + end + diffs ||= [] + diffs end def last_commit @@ -145,11 +163,11 @@ class MergeRequest < ActiveRecord::Base end def merge_event - self.project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::MERGED).last + self.target_project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::MERGED).last end def closed_event - self.project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::CLOSED).last + self.target_project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::CLOSED).last end def commits @@ -165,15 +183,23 @@ class MergeRequest < ActiveRecord::Base if opened? && unmerged_commits.any? self.st_commits = dump_commits(unmerged_commits) save + end commits end def unmerged_commits - self.project.repository. - commits_between(self.target_branch, self.source_branch). + if for_fork? + commits = Gitlab::Satellite::MergeAction.new(self.author, self).commits_between + else + commits = target_project.repository.commits_between(self.target_branch, self.source_branch) + end + if commits.present? + commits = Commit.decorate(commits). sort_by(&:created_at). reverse + end + commits end def merge!(user_id) @@ -199,21 +225,29 @@ class MergeRequest < ActiveRecord::Base # Returns the raw diff for this merge request # # see "git diff" - def to_diff - project.repo.git.native(:diff, {timeout: 30, raise: true}, "#{target_branch}...#{source_branch}") + def to_diff(current_user) + Gitlab::Satellite::MergeAction.new(current_user, self).diff_in_satellite end # Returns the commit as a series of email patches. # # see "git format-patch" - def to_patch - project.repo.git.format_patch({timeout: 30, raise: true, stdout: true}, "#{target_branch}..#{source_branch}") + def to_patch(current_user) + Gitlab::Satellite::MergeAction.new(current_user, self).format_patch end def last_commit_short_sha @last_commit_short_sha ||= last_commit.sha[0..10] end + def for_fork? + target_project != source_project + end + + def disallow_source_branch_removal? + (source_project.root_ref? source_branch) || for_fork? + end + private def dump_commits(commits) diff --git a/app/models/note.rb b/app/models/note.rb index c23aab03bcc..fecee950713 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -42,18 +42,18 @@ class Note < ActiveRecord::Base # Scopes scope :for_commit_id, ->(commit_id) { where(noteable_type: "Commit", commit_id: commit_id) } - scope :inline, -> { where("line_code IS NOT NULL") } - scope :not_inline, -> { where(line_code: [nil, '']) } + scope :inline, ->{ where("line_code IS NOT NULL") } + scope :not_inline, ->{ where(line_code: [nil, '']) } scope :common, ->{ where(noteable_type: ["", nil]) } scope :fresh, ->{ order("created_at ASC, id ASC") } scope :inc_author_project, ->{ includes(:project, :author) } scope :inc_author, ->{ includes(:author) } - def self.create_status_change_note(noteable, author, status) + def self.create_status_change_note(noteable, project, author, status) create({ noteable: noteable, - project: noteable.project, + project: project, author: author, note: "_Status changed to #{status}_" }, without_protection: true) @@ -62,7 +62,7 @@ class Note < ActiveRecord::Base def commit_author @commit_author ||= project.users.find_by_email(noteable.author_email) || - project.users.find_by_name(noteable.author_name) + project.users.find_by_name(noteable.author_name) rescue nil end diff --git a/app/models/project.rb b/app/models/project.rb index 497ed1a218c..59c6d212f48 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -53,7 +53,7 @@ class Project < ActiveRecord::Base has_many :services, dependent: :destroy has_many :events, dependent: :destroy - has_many :merge_requests, dependent: :destroy + has_many :merge_requests, dependent: :destroy, foreign_key: "target_project_id" has_many :issues, dependent: :destroy, order: "state DESC, created_at DESC" has_many :milestones, dependent: :destroy has_many :notes, dependent: :destroy diff --git a/app/observers/activity_observer.rb b/app/observers/activity_observer.rb index 4f4eb36a188..91f097154d8 100644 --- a/app/observers/activity_observer.rb +++ b/app/observers/activity_observer.rb @@ -1,5 +1,5 @@ class ActivityObserver < BaseObserver - observe :issue, :merge_request, :note, :milestone + observe :issue, :note, :milestone def after_create(record) event_author_id = record.author_id @@ -13,47 +13,27 @@ class ActivityObserver < BaseObserver end if event_author_id - Event.create( - project: record.project, - target_id: record.id, - target_type: record.class.name, - action: Event.determine_action(record), - author_id: event_author_id - ) + create_event(record, Event.determine_action(record)) end end def after_close(record, transition) - Event.create( - project: record.project, - target_id: record.id, - target_type: record.class.name, - action: Event::CLOSED, - author_id: record.author_id_of_changes - ) + create_event(record, Event::CLOSED) end def after_reopen(record, transition) - Event.create( - project: record.project, - target_id: record.id, - target_type: record.class.name, - action: Event::REOPENED, - author_id: record.author_id_of_changes - ) + create_event(record, Event::REOPENED) end - def after_merge(record, transition) - # Since MR can be merged via sidekiq - # to prevent event duplication do this check - return true if record.merge_event + protected + def create_event(record, status) Event.create( - project: record.project, - target_id: record.id, - target_type: record.class.name, - action: Event::MERGED, - author_id: record.author_id_of_changes + project: record.project, + target_id: record.id, + target_type: record.class.name, + action: status, + author_id: record.author_id ) end end diff --git a/app/observers/issue_observer.rb b/app/observers/issue_observer.rb index 888fa7f6b73..50538419776 100644 --- a/app/observers/issue_observer.rb +++ b/app/observers/issue_observer.rb @@ -23,6 +23,6 @@ class IssueObserver < BaseObserver # Create issue note with service comment like 'Status changed to closed' def create_note(issue) - Note.create_status_change_note(issue, current_user, issue.state) + Note.create_status_change_note(issue, issue.project, current_user, issue.state) end end diff --git a/app/observers/merge_request_observer.rb b/app/observers/merge_request_observer.rb index 03d4a22c1e6..436645a376f 100644 --- a/app/observers/merge_request_observer.rb +++ b/app/observers/merge_request_observer.rb @@ -1,23 +1,53 @@ -class MergeRequestObserver < BaseObserver +class MergeRequestObserver < ActivityObserver + observe :merge_request + def after_create(merge_request) + if merge_request.author_id + create_event(merge_request, Event.determine_action(merge_request)) + end + notification.new_merge_request(merge_request, current_user) end def after_close(merge_request, transition) - Note.create_status_change_note(merge_request, current_user, merge_request.state) + create_event(merge_request, Event::CLOSED) + Note.create_status_change_note(merge_request, merge_request.target_project, current_user, merge_request.state) notification.close_mr(merge_request, current_user) end def after_merge(merge_request, transition) notification.merge_mr(merge_request) + # Since MR can be merged via sidekiq + # to prevent event duplication do this check + return true if merge_request.merge_event + + Event.create( + project: merge_request.target_project, + target_id: merge_request.id, + target_type: merge_request.class.name, + action: Event::MERGED, + author_id: merge_request.author_id_of_changes + ) end def after_reopen(merge_request, transition) - Note.create_status_change_note(merge_request, current_user, merge_request.state) + create_event(merge_request, Event::REOPENED) + Note.create_status_change_note(merge_request, merge_request.target_project, current_user, merge_request.state) end def after_update(merge_request) notification.reassigned_merge_request(merge_request, current_user) if merge_request.is_being_reassigned? end + + def create_event(record, status) + Event.create( + project: record.target_project, + target_id: record.id, + target_type: record.class.name, + action: status, + author_id: record.author_id + ) + end + end diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index b5cf5cedd6b..5548c18bfe1 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -23,7 +23,7 @@ class NotificationService # * project team members with notification level higher then Participating # def new_issue(issue, current_user) - new_resource_email(issue, 'new_issue_email') + new_resource_email(issue, issue.project, 'new_issue_email') end # When we close an issue we should send next emails: @@ -33,7 +33,7 @@ class NotificationService # * project team members with notification level higher then Participating # def close_issue(issue, current_user) - close_resource_email(issue, current_user, 'closed_issue_email') + close_resource_email(issue, issue.project, current_user, 'closed_issue_email') end # When we reassign an issue we should send next emails: @@ -42,7 +42,7 @@ class NotificationService # * issue new assignee if his notification level is not Disabled # def reassigned_issue(issue, current_user) - reassign_resource_email(issue, current_user, 'reassigned_issue_email') + reassign_resource_email(issue, issue.project, current_user, 'reassigned_issue_email') end @@ -51,7 +51,7 @@ class NotificationService # * mr assignee if his notification level is not Disabled # def new_merge_request(merge_request, current_user) - new_resource_email(merge_request, 'new_merge_request_email') + new_resource_email(merge_request, merge_request.target_project, 'new_merge_request_email') end # When we reassign a merge_request we should send next emails: @@ -60,7 +60,7 @@ class NotificationService # * merge_request assignee if his notification level is not Disabled # def reassigned_merge_request(merge_request, current_user) - reassign_resource_email(merge_request, current_user, 'reassigned_merge_request_email') + reassign_resource_email(merge_request, merge_request.target_project, current_user, 'reassigned_merge_request_email') end # When we close a merge request we should send next emails: @@ -70,7 +70,7 @@ class NotificationService # * project team members with notification level higher then Participating # def close_mr(merge_request, current_user) - close_resource_email(merge_request, current_user, 'closed_merge_request_email') + close_resource_email(merge_request, merge_request.target_project, current_user, 'closed_merge_request_email') end # When we merge a merge request we should send next emails: @@ -80,8 +80,8 @@ class NotificationService # * project team members with notification level higher then Participating # def merge_mr(merge_request) - recipients = reject_muted_users([merge_request.author, merge_request.assignee], merge_request.project) - recipients = recipients.concat(project_watchers(merge_request.project)).uniq + recipients = reject_muted_users([merge_request.author, merge_request.assignee], merge_request.target_project) + recipients = recipients.concat(project_watchers(merge_request.target_project)).uniq recipients.each do |recipient| mailer.merged_merge_request_email(recipient.id, merge_request.id) @@ -191,14 +191,14 @@ class NotificationService end end - def new_resource_email(target, method) + def new_resource_email(target, project, method) if target.respond_to?(:participants) recipients = target.participants else recipients = [] end - recipients = reject_muted_users(recipients, target.project) - recipients = recipients.concat(project_watchers(target.project)).uniq + recipients = reject_muted_users(recipients, project) + recipients = recipients.concat(project_watchers(project)).uniq recipients.delete(target.author) recipients.each do |recipient| @@ -206,9 +206,9 @@ class NotificationService end end - def close_resource_email(target, current_user, method) - recipients = reject_muted_users([target.author, target.assignee], target.project) - recipients = recipients.concat(project_watchers(target.project)).uniq + def close_resource_email(target, project, current_user, method) + recipients = reject_muted_users([target.author, target.assignee], project) + recipients = recipients.concat(project_watchers(project)).uniq recipients.delete(current_user) recipients.each do |recipient| @@ -216,14 +216,14 @@ class NotificationService end end - def reassign_resource_email(target, current_user, method) + def reassign_resource_email(target, project, current_user, method) recipients = User.where(id: [target.assignee_id, target.assignee_id_was]) # Add watchers to email list - recipients = recipients.concat(project_watchers(target.project)) + recipients = recipients.concat(project_watchers(project)) # reject users with disabled notifications - recipients = reject_muted_users(recipients, target.project) + recipients = reject_muted_users(recipients, project) # Reject me from recipients if I reassign an item recipients.delete(current_user) diff --git a/app/views/events/_event_last_push.html.haml b/app/views/events/_event_last_push.html.haml index de5634d3c55..a634365ff3e 100644 --- a/app/views/events/_event_last_push.html.haml +++ b/app/views/events/_event_last_push.html.haml @@ -9,6 +9,9 @@ = time_ago_in_words(event.created_at) ago. .pull-right - = link_to new_mr_path_from_push_event(event), title: "New Merge Request", class: "btn btn-create btn-small" do + = link_to new_mr_path_from_push_event(event), title: "New Merge Request", class: "btn btn-new-mr" do Create Merge Request + - if !event.project.nil? && event.project.forked? + = link_to new_mr_path_for_fork_from_push_event(event), title: "New Merge Request", class: "btn btn-create btn-small" do + Create Merge Request on fork %hr diff --git a/app/views/notify/closed_merge_request_email.html.haml b/app/views/notify/closed_merge_request_email.html.haml index 0c6c79e097a..c6b45b1710a 100644 --- a/app/views/notify/closed_merge_request_email.html.haml +++ b/app/views/notify/closed_merge_request_email.html.haml @@ -1,9 +1,9 @@ %p = "Merge Request #{@merge_request.id} was closed by #{@updated_by.name}" %p - = link_to_gfm truncate(@merge_request.title, length: 40), project_merge_request_url(@merge_request.project, @merge_request) + = link_to_gfm truncate(@merge_request.title, length: 40), project_merge_request_url(@merge_request.target_project, @merge_request) %p - Branches: #{@merge_request.source_branch} → #{@merge_request.target_branch} + != merge_path_description(@merge_request, '→') %p Assignee: #{@merge_request.author_name} → #{@merge_request.assignee_name} diff --git a/app/views/notify/closed_merge_request_email.text.haml b/app/views/notify/closed_merge_request_email.text.haml index ee4648e3d09..9a5bce5915a 100644 --- a/app/views/notify/closed_merge_request_email.text.haml +++ b/app/views/notify/closed_merge_request_email.text.haml @@ -1,8 +1,8 @@ = "Merge Request #{@merge_request.id} was closed by #{@updated_by.name}" -Merge Request url: #{project_merge_request_url(@merge_request.project, @merge_request)} +Merge Request url: #{project_merge_request_url(@merge_request.target_project, @merge_request)} -Branches: #{@merge_request.source_branch} - #{@merge_request.target_branch} += merge_path_description(@merge_request, 'to') Author: #{@merge_request.author_name} Assignee: #{@merge_request.assignee_name} diff --git a/app/views/notify/merged_merge_request_email.html.haml b/app/views/notify/merged_merge_request_email.html.haml index 2b8cc030b23..e3ae41819f8 100644 --- a/app/views/notify/merged_merge_request_email.html.haml +++ b/app/views/notify/merged_merge_request_email.html.haml @@ -1,9 +1,9 @@ %p = "Merge Request #{@merge_request.id} was merged" %p - = link_to_gfm truncate(@merge_request.title, length: 40), project_merge_request_url(@merge_request.project, @merge_request) + = link_to_gfm truncate(@merge_request.title, length: 40), project_merge_request_url(@merge_request.target_project, @merge_request) %p - Branches: #{@merge_request.source_branch} → #{@merge_request.target_branch} + != merge_path_description(@merge_request, '→') %p Assignee: #{@merge_request.author_name} → #{@merge_request.assignee_name} diff --git a/app/views/notify/merged_merge_request_email.text.haml b/app/views/notify/merged_merge_request_email.text.haml index 91c23360195..fa9ef0a4b32 100644 --- a/app/views/notify/merged_merge_request_email.text.haml +++ b/app/views/notify/merged_merge_request_email.text.haml @@ -1,8 +1,8 @@ = "Merge Request #{@merge_request.id} was merged" -Merge Request Url: #{project_merge_request_url(@merge_request.project, @merge_request)} +Merge Request Url: #{project_merge_request_url(@merge_request.target_project, @merge_request)} -Branches: #{@merge_request.source_branch} - #{@merge_request.target_branch} += merge_path_description(@merge_request, 'to') Author: #{@merge_request.author_name} Assignee: #{@merge_request.assignee_name} diff --git a/app/views/notify/new_merge_request_email.html.haml b/app/views/notify/new_merge_request_email.html.haml index 0f1cfff5831..3b060001e6b 100644 --- a/app/views/notify/new_merge_request_email.html.haml +++ b/app/views/notify/new_merge_request_email.html.haml @@ -1,9 +1,9 @@ %p = "New Merge Request !#{@merge_request.id}" %p - = link_to_gfm truncate(@merge_request.title, length: 40), project_merge_request_url(@merge_request.project, @merge_request) + = link_to_gfm truncate(@merge_request.title, length: 40), project_merge_request_url(@merge_request.target_project, @merge_request) %p - Branches: #{@merge_request.source_branch} → #{@merge_request.target_branch} + != merge_path_description(@merge_request, '→') %p Assignee: #{@merge_request.author_name} → #{@merge_request.assignee_name} diff --git a/app/views/notify/new_merge_request_email.text.erb b/app/views/notify/new_merge_request_email.text.erb index 3393d8384f1..3f711840a51 100644 --- a/app/views/notify/new_merge_request_email.text.erb +++ b/app/views/notify/new_merge_request_email.text.erb @@ -1,9 +1,8 @@ New Merge Request <%= @merge_request.id %> -<%= url_for(project_merge_request_url(@merge_request.project, @merge_request)) %> - +<%= url_for(project_merge_request_url(@merge_request.target_project, @merge_request)) %> -Branches: <%= @merge_request.source_branch %> to <%= @merge_request.target_branch %> +<%= merge_path_description(@merge_request, 'to') %> Author: <%= @merge_request.author_name %> Asignee: <%= @merge_request.assignee_name %> diff --git a/app/views/notify/note_merge_request_email.html.haml b/app/views/notify/note_merge_request_email.html.haml index 4f97867e49d..14abcca6070 100644 --- a/app/views/notify/note_merge_request_email.html.haml +++ b/app/views/notify/note_merge_request_email.html.haml @@ -1,8 +1,8 @@ %p - if @note.for_diff_line? - = link_to "New comment on diff", diffs_project_merge_request_url(@merge_request.project, @merge_request, anchor: "note_#{@note.id}") + = link_to "New comment on diff", diffs_project_merge_request_url(@merge_request.target_project, @merge_request, anchor: "note_#{@note.id}") - else - = link_to "New comment", project_merge_request_url(@merge_request.project, @merge_request, anchor: "note_#{@note.id}") + = link_to "New comment", project_merge_request_url(@merge_request.target_project, @merge_request, anchor: "note_#{@note.id}") for Merge Request ##{@merge_request.id} %cite "#{truncate(@merge_request.title, length: 20)}" = render 'note_message' diff --git a/app/views/notify/note_merge_request_email.text.erb b/app/views/notify/note_merge_request_email.text.erb index 26c73bdaa38..3daa091db81 100644 --- a/app/views/notify/note_merge_request_email.text.erb +++ b/app/views/notify/note_merge_request_email.text.erb @@ -1,6 +1,6 @@ New comment for Merge Request <%= @merge_request.id %> -<%= url_for(project_merge_request_url(@merge_request.project, @merge_request, anchor: "note_#{@note.id}")) %> +<%= url_for(project_merge_request_url(@merge_request.target_project, @merge_request, anchor: "note_#{@note.id}")) %> <%= @note.author_name %> diff --git a/app/views/notify/reassigned_merge_request_email.html.haml b/app/views/notify/reassigned_merge_request_email.html.haml index 5ad72764e38..314b2882672 100644 --- a/app/views/notify/reassigned_merge_request_email.html.haml +++ b/app/views/notify/reassigned_merge_request_email.html.haml @@ -1,6 +1,6 @@ %p = "Reassigned Merge Request !#{@merge_request.id}" - = link_to_gfm truncate(@merge_request.title, length: 30), project_merge_request_url(@merge_request.project, @merge_request) + = link_to_gfm truncate(@merge_request.title, length: 30), project_merge_request_url(@merge_request.target_project, @merge_request) %p Assignee changed - if @previous_assignee diff --git a/app/views/notify/reassigned_merge_request_email.text.erb b/app/views/notify/reassigned_merge_request_email.text.erb index 25b2a43fcdd..05a9797165d 100644 --- a/app/views/notify/reassigned_merge_request_email.text.erb +++ b/app/views/notify/reassigned_merge_request_email.text.erb @@ -1,6 +1,6 @@ Reassigned Merge Request <%= @merge_request.id %> -<%= url_for(project_merge_request_url(@merge_request.project, @merge_request)) %> +<%= url_for(project_merge_request_url(@merge_request.target_project, @merge_request)) %> Assignee changed <%= "from #{@previous_assignee.name}" if @previous_assignee %> to <%= @merge_request.assignee_name %> diff --git a/app/views/projects/commit/show.html.haml b/app/views/projects/commit/show.html.haml index 38c98d81b5c..da1b4c10f87 100644 --- a/app/views/projects/commit/show.html.haml +++ b/app/views/projects/commit/show.html.haml @@ -1,3 +1,3 @@ = render "commit_box" -= render "projects/commits/diffs", diffs: @commit.diffs += render "projects/commits/diffs", diffs: @commit.diffs, project: @project = render "projects/notes/notes_with_form" diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index eba6c206c46..eb5bdb886e2 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -1,12 +1,12 @@ %li.commit .browse_code_link_holder %p - %strong= link_to "Browse Code »", project_tree_path(@project, commit), class: "right" + %strong= link_to "Browse Code »", project_tree_path(project, commit), class: "right" %p - = link_to commit.short_id(8), project_commit_path(@project, commit), class: "commit_short_id" + = link_to commit.short_id(8), project_commit_path(project, commit), class: "commit_short_id" = commit_author_link(commit, avatar: true, size: 24) - = link_to_gfm truncate(commit.title, length: 70), project_commit_path(@project, commit.id), class: "row_title" + = link_to_gfm truncate(commit.title, length: 70), project_commit_path(project, commit.id), class: "row_title" %time.committed_ago{ datetime: commit.committed_date, title: commit.committed_date.stamp("Aug 21, 2011 9:23pm") } = time_ago_in_words(commit.committed_date) @@ -14,7 +14,7 @@ %span.notes_count - - notes = @project.notes.for_commit_id(commit.id) + - notes = project.notes.for_commit_id(commit.id) - if notes.any? %span.badge.badge-info %i.icon-comment diff --git a/app/views/projects/commits/_commits.html.haml b/app/views/projects/commits/_commits.html.haml index acdb8891344..243299d028c 100644 --- a/app/views/projects/commits/_commits.html.haml +++ b/app/views/projects/commits/_commits.html.haml @@ -3,7 +3,6 @@ .title %i.icon-calendar %span= day.stamp("28 Aug, 2010") - .pull-right %small= pluralize(commits.count, 'commit') - %ul.well-list= render commits + %ul.well-list= render commits, project: @project diff --git a/app/views/projects/commits/_diffs.html.haml b/app/views/projects/commits/_diffs.html.haml index a60bf75175d..ca025731258 100644 --- a/app/views/projects/commits/_diffs.html.haml +++ b/app/views/projects/commits/_diffs.html.haml @@ -5,7 +5,7 @@ %p To prevent performance issue we rejected diff information. %p But if you still want to see diff - = link_to "click this link", project_commit_path(@project, @commit, force_show_diff: true), class: "underlined_link" + = link_to "click this link", project_commit_path(project, @commit, force_show_diff: true), class: "underlined_link" %p.commit-stat-summary Showing @@ -23,8 +23,8 @@ - unless @suppress_diff - diffs.each_with_index do |diff, i| - next if diff.diff.empty? - - file = Gitlab::Git::Blob.new(@repository, @commit.id, @ref, diff.new_path) - - file = Gitlab::Git::Blob.new(@repository, @commit.parent_id, @ref, diff.old_path) unless file.exists? + - file = Gitlab::Git::Blob.new(project.repository, @commit.id, @ref, diff.new_path) + - file = Gitlab::Git::Blob.new(project.repository, @commit.parent_id, @ref, diff.old_path) unless file.exists? - next unless file.exists? .file{id: "diff-#{i}"} .header @@ -32,7 +32,7 @@ %span= diff.old_path - if @commit.parent_ids.present? - = link_to project_blob_path(@project, tree_join(@commit.parent_id, diff.new_path)), {:class => 'btn btn-tiny pull-right view-file'} do + = link_to project_blob_path(project, tree_join(@commit.parent_id, diff.new_path)), {:class => 'btn btn-tiny pull-right view-file'} do View file @ %span.commit-short-id= @commit.short_id(6) - else @@ -40,7 +40,7 @@ - if diff.a_mode && diff.b_mode && diff.a_mode != diff.b_mode %span.file-mode= "#{diff.a_mode} → #{diff.b_mode}" - = link_to project_blob_path(@project, tree_join(@commit.id, diff.new_path)), {:class => 'btn btn-tiny pull-right view-file'} do + = link_to project_blob_path(project, tree_join(@commit.id, diff.new_path)), {:class => 'btn btn-tiny pull-right view-file'} do View file @ %span.commit-short-id= @commit.short_id(6) @@ -50,7 +50,7 @@ - if file.text? = render "projects/commits/text_file", diff: diff, index: i - elsif file.image? - - old_file = Gitlab::Git::Blob.new(@repository, @commit.parent_id, @ref, diff.old_path) if @commit.parent_id + - old_file = Gitlab::Git::Blob.new(project.repository, @commit.parent_id, @ref, diff.old_path) if @commit.parent_id = render "projects/commits/image", diff: diff, old_file: old_file, file: file, index: i - else %p.nothing_here_message No preview for this file type diff --git a/app/views/projects/compare/show.html.haml b/app/views/projects/compare/show.html.haml index f2e65f68da6..266c14b358a 100644 --- a/app/views/projects/compare/show.html.haml +++ b/app/views/projects/compare/show.html.haml @@ -15,8 +15,8 @@ %div.ui-box .title Commits (#{@commits.count}) - %ul.well-list= render Commit.decorate(@commits) + %ul.well-list= render Commit.decorate(@commits), project: @project - unless @diffs.empty? %h4 Diff - = render "projects/commits/diffs", diffs: @diffs + = render "projects/commits/diffs", diffs: @diffs, project: @project diff --git a/app/views/projects/merge_requests/_form.html.haml b/app/views/projects/merge_requests/_form.html.haml index 86c442142bf..54697706198 100644 --- a/app/views/projects/merge_requests/_form.html.haml +++ b/app/views/projects/merge_requests/_form.html.haml @@ -12,18 +12,20 @@ .row .span5 .light-well - %h5.cgray From (Head Branch) - = f.select(:source_branch, @repository.branch_names, { include_blank: "Select branch" }, {class: 'chosen span4'}) + %h5.cgray From + .padded= f.select(:source_project_id,[[@merge_request.source_project.path_with_namespace,@merge_request.source_project.id]] , {}, {class: 'source_project chosen span4'}) + .padded= f.select(:source_branch, @merge_request.source_project.repository.branch_names, { include_blank: "Select branch" }, {class: 'source_branch chosen span4'}) .mr_source_commit.prepend-top-10 - .span2 %h1.merge-request-angle %i.icon-angle-right .span5 .light-well - %h5.cgray To (Base Branch) - = f.select(:target_branch, @repository.branch_names, { include_blank: "Select branch" }, {class: 'chosen span4'}) - .mr_target_commit.prepend-top-10 + %h5.cgray To + - projects = @project.forked_from_project.nil? ? [@project] : [ @project,@project.forked_from_project] + .padded= f.select(:target_project_id, projects.map { |proj| [proj.path_with_namespace,proj.id] }, {include_blank: "Select Target Project" }, {class: 'target_project chosen span4'}) + .padded= f.select(:target_branch, @target_branches, { include_blank: "Select branch" }, {class: 'target_branch chosen span4'}) + .mr_target_commit.prepend-top-10 %hr @@ -47,32 +49,34 @@ Milestone .input= f.select(:milestone_id, @project.milestones.active.all.map {|p| [ p.title, p.id ] }, { include_blank: "Select milestone" }, {class: 'chosen'}) - .form-actions - if @merge_request.new_record? = f.submit 'Submit merge request', class: "btn btn-create" -else = f.submit 'Save changes', class: "btn btn-save" - if @merge_request.new_record? - = link_to project_merge_requests_path(@project), class: "btn btn-cancel" do + = link_to project_merge_requests_path(@source_project), class: "btn btn-cancel" do Cancel - else - = link_to project_merge_request_path(@project, @merge_request), class: "btn btn-cancel" do + = link_to project_merge_request_path(@target_project, @merge_request), class: "btn btn-cancel" do Cancel :javascript disableButtonIfEmptyField("#merge_request_title", ".btn-save"); var source_branch = $("#merge_request_source_branch") - , target_branch = $("#merge_request_target_branch"); + , target_branch = $("#merge_request_target_branch") + , target_project = $("#merge_request_target_project_id"); - $.get("#{branch_from_project_merge_requests_path(@project)}", {ref: source_branch.val() }); - $.get("#{branch_to_project_merge_requests_path(@project)}", {ref: target_branch.val() }); + $.get("#{branch_from_project_merge_requests_path(@source_project)}", {ref: source_branch.val() }); + $.get("#{branch_to_project_merge_requests_path(@source_project)}", {target_project_id: target_project.val(),ref: target_branch.val() }); - source_branch.live("change", function() { - $.get("#{branch_from_project_merge_requests_path(@project)}", {ref: $(this).val() }); + target_project.on("change", function() { + $.get("#{update_branches_project_merge_requests_path(@source_project)}", {target_project_id: $(this).val() }); }); - - target_branch.live("change", function() { - $.get("#{branch_to_project_merge_requests_path(@project)}", {ref: $(this).val() }); + source_branch.on("change", function() { + $.get("#{branch_from_project_merge_requests_path(@source_project)}", {ref: $(this).val() }); + }); + target_branch.on("change", function() { + $.get("#{branch_to_project_merge_requests_path(@source_project)}", {target_project_id: target_project.val(),ref: $(this).val() }); }); diff --git a/app/views/projects/merge_requests/_merge_request.html.haml b/app/views/projects/merge_requests/_merge_request.html.haml index ffc6b8fda1e..a10ed02a077 100644 --- a/app/views/projects/merge_requests/_merge_request.html.haml +++ b/app/views/projects/merge_requests/_merge_request.html.haml @@ -1,18 +1,24 @@ %li{ class: mr_css_classes(merge_request) } .merge-request-title %span.light= "##{merge_request.id}" - = link_to_gfm truncate(merge_request.title, length: 80), project_merge_request_path(merge_request.project, merge_request), class: "row_title" + = link_to_gfm truncate(merge_request.title, length: 80), project_merge_request_path(merge_request.target_project, merge_request), class: "row_title" - if merge_request.merged? %small.pull-right %i.icon-ok = "MERGED" - else %span.pull-right - %i.icon-angle-right - = merge_request.target_branch + - if merge_request.for_fork? + = "#{merge_request.source_project.path_with_namespace}/#{merge_request.source_branch}" + %i.icon-angle-right + = "#{merge_request.target_project.path_with_namespace}/#{merge_request.target_branch}" + - else + = "#{merge_request.source_branch}" + %i.icon-angle-right + = "#{merge_request.target_branch}" .merge-request-info - if merge_request.author - authored by #{link_to_member(@project, merge_request.author)} + authored by #{link_to_member(merge_request.source_project, merge_request.author)} - if merge_request.votes_count > 0 = render 'votes/votes_inline', votable: merge_request - if merge_request.notes.any? diff --git a/app/views/projects/merge_requests/branch_from.js.haml b/app/views/projects/merge_requests/branch_from.js.haml index 1d6b10f03ae..d0a148575dc 100644 --- a/app/views/projects/merge_requests/branch_from.js.haml +++ b/app/views/projects/merge_requests/branch_from.js.haml @@ -1,5 +1,5 @@ :plain - $(".mr_source_commit").html("#{commit_to_html(@commit)}"); + $(".mr_source_commit").html("#{commit_to_html(@commit, @source_project)}"); var mrTitle = $('#merge_request_title'); if(mrTitle.is(":empty")) { diff --git a/app/views/projects/merge_requests/branch_to.js.haml b/app/views/projects/merge_requests/branch_to.js.haml index 974100d1ba7..f4e2886ee44 100644 --- a/app/views/projects/merge_requests/branch_to.js.haml +++ b/app/views/projects/merge_requests/branch_to.js.haml @@ -1,2 +1,2 @@ :plain - $(".mr_target_commit").html("#{commit_to_html(@commit)}"); + $(".mr_target_commit").html("#{commit_to_html(@commit, @target_project)}"); diff --git a/app/views/projects/merge_requests/show/_commits.html.haml b/app/views/projects/merge_requests/show/_commits.html.haml index 40876d16ddd..7b0e67053a5 100644 --- a/app/views/projects/merge_requests/show/_commits.html.haml +++ b/app/views/projects/merge_requests/show/_commits.html.haml @@ -7,19 +7,19 @@ - if @commits.count > 8 %ul.first-commits.well-list - @commits.first(8).each do |commit| - = render "projects/commits/commit", commit: commit + = render "projects/commits/commit", commit: commit, project: @merge_request.source_project %li.bottom 8 of #{@commits.count} commits displayed. %strong %a.show-all-commits Click here to show all %ul.all-commits.hide.well-list - @commits.each do |commit| - = render "projects/commits/commit", commit: commit + = render "projects/commits/commit", commit: commit, project: @merge_request.source_project - else %ul.well-list - @commits.each do |commit| - = render "projects/commits/commit", commit: commit + = render "projects/commits/commit", commit: commit, project: @merge_request.source_project - else %h4.nothing_here_message diff --git a/app/views/projects/merge_requests/show/_diffs.html.haml b/app/views/projects/merge_requests/show/_diffs.html.haml index 3c1d14572aa..25f63804858 100644 --- a/app/views/projects/merge_requests/show/_diffs.html.haml +++ b/app/views/projects/merge_requests/show/_diffs.html.haml @@ -1,10 +1,10 @@ - if @merge_request.valid_diffs? - = render "projects/commits/diffs", diffs: @merge_request.diffs + = render "projects/commits/diffs", diffs: @merge_request.diffs, project: @merge_request.source_project - elsif @merge_request.broken_diffs? %h4.nothing_here_message Can't load diff. You can - = link_to "download it", project_merge_request_path(@project, @merge_request, format: :diff), class: "vlink" + = link_to "download it", project_merge_request_path(@merge_request.source_project, @merge_request), format: :diff, class: "vlink" instead. - else %h4.nothing_here_message Nothing to merge diff --git a/app/views/projects/merge_requests/show/_how_to_merge.html.haml b/app/views/projects/merge_requests/show/_how_to_merge.html.haml index 7f1e33418de..a0eb2309585 100644 --- a/app/views/projects/merge_requests/show/_how_to_merge.html.haml +++ b/app/views/projects/merge_requests/show/_how_to_merge.html.haml @@ -3,17 +3,49 @@ %a.close{href: "#"} × %h3 How To Merge .modal-body - %p - %strong Step 1. - Checkout target branch and get recent objects from GitLab - %pre.dark - :preserve - git checkout #{@merge_request.target_branch} - git fetch origin - %p - %strong Step 2. - Merge source branch into target branch and push changes to GitLab - %pre.dark - :preserve - git merge origin/#{@merge_request.source_branch} - git push origin #{@merge_request.target_branch} + - if @merge_request.for_fork? + - source_remote = @merge_request.source_project.namespace.nil? ? "source" :@merge_request.source_project.namespace.path + - target_remote = @merge_request.target_project.namespace.nil? ? "target" :@merge_request.target_project.namespace.path + %p + %strong Step 1. + Checkout target branch and get recent objects from GitLab + Assuming remote for #{@merge_request.target_project.path_with_namespace} is called #{target_remote} + remote for #{@merge_request.source_project.path_with_namespace} is called #{source_remote} + %pre.dark + :preserve + git checkout #{target_remote} #{@merge_request.target_branch} + git fetch #{source_remote} + %p + %strong Step 2. + Merge source branch into target branch and push changes to GitLab + %pre.dark + :preserve + git merge #{source_remote}/#{@merge_request.source_branch} + git push #{target_remote} #{@merge_request.target_branch} + - else + %p + %strong Step 1. + Checkout target branch and get recent objects from GitLab + %pre.dark + :preserve + git checkout #{@merge_request.target_branch} + git fetch origin + %p + %strong Step 2. + Merge source branch into target branch and push changes to GitLab + %pre.dark + :preserve + git merge origin/#{@merge_request.source_branch} + git push origin #{@merge_request.target_branch} + + +:javascript + $(function(){ + var modal = $('#modal_merge_info').modal({modal: true, show:false}); + $('.how_to_merge_link').bind("click", function(){ + modal.show(); + }); + $('.modal-header .close').bind("click", function(){ + modal.hide(); + }) + }) diff --git a/app/views/projects/merge_requests/show/_mr_accept.html.haml b/app/views/projects/merge_requests/show/_mr_accept.html.haml index 01378d99c99..47db8cdc8d2 100644 --- a/app/views/projects/merge_requests/show/_mr_accept.html.haml +++ b/app/views/projects/merge_requests/show/_mr_accept.html.haml @@ -15,7 +15,7 @@ for instructions .accept_group = f.submit "Accept Merge Request", class: "btn btn-create accept_merge_request" - - unless @project.root_ref? @merge_request.source_branch + - unless @merge_request.disallow_source_branch_removal? .remove_branch_holder = label_tag :should_remove_source_branch, class: "checkbox" do = check_box_tag :should_remove_source_branch diff --git a/app/views/projects/merge_requests/show/_mr_title.html.haml b/app/views/projects/merge_requests/show/_mr_title.html.haml index 5a07258f91c..c36ac2ed55b 100644 --- a/app/views/projects/merge_requests/show/_mr_title.html.haml +++ b/app/views/projects/merge_requests/show/_mr_title.html.haml @@ -1,9 +1,16 @@ %h3.page-title = "Merge Request ##{@merge_request.id}:" - %span.label-branch= @merge_request.source_branch - → - %span.label-branch= @merge_request.target_branch + -if @merge_request.for_fork? + %span.label-project= @merge_request.source_project.path_with_namespace + %span.label-branch= @merge_request.source_branch + → + %span.label-project= @merge_request.target_project.path_with_namespace + %span.label-branch= @merge_request.target_branch + - else + %span.label-branch= @merge_request.source_branch + → + %span.label-branch= @merge_request.target_branch %span.pull-right - if can?(current_user, :modify_merge_request, @merge_request) @@ -19,7 +26,7 @@ = link_to 'Close', project_merge_request_path(@project, @merge_request, merge_request: {state_event: :close }), method: :put, class: "btn grouped btn-close", title: "Close merge request" - = link_to edit_project_merge_request_path(@project, @merge_request), class: "btn grouped" do + = link_to edit_project_merge_request_path(@project, @merge_request), class: "btn grouped", id:"edit_merge_request" do %i.icon-edit Edit diff --git a/app/views/projects/merge_requests/update_branches.js.haml b/app/views/projects/merge_requests/update_branches.js.haml new file mode 100644 index 00000000000..db25ae3b918 --- /dev/null +++ b/app/views/projects/merge_requests/update_branches.js.haml @@ -0,0 +1,5 @@ +:plain + $(".target_branch").html("#{escape_javascript(options_for_select(@target_branches))}"); + $(".target_branch").trigger("liszt:updated"); + $(".mr_target_commit").html(""); + $(".target_branch").trigger("change");
\ No newline at end of file diff --git a/app/views/projects/notes/_discussion.html.haml b/app/views/projects/notes/_discussion.html.haml index 14d81bbb5ce..8c79b5ad53e 100644 --- a/app/views/projects/notes/_discussion.html.haml +++ b/app/views/projects/notes/_discussion.html.haml @@ -23,7 +23,7 @@ discussion on this merge request diff - elsif note.for_commit? started a discussion on commit - #{link_to note.noteable.short_id, project_commit_path(@project, note.noteable)} + #{link_to note.noteable.short_id, project_commit_path(note.project, note.noteable)} = link_to_commit_diff_line_note(note) if note.for_diff_line? - else %cite.cgray started a discussion diff --git a/app/views/search/_result.html.haml b/app/views/search/_result.html.haml index 4e56eea084e..59c7738019b 100644 --- a/app/views/search/_result.html.haml +++ b/app/views/search/_result.html.haml @@ -22,11 +22,14 @@ - @merge_requests.each do |merge_request| %li merge request: - = link_to [merge_request.project, merge_request] do + = link_to [merge_request.target_project, merge_request] do %span ##{merge_request.id} %strong.term = truncate merge_request.title, length: 50 - %span.light (#{merge_request.project.name_with_namespace}) + - if merge_request.for_fork? + %span.light (#{merge_request.source_project.name_with_namespace}:#{merge_request.source_branch} → #{merge_request.target_project.name_with_namespace}:#{merge_request.target_branch}) + - else + %span.light (#{merge_request.source_branch} → #{merge_request.target_branch}) - @issues.each do |issue| %li issue: diff --git a/app/views/shared/_merge_requests.html.haml b/app/views/shared/_merge_requests.html.haml index 935a7a7f7c0..5276f4bae31 100644 --- a/app/views/shared/_merge_requests.html.haml +++ b/app/views/shared/_merge_requests.html.haml @@ -1,5 +1,5 @@ - if @merge_requests.any? - - @merge_requests.group_by(&:project).each do |group| + - @merge_requests.group_by(&:target_project).each do |group| .ui-box - project = group[0] .title |