|
|
|
require File.join(Rails.root, "app/models/commit")
|
|
|
|
|
|
|
class MergeRequest < ActiveRecord::Base
|
|
class MergeRequest < ActiveRecord::Base
|
|
|
belongs_to :project
|
|
belongs_to :project
|
|
|
belongs_to :author, :class_name => "User"
|
|
belongs_to :author, :class_name => "User"
|
|
|
belongs_to :assignee, :class_name => "User"
|
|
belongs_to :assignee, :class_name => "User"
|
|
|
has_many :notes, :as => :noteable, :dependent => :destroy
|
|
has_many :notes, :as => :noteable, :dependent => :destroy
|
|
|
|
|
|
|
|
|
serialize :st_commits
|
|
|
|
serialize :st_diffs
|
|
|
|
|
|
|
attr_protected :author, :author_id, :project, :project_id
|
|
attr_protected :author, :author_id, :project, :project_id
|
|
|
attr_accessor :author_id_of_changes
|
|
attr_accessor :author_id_of_changes
|
|
|
|
|
|
| ... | @@ -32,7 +37,6 @@ class MergeRequest < ActiveRecord::Base |
... | @@ -32,7 +37,6 @@ class MergeRequest < ActiveRecord::Base |
|
|
scope :closed, where(:closed => true)
|
|
scope :closed, where(:closed => true)
|
|
|
scope :assigned, lambda { |u| where(:assignee_id => u.id)}
|
|
scope :assigned, lambda { |u| where(:assignee_id => u.id)}
|
|
|
|
|
|
|
|
|
|
|
|
|
def validate_branches
|
|
def validate_branches
|
|
|
if target_branch == source_branch
|
|
if target_branch == source_branch
|
|
|
errors.add :base, "You can not use same branch for source and target branches"
|
|
errors.add :base, "You can not use same branch for source and target branches"
|
| ... | @@ -44,18 +48,65 @@ class MergeRequest < ActiveRecord::Base |
... | @@ -44,18 +48,65 @@ class MergeRequest < ActiveRecord::Base |
|
|
end
|
|
end
|
|
|
|
|
|
|
|
def diffs
|
|
def diffs
|
|
|
|
st_diffs || []
|
|
|
|
end
|
|
|
|
|
|
|
|
def reloaded_diffs
|
|
|
|
if open? && unmerged_diffs.any?
|
|
|
|
self.st_diffs = unmerged_diffs
|
|
|
|
save
|
|
|
|
end
|
|
|
|
diffs
|
|
|
|
end
|
|
|
|
|
|
|
|
def unmerged_diffs
|
|
|
commits = project.repo.commits_between(target_branch, source_branch).map {|c| Commit.new(c)}
|
|
commits = project.repo.commits_between(target_branch, source_branch).map {|c| Commit.new(c)}
|
|
|
diffs = project.repo.diff(commits.first.prev_commit.id, commits.last.id) rescue []
|
|
diffs = project.repo.diff(commits.first.prev_commit.id, commits.last.id) rescue []
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
def last_commit
|
|
def last_commit
|
|
|
project.commit(source_branch)
|
|
commits.first
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
# Return the number of +1 comments (upvotes)
|
|
# Return the number of +1 comments (upvotes)
|
|
|
def upvotes
|
|
def upvotes
|
|
|
notes.select(&:upvote?).size
|
|
notes.select(&:upvote?).size
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
def commits
|
|
|
|
st_commits || []
|
|
|
|
end
|
|
|
|
|
|
|
|
def probably_merged?
|
|
|
|
unmerged_commits.empty? &&
|
|
|
|
commits.any? && open?
|
|
|
|
end
|
|
|
|
|
|
|
|
def open?
|
|
|
|
!closed
|
|
|
|
end
|
|
|
|
|
|
|
|
def mark_as_merged!
|
|
|
|
self.merged = true
|
|
|
|
self.closed = true
|
|
|
|
save
|
|
|
|
end
|
|
|
|
|
|
|
|
def reloaded_commits
|
|
|
|
if open? && unmerged_commits.any?
|
|
|
|
self.st_commits = unmerged_commits
|
|
|
|
save
|
|
|
|
end
|
|
|
|
commits
|
|
|
|
end
|
|
|
|
|
|
|
|
def unmerged_commits
|
|
|
|
self.project.repo.
|
|
|
|
commits_between(self.target_branch, self.source_branch).
|
|
|
|
map {|c| Commit.new(c)}.
|
|
|
|
sort_by(&:created_at).
|
|
|
|
reverse
|
|
|
|
end
|
|
|
end
|
|
end
|
|
|
# == Schema Information
|
|
# == Schema Information
|
|
|
#
|
|
#
|
| ... | |
... | |
| ... | | ... | |