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, #cancelable?, cast_id, #complete?, has, #include?, #initialize, #inspect, inspect_info, #load, many, #missing?, one, #relations, relations, #reload, #restartable?, 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)


84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/travis/client/repository.rb', line 84

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

#branch(name) ⇒ Object


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

def branch(name)
  last_on_branch.detect { |b| b.commit.branch == name.to_s }
end

#branchesObject


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

def branches
  last_on_branch.map { |b| { b.commit.branch => b } }.inject(:merge)
end

#build(number) ⇒ Object


103
104
105
# File 'lib/travis/client/repository.rb', line 103

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

#builds(params = nil) ⇒ Object


98
99
100
101
# File 'lib/travis/client/repository.rb', line 98

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

#disableObject


149
150
151
# File 'lib/travis/client/repository.rb', line 149

def disable
  set_hook(false)
end

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


124
125
126
127
128
129
130
131
132
133
134
# File 'lib/travis/client/repository.rb', line 124

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


153
154
155
# File 'lib/travis/client/repository.rb', line 153

def enable
  set_hook(true)
end

#encrypt(value) ⇒ Object


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

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

#job(number) ⇒ Object


136
137
138
139
140
141
142
# File 'lib/travis/client/repository.rb', line 136

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

#last_on_branch(name = nil) ⇒ Object


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

def last_on_branch(name = nil)
  return branch(name) if name
  attributes['last_on_branch'] ||= session.get('branches', :repository_id => id)['branches']
end

#nameObject


67
68
69
# File 'lib/travis/client/repository.rb', line 67

def name
  slug[/[^\/]+$/]
end

#public_keyObject Also known as: key


60
61
62
63
64
65
# File 'lib/travis/client/repository.rb', line 60

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=


71
72
73
74
# File 'lib/travis/client/repository.rb', line 71

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

#pusher_channelsObject


157
158
159
160
161
162
163
# File 'lib/travis/client/repository.rb', line 157

def pusher_channels
  attributes['pusher_channels'] ||= if session.private_channels?
    ["user-#{session.user.id}", "repo-#{id}"]
  else
    ["common"]
  end
end

#recent_buildsObject


107
108
109
# File 'lib/travis/client/repository.rb', line 107

def recent_builds
  builds({})
end

#set_hook(flag) ⇒ Object


144
145
146
147
# File 'lib/travis/client/repository.rb', line 144

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