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