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
150 151 152 153 154 |
# File 'lib/fbe/octo.rb', line 150 def add_comment(_repo, _issue, _text) { id: 42 } end |
#issue_timeline(_repo, _issue, _options = {}) ⇒ Object
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 201 202 203 204 205 |
# File 'lib/fbe/octo.rb', line 171 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
112 113 114 115 |
# File 'lib/fbe/octo.rb', line 112 def name_to_number(name) return name unless name.is_a?(String) name.chars.map(&:ord).inject(0, :+) end |
#random_time ⇒ Object
108 109 110 |
# File 'lib/fbe/octo.rb', line 108 def random_time Time.now - rand(10_000) end |
#rate_limit ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/fbe/octo.rb', line 117 def rate_limit o = Object.new def o.remaining 100 end o end |
#repositories(_user = nil) ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/fbe/octo.rb', line 125 def repositories(_user = nil) [ { name: 'judges', full_name: 'yegor256/judges', id: 444 } ] end |
#repository(name) ⇒ Object
143 144 145 146 147 148 |
# File 'lib/fbe/octo.rb', line 143 def repository(name) { id: name_to_number(name), full_name: name.is_a?(Integer) ? 'yegor256/test' : name } end |
#repository_events(repo, _options = {}) ⇒ Object
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 260 261 262 263 264 |
# File 'lib/fbe/octo.rb', line 207 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
156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/fbe/octo.rb', line 156 def search_issues(_query, = {}) { items: [ { number: 42, labels: [ { name: 'bug' } ] } ] } end |
#user(name) ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/fbe/octo.rb', line 135 def user(name) { id: 444, login: 'yegor256', type: name == 29_139_614 ? 'Bot' : 'User' } end |