diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index e998b7bb..9b65d605 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -41,6 +41,10 @@ a:focus { .label { background-color: #474D57; + + &.pushed { + background-color: $link_color; + } } .pretty_label { @@ -865,7 +869,7 @@ p.time { } } - padding: 10px 5px; + padding: 15px 5px; border-bottom: 1px solid #eee; border-bottom: 1px solid rgba(0, 0, 0, 0.05); &:last-child { border:none } @@ -963,3 +967,17 @@ p.time { .highlight_word { background:#EEDC94; } + +.status_info { + font-size:14px; + padding:5px 15px; + line-height:24px; + width:60px; + text-align:center; + float:left; + margin-right:20px; +} + +.merge_request_status_holder { + margin-bottom:20px; +} diff --git a/app/controllers/merge_requests_controller.rb b/app/controllers/merge_requests_controller.rb index 2de7ec31..3a3143cb 100644 --- a/app/controllers/merge_requests_controller.rb +++ b/app/controllers/merge_requests_controller.rb @@ -45,9 +45,6 @@ class MergeRequestsController < ApplicationController # or from cache if already merged @commits = @merge_request.commits - # Close MR if nothing to merge - #@merge_request.mark_as_merged! if @merge_request.probably_merged? - respond_to do |format| format.html format.js @@ -75,8 +72,7 @@ class MergeRequestsController < ApplicationController respond_to do |format| if @merge_request.save - @merge_request.reloaded_commits - @merge_request.reloaded_diffs + @merge_request.reload_code format.html { redirect_to [@project, @merge_request], notice: 'Merge request was successfully created.' } format.json { render json: @merge_request, status: :created, location: @merge_request } else @@ -89,6 +85,7 @@ class MergeRequestsController < ApplicationController def update respond_to do |format| if @merge_request.update_attributes(params[:merge_request].merge(:author_id_of_changes => current_user.id)) + @merge_request.reload_code format.html { redirect_to [@project, @merge_request], notice: 'Merge request was successfully updated.' } format.json { head :ok } else diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 8f5c2f27..edf073d4 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -41,12 +41,21 @@ class MergeRequest < ActiveRecord::Base where("title like :query", :query => "%#{query}%") end + def self.find_all_by_branch(branch_name) + where("source_branch like :branch or target_branch like :branch", :branch => branch_name) + end + def validate_branches if target_branch == source_branch errors.add :base, "You can not use same branch for source and target branches" end end + def reload_code + self.reloaded_commits + self.reloaded_diffs + end + def new? today? && created_at == updated_at end @@ -72,10 +81,19 @@ class MergeRequest < ActiveRecord::Base commits.first end + def merged? + merged && merge_event + end + def merge_event self.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 + end + + # Return the number of +1 comments (upvotes) def upvotes notes.select(&:upvote?).size @@ -115,6 +133,17 @@ class MergeRequest < ActiveRecord::Base sort_by(&:created_at). reverse end + + def merge!(user_id) + self.mark_as_merged! + Event.create( + :project => self.project, + :action => Event::Merged, + :target_id => self.id, + :target_type => "MergeRequest", + :author_id => user_id + ) + end end # == Schema Information # diff --git a/app/models/project.rb b/app/models/project.rb index 9391ba9c..88111761 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -80,35 +80,18 @@ class Project < ActiveRecord::Base def update_merge_requests(oldrev, newrev, ref, author_key_id) return true unless ref =~ /heads/ branch_name = ref.gsub("refs/heads/", "") - - key = Key.find_by_identifier(author_key_id) - user = key.user - + user = Key.find_by_identifier(author_key_id).user c_ids = self.commits_between(oldrev, newrev).map(&:id) - # update commits & diffs for existing MR - mrs = self.merge_requests.opened.where(:source_branch => branch_name).all - mrs.each do |merge_request| - merge_request.reloaded_commits - merge_request.reloaded_diffs - end + # Update code for merge requests + mrs = self.merge_requests.opened.find_all_by_branch(branch_name).all + mrs.each { |merge_request| merge_request.reload_code } # Close merge requests mrs = self.merge_requests.opened.where(:target_branch => branch_name).all - mrs.each do |merge_request| - next unless merge_request.last_commit - # Mark as merged & create event if merged - if c_ids.include?(merge_request.last_commit.id) - merge_request.mark_as_merged! - Event.create( - :project => self, - :action => Event::Merged, - :target_id => merge_request.id, - :target_type => "MergeRequest", - :author_id => user.id - ) - end - end + mrs = mrs.select(&:last_commit).select { |mr| c_ids.include?(mr.last_commit.id) } + mrs.each { |merge_request| merge_request.merge!(user.id) } + true end diff --git a/app/views/events/_event_changed_issue.html.haml b/app/views/events/_event_changed_issue.html.haml index 65cfebbd..4f5d78af 100644 --- a/app/views/events/_event_changed_issue.html.haml +++ b/app/views/events/_event_changed_issue.html.haml @@ -1,10 +1,11 @@ = image_tag gravatar_icon(event.author_email), :class => "avatar" %strong #{event.author_name} -- if event.closed? - closed -- else - reopened -issue +%span.label.important + - if event.closed? + closed + - else + reopened + issue = link_to project_issue_path(event.project, event.issue) do %strong= truncate event.issue_title at diff --git a/app/views/events/_event_changed_merge_request.html.haml b/app/views/events/_event_changed_merge_request.html.haml index a55e609c..ff91375e 100644 --- a/app/views/events/_event_changed_merge_request.html.haml +++ b/app/views/events/_event_changed_merge_request.html.haml @@ -1,10 +1,11 @@ = image_tag gravatar_icon(event.author_email), :class => "avatar" %strong #{event.author_name} -- if event.closed? - closed -- else - reopened -merge request +%span.label.important + - if event.closed? + closed + - else + reopened + merge request = link_to project_merge_request_path(event.project, event.merge_request) do %strong= truncate event.merge_request_title at @@ -12,7 +13,6 @@ at %span.cgray = time_ago_in_words(event.created_at) ago. -%br %span.label= event.merge_request.source_branch → %span.label= event.merge_request.target_branch diff --git a/app/views/events/_event_new_issue.html.haml b/app/views/events/_event_new_issue.html.haml index 477ca48f..3d38d844 100644 --- a/app/views/events/_event_new_issue.html.haml +++ b/app/views/events/_event_new_issue.html.haml @@ -1,6 +1,7 @@ = image_tag gravatar_icon(event.author_email), :class => "avatar" %strong #{event.author_name} -created new issue +%span.label.success created + new issue = link_to project_issue_path(event.project, event.issue) do %strong= truncate event.issue_title at diff --git a/app/views/events/_event_new_merge_request.html.haml b/app/views/events/_event_new_merge_request.html.haml index e6895351..e3d8ab2a 100644 --- a/app/views/events/_event_new_merge_request.html.haml +++ b/app/views/events/_event_new_merge_request.html.haml @@ -1,6 +1,7 @@ = image_tag gravatar_icon(event.author_email), :class => "avatar" %strong #{event.author_name} -requested merge +%span.label.success requested + merge = link_to project_merge_request_path(event.project, event.merge_request) do %strong= truncate event.merge_request_title at @@ -8,7 +9,6 @@ at %span.cgray = time_ago_in_words(event.created_at) ago. -%br %span.label= event.merge_request.source_branch → %span.label= event.merge_request.target_branch diff --git a/app/views/events/_event_push.html.haml b/app/views/events/_event_push.html.haml index c59b482f..f09aac29 100644 --- a/app/views/events/_event_push.html.haml +++ b/app/views/events/_event_push.html.haml @@ -1,7 +1,8 @@ - if event.new_branch? || event.new_tag? = image_tag gravatar_icon(event.author_email), :class => "avatar" %strong #{event.author_name} - pushed new + %span.label.pushed pushed +  new - if event.new_tag? tag = link_to project_commits_path(event.project, :ref => event.tag_name) do @@ -18,7 +19,8 @@ - else = image_tag gravatar_icon(event.author_email), :class => "avatar" %strong #{event.author_name} - pushed to + %span.label.pushed pushed +  to = link_to project_commits_path(event.project, :ref => event.branch_name) do %strong= event.branch_name at @@ -30,10 +32,10 @@ = link_to compare_project_commits_path(event.project, :from => event.commits.first.prev_commit_id, :to => event.commits.last.id) do Compare #{event.commits.first.commit.id[0..8]}...#{event.commits.last.id[0..8]} - @project = event.project - %ul.unstyled - - if event.commits.size > 4 - = render event.commits[0..2] - %li ... and #{event.commits.size - 3} more commits + %ul.unstyled.event_commits + - if event.commits.size > 3 + = render event.commits[0...2] + %li ... and #{event.commits.size - 2} more commits - else = render event.commits diff --git a/app/views/issues/_show.html.haml b/app/views/issues/_show.html.haml index 7b25579f..78d50340 100644 --- a/app/views/issues/_show.html.haml +++ b/app/views/issues/_show.html.haml @@ -15,7 +15,7 @@ - if issue.today? %span.label.success today - if issue.notes.any? - %span.label= pluralize issue.notes.count, 'note' + %span.pretty_label= pluralize issue.notes.count, 'note' - if issue.upvotes > 0 %span.label.success= "+#{issue.upvotes}" diff --git a/app/views/merge_requests/_how_to_merge.html.haml b/app/views/merge_requests/_how_to_merge.html.haml index 19caca3f..5cf5e5bc 100644 --- a/app/views/merge_requests/_how_to_merge.html.haml +++ b/app/views/merge_requests/_how_to_merge.html.haml @@ -15,7 +15,7 @@ :javascript $(function(){ var modal = $('#modal_merge_info').modal({modal: true}); - $('.info_link').bind("click", function(){ + $('.how_to_merge_link').bind("click", function(){ modal.show(); }); $('.modal-header .close').bind("click", function(){ diff --git a/app/views/merge_requests/_merge_request.html.haml b/app/views/merge_requests/_merge_request.html.haml index 4b3470f9..9f556c06 100644 --- a/app/views/merge_requests/_merge_request.html.haml +++ b/app/views/merge_requests/_merge_request.html.haml @@ -6,7 +6,7 @@ = time_ago_in_words(merge_request.created_at) ago - if merge_request.notes.any? - %span.label= pluralize merge_request.notes.count, 'note' + %span.pretty_label= pluralize merge_request.notes.count, 'note' - if merge_request.upvotes > 0 %span.label.success= "+#{merge_request.upvotes}" .right diff --git a/app/views/merge_requests/show.html.haml b/app/views/merge_requests/show.html.haml index 44291cf4..a72813a0 100644 --- a/app/views/merge_requests/show.html.haml +++ b/app/views/merge_requests/show.html.haml @@ -26,23 +26,23 @@ %hr -- if @merge_request.closed - .alert-message.error Closed - - if @merge_request.merged - - event = @merge_request.merge_event - %div - %p - %strong #{event.author_name} - merged this request - %span.cgray - = time_ago_in_words(event.created_at) - ago. - %br -- else - .alert-message.success - = link_to "#", :class => "info_link", :title => "How To Merge" do - = image_tag "Info-UI.PNG" - Open +.merge_request_status_holder + - if @merge_request.closed + %h5 + .alert-message.error.status_info Closed + - if @merge_request.merged? + %span + Merged by #{@merge_request.merge_event.author_name} + %small #{time_ago_in_words(@merge_request.merge_event.created_at)} ago. + - elsif @merge_request.closed_event + %span + Closed by #{@merge_request.closed_event.author_name} + %small #{time_ago_in_words(@merge_request.closed_event.created_at)} ago. + %br + - else + %h5 + .alert-message.success.status_info Open + = link_to "How to merge", "#", :class => "vlink how_to_merge_link", :title => "How To Merge" = render "merge_requests/how_to_merge"