Class: Travis::Client::Repository

Inherits:
Entity
  • Object
show all
Includes:
States
Defined in:
lib/travis/client/repository.rb

Defined Under Namespace

Classes: Key

Constant Summary

Constants included from States

States::STATES

Constants inherited from Entity

Entity::MAP

Instance Attribute Summary collapse

Attributes inherited from Entity

#attributes, #curry, #id, #session

Instance Method Summary collapse

Methods included from States

#canceled?, #color, #created?, #errored?, #failed?, #finished?, #green?, #passed?, #pending?, #queued?, #ready?, #red?, #running?, #started?, #unsuccessful?, #yellow?

Methods inherited from Entity

#[], #[]=, aka, #attribute_names, attributes, cast_id, #complete?, has, #include?, #initialize, #inspect, inspect_info, #load, many, #missing?, one, relations, #relations, #reload, subclass_for, subclasses, time, #update_attributes

Constructor Details

This class inherits a constructor from Travis::Client::Entity

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



1
2
3
# File 'lib/travis/client/repository.rb', line 1

def description
  @description
end

#last_buildObject (readonly)



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/travis/client/repository.rb', line 64

def last_build
  return unless last_build_id
  attributes['last_build'] ||= begin
    last_build               = session.find_one(Build, last_build_id)
    last_build.number        = last_build_number
    last_build.state         = last_build_state
    last_build.duration      = last_build_duration
    last_build.started_at    = last_build_started_at
    last_build.finished_at   = last_build_finished_at
    last_build.repository_id = id
    last_build
  end
end

#slugObject (readonly)

Returns the value of attribute slug.



1
2
3
# File 'lib/travis/client/repository.rb', line 1

def slug
  @slug
end

Instance Method Details

#build(number) ⇒ Object



83
84
85
# File 'lib/travis/client/repository.rb', line 83

def build(number)
  builds(:number => number.to_s).first
end

#builds(params = nil) ⇒ Object



78
79
80
81
# File 'lib/travis/client/repository.rb', line 78

def builds(params = nil)
  return each_build unless params
  session.find_many(Build, params.merge(:repository_id => id))
end

#disableObject



116
117
118
# File 'lib/travis/client/repository.rb', line 116

def disable
  set_hook(false)
end

#each_build(params = nil, &block) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/travis/client/repository.rb', line 91

def each_build(params = nil, &block)
  return enum_for(__method__, params) unless block_given?
  params ||= {}
  chunk = builds(params)
  until chunk.empty?
    chunk.each(&block)
    number = chunk.last.number
    chunk  = number == '1' ? [] : builds(params.merge(:after_number => number))
  end
  self
end

#enableObject



120
121
122
# File 'lib/travis/client/repository.rb', line 120

def enable
  set_hook(true)
end

#encrypt(value) ⇒ Object



59
60
61
# File 'lib/travis/client/repository.rb', line 59

def encrypt(value)
  key.encrypt(value)
end

#job(number) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/travis/client/repository.rb', line 103

def job(number)
  build_number = number.to_s[/^\d+/]
  build        = build(build_number)
  job          = build.jobs.detect { |j| j.number == number } if number != build_number
  job        ||= build.jobs.first if build and build.jobs.size == 1
  job
end

#public_keyObject Also known as: key



44
45
46
47
48
49
# File 'lib/travis/client/repository.rb', line 44

def public_key
  attributes["public_key"] ||= begin
    payload = session.get_raw("/repos/#{id}/key")
    Key.new(payload.fetch('key'))
  end
end

#public_key=(key) ⇒ Object Also known as: key=



51
52
53
54
# File 'lib/travis/client/repository.rb', line 51

def public_key=(key)
  key = Key.new(key) unless key.is_a? Key
  set_attribute(:public_key, key)
end

#recent_buildsObject



87
88
89
# File 'lib/travis/client/repository.rb', line 87

def recent_builds
  builds({})
end

#set_hook(flag) ⇒ Object



111
112
113
114
# File 'lib/travis/client/repository.rb', line 111

def set_hook(flag)
  result = session.put_raw('/hooks/', :hook => { :id => id, :active => flag })
  result['result']
end