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
- #commit_pulls(repo, _sha) ⇒ Object
- #create_commit_comment(_repo, sha, text) ⇒ Object
- #issue_timeline(_repo, _issue, _options = {}) ⇒ Object
- #name_to_number(name) ⇒ Object
- #pull_request(repo, number) ⇒ Object
- #random_time ⇒ Object
- #rate_limit ⇒ Object
- #release(_url) ⇒ Object
- #releases(_repo, _opts = {}) ⇒ Object
- #repositories(_user = nil) ⇒ Object
- #repository(name) ⇒ Object
- #repository_events(repo, _options = {}) ⇒ Object
- #repository_workflow_runs(repo, _opts = {}) ⇒ Object
- #search_issues(_query, _options = {}) ⇒ Object
- #user(name) ⇒ Object
- #workflow_run(repo, id) ⇒ Object
Instance Method Details
#add_comment(_repo, _issue, _text) ⇒ Object
256 257 258 259 260 |
# File 'lib/fbe/octo.rb', line 256 def add_comment(_repo, _issue, _text) { id: 42 } end |
#commit_pulls(repo, _sha) ⇒ Object
240 241 242 243 244 |
# File 'lib/fbe/octo.rb', line 240 def commit_pulls(repo, _sha) [ pull_request(repo, 42) ] end |
#create_commit_comment(_repo, sha, text) ⇒ Object
262 263 264 265 266 267 268 269 270 271 |
# File 'lib/fbe/octo.rb', line 262 def create_commit_comment(_repo, sha, text) { commit_id: sha, id: 42, body: text, path: 'something.txt', line: 1, position: 1 } end |
#issue_timeline(_repo, _issue, _options = {}) ⇒ Object
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/fbe/octo.rb', line 288 def issue_timeline(_repo, _issue, = {}) [ { event: 'renamed', actor: { id: 888, login: 'torvalds' }, repository: { id: name_to_number('yegor256/judges'), full_name: 'yegor256/judges' }, rename: { from: 'before', to: 'after' }, created_at: random_time }, { event: 'labeled', actor: { id: 888, login: 'torvalds' }, repository: { id: name_to_number('yegor256/judges'), full_name: 'yegor256/judges' }, label: { name: 'bug' }, created_at: random_time } ] end |
#name_to_number(name) ⇒ Object
128 129 130 131 |
# File 'lib/fbe/octo.rb', line 128 def name_to_number(name) return name unless name.is_a?(String) name.chars.map(&:ord).inject(0, :+) end |
#pull_request(repo, number) ⇒ Object
246 247 248 249 250 251 252 253 254 |
# File 'lib/fbe/octo.rb', line 246 def pull_request(repo, number) { id: 42, number:, repo: { full_name: repo } } end |
#random_time ⇒ Object
124 125 126 |
# File 'lib/fbe/octo.rb', line 124 def random_time Time.now - rand(10_000) end |
#rate_limit ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/fbe/octo.rb', line 133 def rate_limit o = Object.new def o.remaining 100 end o end |
#release(_url) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/fbe/octo.rb', line 188 def release(_url) { node_id: 'RE_kwDOL6GCO84J7Cen', tag_name: '0.19.0', target_commitish: 'master', name: 'just a fake name', draft: false, prerelease: false, created_at: random_time, published_at: random_time, assets: [] } end |
#releases(_repo, _opts = {}) ⇒ Object
181 182 183 184 185 186 |
# File 'lib/fbe/octo.rb', line 181 def releases(_repo, _opts = {}) [ release('https://github...'), release('https://gith') ] end |
#repositories(_user = nil) ⇒ Object
141 142 143 144 145 146 |
# File 'lib/fbe/octo.rb', line 141 def repositories(_user = nil) [ repository('yegor256/judges'), repository('yegor256/factbase') ] end |
#repository(name) ⇒ 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 |
# File 'lib/fbe/octo.rb', line 202 def repository(name) { id: name_to_number(name), full_name: name.is_a?(Integer) ? 'yegor256/test' : name, default_branch: 'master', private: false, owner: { login: name.to_s.split('/')[0], id: 526_301, site_admin: false }, html_url: "https://github.com/#{name}", description: 'something', fork: false, url: "https://github.com/#{name}", created_at: random_time, updated_at: random_time, pushed_at: random_time, size: 470, stargazers_count: 1, watchers_count: 1, language: 'Ruby', has_issues: true, has_projects: true, has_downloads: true, has_wiki: true, has_pages: false, has_discussions: false, forks_count: 0, archived: false, disabled: false, open_issues_count: 6, license: { key: 'mit', name: 'MIT License' }, allow_forking: true, is_template: false, visibility: 'public', forks: 0, open_issues: 6, watchers: 1 } end |
#repository_events(repo, _options = {}) ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/fbe/octo.rb', line 324 def repository_events(repo, = {}) [ { id: '123', type: 'PushEvent', repo: { id: name_to_number(repo), name: repo, url: "https://api.github.com/repos/#{repo}" }, payload: { push_id: 42, ref: 'refs/heads/master', size: 1, distinct_size: 0, head: 'b7089c51cc2526a0d2619d35379f921d53c72731', before: '12d3bff1a55bad50ee2e8f29ade7f1c1e07bb025' }, actor: { id: 888, login: 'torvalds', display_login: 'torvalds' }, created_at: random_time, public: true }, { id: '124', type: 'IssuesEvent', repo: { id: name_to_number(repo), name: repo, url: "https://api.github.com/repos/#{repo}" }, payload: { action: 'closed', issue: { number: 42 } }, actor: { id: 888, login: 'torvalds', display_login: 'torvalds' }, created_at: random_time, public: true }, { id: '125', type: 'IssuesEvent', repo: { id: name_to_number(repo), name: repo, url: "https://api.github.com/repos/#{repo}" }, payload: { action: 'opened', issue: { number: 42 } }, actor: { id: 888, login: 'torvalds', display_login: 'torvalds' }, created_at: random_time, public: true } ] end |
#repository_workflow_runs(repo, _opts = {}) ⇒ Object
156 157 158 159 160 161 162 163 164 |
# File 'lib/fbe/octo.rb', line 156 def repository_workflow_runs(repo, _opts = {}) { total_count: 2, workflow_runs: [ workflow_run(repo, 42), workflow_run(repo, 7) ] } end |
#search_issues(_query, _options = {}) ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/fbe/octo.rb', line 273 def search_issues(_query, = {}) { items: [ { number: 42, labels: [ { name: 'bug' } ] } ] } end |
#user(name) ⇒ Object
148 149 150 151 152 153 154 |
# File 'lib/fbe/octo.rb', line 148 def user(name) { id: 444, login: 'yegor256', type: name == 29_139_614 ? 'Bot' : 'User' } end |
#workflow_run(repo, id) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/fbe/octo.rb', line 166 def workflow_run(repo, id) { id:, name: 'copyrights', head_branch: 'master', head_sha: '7d34c53e6743944dbf6fc729b1066bcbb3b18443', event: 'push', status: 'completed', conclusion: 'success', workflow_id: id, created_at: random_time, repository: repository(repo) } end |