BROKEN_DIFF = "--broken-diff"
- UNCHECKED = 1
- CAN_BE_MERGED = 2
- CANNOT_BE_MERGED = 3
+ state_machine :merge_status, initial: :unchecked do
+ event :mark_as_unchecked do
+ transition [:can_be_merged, :cannot_be_merged] => :unchecked
+ end
+
+ event :mark_as_mergeable do
+ transition unchecked: :can_be_merged
+ end
+
+ event :mark_as_unmergeable do
+ transition unchecked: :cannot_be_merged
+ end
+
+ state :unchecked
+
+ state :can_be_merged
+
+ state :cannot_be_merged
+ end
serialize :st_commits
serialize :st_diffs
validates :source_branch, presence: true
validates :target_branch, presence: true
- validate :validate_branches
+ validate :validate_branches
scope :merged, -> { with_state(:merged) }
end
end
+ # DEPRECATED: Please use human_merge_status_name instead
def human_merge_status
- merge_statuses = {
- CAN_BE_MERGED => "can_be_merged",
- CANNOT_BE_MERGED => "cannot_be_merged",
- UNCHECKED => "unchecked"
- }
- merge_statuses[self.merge_status]
+ human_merge_status_name
end
def validate_branches
self.reloaded_diffs
end
- def unchecked?
- merge_status == UNCHECKED
- end
-
- def mark_as_unchecked
- self.merge_status = UNCHECKED
- self.save
- end
-
- def can_be_merged?
- merge_status == CAN_BE_MERGED
- end
-
def check_if_can_be_merged
- self.merge_status = if Gitlab::Satellite::MergeAction.new(self.author, self).can_be_merged?
- CAN_BE_MERGED
- else
- CANNOT_BE_MERGED
- end
- self.save
+ if Gitlab::Satellite::MergeAction.new(self.author, self).can_be_merged?
+ mark_as_mergeable
+ else
+ mark_as_unmergeable
+ end
end
def diffs
commits.any? && opened?
end
- def mark_as_unmergable
- self.merge_status = CANNOT_BE_MERGED
- self.save
- end
-
def reloaded_commits
if opened? && unmerged_commits.any?
self.st_commits = unmerged_commits
true
end
rescue
- self.mark_as_unmergable
+ mark_as_unmergeable
false
end
$(function(){
merge_request = new MergeRequest({
url_to_automerge_check: "#{automerge_check_project_merge_request_path(@project, @merge_request)}",
- check_enable: #{@merge_request.merge_status == MergeRequest::UNCHECKED ? "true" : "false"},
+ check_enable: #{@merge_request.unchecked? ? "true" : "false"},
url_to_ci_check: "#{ci_status_project_merge_request_path(@project, @merge_request)}",
ci_enable: #{@project.gitlab_ci? ? "true" : "false"},
current_status: "#{@merge_request.human_merge_status}",