Class: Fbe::FakeOctokit
- Inherits:
-
Object
- Object
- Fbe::FakeOctokit
- Defined in:
- lib/fbe/octo.rb
Overview
Fake GitHub client, for tests.
Instance Method Summary collapse
- #add_comment(_repo, _issue, _text) ⇒ Object
- #issue_timeline(_repo, _issue, _options = {}) ⇒ Object
- #name_to_number(name) ⇒ Object
- #random_time ⇒ Object
- #rate_limit ⇒ Object
- #repositories(_user = nil) ⇒ Object
- #repository(name) ⇒ Object
- #repository_events(repo, _options = {}) ⇒ Object
- #search_issues(_query, _options = {}) ⇒ Object
- #user(name) ⇒ Object
Instance Method Details
#add_comment(_repo, _issue, _text) ⇒ Object
147 148 149 |
# File 'lib/fbe/octo.rb', line 147 def add_comment(_repo, _issue, _text) 42 end |
#issue_timeline(_repo, _issue, _options = {}) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/fbe/octo.rb', line 166 def issue_timeline(_repo, _issue, = {}) [ { actor: { id: 888, login: 'torvalds' }, repository: { id: name_to_number('yegor256/judges'), full_name: 'yegor256/judges' }, event: 'renamed', rename: { from: 'before', to: 'after' }, created_at: random_time }, { actor: { id: 888, login: 'torvalds' }, repository: { id: name_to_number('yegor256/judges'), full_name: 'yegor256/judges' }, event: 'labeled', label: { name: 'bug' }, created_at: random_time } ] end |
#name_to_number(name) ⇒ Object
109 110 111 112 |
# File 'lib/fbe/octo.rb', line 109 def name_to_number(name) return name unless name.is_a?(String) name.chars.map(&:ord).inject(0, :+) end |
#random_time ⇒ Object
105 106 107 |
# File 'lib/fbe/octo.rb', line 105 def random_time Time.now - rand(10_000) end |
#rate_limit ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/fbe/octo.rb', line 114 def rate_limit o = Object.new def o.remaining 100 end o end |
#repositories(_user = nil) ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/fbe/octo.rb', line 122 def repositories(_user = nil) [ { name: 'judges', full_name: 'yegor256/judges', id: 444 } ] end |
#repository(name) ⇒ Object
140 141 142 143 144 145 |
# File 'lib/fbe/octo.rb', line 140 def repository(name) { id: name_to_number(name), full_name: name.is_a?(Integer) ? 'yegor256/test' : name } end |
#repository_events(repo, _options = {}) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/fbe/octo.rb', line 202 def repository_events(repo, = {}) [ { id: '123', repo: { id: name_to_number(repo), name: repo }, type: 'PushEvent', payload: { push_id: 42 }, actor: { id: 888, login: 'torvalds' }, created_at: random_time }, { id: '124', repo: { id: name_to_number(repo), name: repo }, type: 'IssuesEvent', payload: { action: 'closed', issue: { number: 42 } }, actor: { id: 888, login: 'torvalds' }, created_at: random_time }, { id: '125', repo: { id: name_to_number(repo), name: repo }, type: 'IssuesEvent', payload: { action: 'opened', issue: { number: 42 } }, actor: { id: 888, login: 'torvalds' }, created_at: random_time } ] end |
#search_issues(_query, _options = {}) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/fbe/octo.rb', line 151 def search_issues(_query, = {}) { items: [ { number: 42, labels: [ { name: 'bug' } ] } ] } end |
#user(name) ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/fbe/octo.rb', line 132 def user(name) { id: 444, login: 'yegor256', type: name == 29_139_614 ? 'Bot' : 'User' } end |