Class: Request

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
States
Defined in:
lib/travis/model/request.rb,
lib/travis/model/request/states.rb,
lib/travis/model/request/payload.rb,
lib/travis/model/request/branches.rb,
lib/travis/model/request/payload/github.rb

Defined Under Namespace

Modules: Branches, Payload, States

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.commit_for(payload, repository) ⇒ Object



27
28
29
# File 'lib/travis/model/request.rb', line 27

def commit_for(payload, repository)
  Commit.create!(payload.attributes[:commit].merge(:repository_id => repository.id))
end

.create_from(payload, token) ⇒ Object

TODO clean this up



12
13
14
15
16
17
18
19
# File 'lib/travis/model/request.rb', line 12

def create_from(payload, token)
  payload = Payload::Github.new(payload, token)
  unless payload.reject?
    repository = repository_for(payload.repository)
    commit = commit_for(payload, repository)
    repository.requests.create!(payload.attributes.merge(:state => :created, :commit => commit))
  end
end

.repository_for(payload) ⇒ Object



21
22
23
24
25
# File 'lib/travis/model/request.rb', line 21

def repository_for(payload)
  Repository.find_or_create_by_owner_name_and_name(payload.owner_name, payload.name).tap do |repository|
    repository.update_attributes!(payload.to_hash)
  end
end

Instance Method Details

#create_build!Object



45
46
47
# File 'lib/travis/model/request.rb', line 45

def create_build!
  build = builds.create!(:repository => repository, :commit => commit, :config => config)
end