OSDN Git Service

Merge branch 'state-machine-stage-2' of https://github.com/Undev/gitlabhq into Undev...
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Tue, 26 Feb 2013 08:38:40 +0000 (10:38 +0200)
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Tue, 26 Feb 2013 08:38:40 +0000 (10:38 +0200)
Conflicts:
app/models/merge_request.rb

1  2 
app/controllers/merge_requests_controller.rb
app/models/merge_request.rb
app/models/project.rb
db/schema.rb

@@@ -24,6 -24,6 +24,8 @@@ require Rails.root.join("lib/static_mod
  class MergeRequest < ActiveRecord::Base
    include Issuable
  
++  BROKEN_DIFF = "--broken-diff"
++
    attr_accessible :title, :assignee_id, :target_branch, :source_branch, :milestone_id,
                    :author_id_of_changes, :state_event
  
      state :merged
    end
  
--  BROKEN_DIFF = "--broken-diff"
 -
+   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 :unchecked
  
-   UNCHECKED = 1
-   CAN_BE_MERGED = 2
-   CANNOT_BE_MERGED = 3
+     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) }
 -  scope :by_milestone, ->(milestone) { where("milestone_id = :milestone_id", milestone_id: milestone) }
+   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) }
 +
 +  # Closed scope for merge request should return
 +  # both merged and closed mr's
 +  scope :closed, -> { with_states(:closed, :merged) }
  
-   class << self
-     def find_all_by_branch(branch_name)
-       where("source_branch LIKE :branch OR target_branch LIKE :branch", branch: branch_name)
-     end
-     def cared(user)
-       where('assignee_id = :user OR author_id = :user', user: user.id)
-     end
-     def find_all_by_branch(branch_name)
-       where("source_branch LIKE :branch OR target_branch LIKE :branch", branch: branch_name)
-     end
-     def find_all_by_milestone(milestone)
-       where("milestone_id = :milestone_id", milestone_id: milestone)
-     end
-   end
-   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]
-   end
    def validate_branches
      if target_branch == source_branch
        errors.add :base, "You can not use same branch for source and target branches"
Simple merge
diff --cc db/schema.rb
@@@ -106,12 -106,13 +106,12 @@@ ActiveRecord::Schema.define(:version =
    add_index "milestones", ["project_id"], :name => "index_milestones_on_project_id"
  
    create_table "namespaces", :force => true do |t|
-     t.string   "name",       :null => false
-     t.string   "path",       :null => false
-     t.integer  "owner_id",   :null => false
-     t.datetime "created_at", :null => false
-     t.datetime "updated_at", :null => false
+     t.string   "name",                        :null => false
+     t.string   "path",                        :null => false
+     t.integer  "owner_id",                    :null => false
+     t.datetime "created_at",                  :null => false
+     t.datetime "updated_at",                  :null => false
      t.string   "type"
 -    t.string   "description", :default => "", :null => false
    end
  
    add_index "namespaces", ["name"], :name => "index_namespaces_on_name"
      t.string   "name"
      t.string   "path"
      t.text     "description"
-     t.datetime "created_at",                                :null => false
-     t.datetime "updated_at",                                :null => false
+     t.datetime "created_at",                                   :null => false
+     t.datetime "updated_at",                                   :null => false
      t.integer  "creator_id"
      t.string   "default_branch"
-     t.boolean  "issues_enabled",         :default => true,  :null => false
-     t.boolean  "wall_enabled",           :default => true,  :null => false
-     t.boolean  "merge_requests_enabled", :default => true,  :null => false
-     t.boolean  "wiki_enabled",           :default => true,  :null => false
+     t.boolean  "issues_enabled",         :default => true,     :null => false
+     t.boolean  "wall_enabled",           :default => true,     :null => false
+     t.boolean  "merge_requests_enabled", :default => true,     :null => false
+     t.boolean  "wiki_enabled",           :default => true,     :null => false
      t.integer  "namespace_id"
-     t.boolean  "public",                 :default => false, :null => false
+     t.boolean  "public",                 :default => false,    :null => false
 -    t.string   "issues_tracker",         :default => "gitlab", :null => false
 -    t.string   "issues_tracker_id"
    end
  
    add_index "projects", ["creator_id"], :name => "index_projects_on_owner_id"
      t.string   "name"
      t.string   "path"
      t.integer  "owner_id"
-     t.datetime "created_at", :null => false
-     t.datetime "updated_at", :null => false
+     t.datetime "created_at",                  :null => false
+     t.datetime "updated_at",                  :null => false
 -    t.string   "description", :default => "", :null => false
    end
  
    create_table "users", :force => true do |t|