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(_repo, sha) ⇒ Object
- #commit_pulls(repo, _sha) ⇒ Object
- #commits_since(repo, _since) ⇒ Object
- #create_commit_comment(_repo, sha, text) ⇒ Object
- #issue(repo, number) ⇒ Object
- #issue_comment_reactions(_name, _comment) ⇒ Object
- #issue_comments(_name, _number) ⇒ Object
- #issue_timeline(_repo, _issue, _options = {}) ⇒ Object
- #list_issues(repo, _options = {}) ⇒ Object
- #name_to_number(name) ⇒ Object
- #pull_request(repo, number) ⇒ Object
- #pull_request_comments(_name, _number) ⇒ Object
- #pull_request_review_comment_reactions(_name, _comment) ⇒ 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
- #workflow_run_usage(_repo, _id) ⇒ Object
Instance Method Details
#add_comment(_repo, _issue, _text) ⇒ Object
315 316 317 318 319 |
# File 'lib/fbe/octo.rb', line 315 def add_comment(_repo, _issue, _text) { id: 42 } end |
#commit(_repo, sha) ⇒ Object
387 388 389 390 391 392 393 394 |
# File 'lib/fbe/octo.rb', line 387 def commit(_repo, sha) { sha:, stats: { total: 123 } } end |
#commit_pulls(repo, _sha) ⇒ Object
276 277 278 279 280 |
# File 'lib/fbe/octo.rb', line 276 def commit_pulls(repo, _sha) [ pull_request(repo, 42) ] end |
#commits_since(repo, _since) ⇒ Object
380 381 382 383 384 385 |
# File 'lib/fbe/octo.rb', line 380 def commits_since(repo, _since) [ commit(repo, 'a1b2c3d4e5f6a1b2c3d4e5f6'), commit(repo, 'a1b2c3d4e5fff1b2c3d4e5f6') ] end |
#create_commit_comment(_repo, sha, text) ⇒ Object
321 322 323 324 325 326 327 328 329 330 |
# File 'lib/fbe/octo.rb', line 321 def create_commit_comment(_repo, sha, text) { commit_id: sha, id: 42, body: text, path: 'something.txt', line: 1, position: 1 } end |
#issue(repo, number) ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/fbe/octo.rb', line 289 def issue(repo, number) { id: 42, number:, repo: { full_name: repo }, pull_request: { merged_at: nil } } end |
#issue_comment_reactions(_name, _comment) ⇒ Object
679 680 681 682 683 684 685 686 687 688 689 690 |
# File 'lib/fbe/octo.rb', line 679 def issue_comment_reactions(_name, _comment) [ { id: 248_923_574, user: { login: 'user', id: 8_086_956 }, content: 'heart' } ] end |
#issue_comments(_name, _number) ⇒ Object
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 |
# File 'lib/fbe/octo.rb', line 619 def issue_comments(_name, _number) [ { pull_request_review_id: 2_227_372_510, id: 1_709_082_320, path: 'test/baza/test_locks.rb', commit_id: 'a9f5f94cf28f29a64d5dd96d0ee23b4174572847', original_commit_id: 'e8c6f94274d14ed3cb26fe71467a9c3f229df59c', user: { login: 'Reviewer', id: 2_566_462 }, body: 'reviewer comment', created_at: '2024-08-08T09:41:46Z', updated_at: '2024-08-08T09:42:46Z', reactions: { url: 'https://api.github.com/repos/zerocracy/baza/pulls/comments/1709082320/reactions', total_count: 1 }, start_line: 'null', original_start_line: 'null', start_side: 'null', line: 'null', original_line: 62, side: 'RIGHT', original_position: 25, position: 'null', subject_type: 'line' }, { pull_request_review_id: 2_227_372_510, id: 1_709_082_321, path: 'test/baza/test_locks.rb', commit_id: 'a9f5f94cf28f29a64d5dd96d0ee23b4174572847', original_commit_id: 'e8c6f94274d14ed3cb26fe71467a9c3f229df59c', user: { login: 'test', id: 88_084_038 }, body: 'author comment', created_at: '2024-08-08T09:42:46Z', updated_at: '2024-08-08T09:42:46Z', reactions: { url: 'https://api.github.com/repos/zerocracy/baza/pulls/comments/1709082321/reactions', total_count: 1 }, start_line: 'null', original_start_line: 'null', start_side: 'null', line: 'null', original_line: 62, side: 'RIGHT', original_position: 25, in_reply_to_id: 1_709_082_318, position: 'null', subject_type: 'line' } ] end |
#issue_timeline(_repo, _issue, _options = {}) ⇒ Object
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'lib/fbe/octo.rb', line 396 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 |
#list_issues(repo, _options = {}) ⇒ Object
282 283 284 285 286 287 |
# File 'lib/fbe/octo.rb', line 282 def list_issues(repo, = {}) [ issue(repo, 42), issue(repo, 43) ] end |
#name_to_number(name) ⇒ Object
144 145 146 147 |
# File 'lib/fbe/octo.rb', line 144 def name_to_number(name) return name unless name.is_a?(String) name.chars.map(&:ord).inject(0, :+) end |
#pull_request(repo, number) ⇒ Object
302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/fbe/octo.rb', line 302 def pull_request(repo, number) { id: 42, number:, repo: { full_name: repo }, additions: 12, deletions: 5, changed_files: 3 } end |
#pull_request_comments(_name, _number) ⇒ Object
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
# File 'lib/fbe/octo.rb', line 559 def pull_request_comments(_name, _number) [ { pull_request_review_id: 2_227_372_510, id: 1_709_082_318, path: 'test/baza/test_locks.rb', commit_id: 'a9f5f94cf28f29a64d5dd96d0ee23b4174572847', original_commit_id: 'e8c6f94274d14ed3cb26fe71467a9c3f229df59c', user: { login: 'Reviewer', id: 2_566_462 }, body: 'Most likely, parentheses were missed here.', created_at: '2024-08-08T09:41:46Z', updated_at: '2024-08-08T09:42:46Z', reactions: { url: 'https://api.github.com/repos/zerocracy/baza/pulls/comments/1709082318/reactions', total_count: 0 }, start_line: 'null', original_start_line: 'null', start_side: 'null', line: 'null', original_line: 62, side: 'RIGHT', original_position: 25, position: 'null', subject_type: 'line' }, { pull_request_review_id: 2_227_372_510, id: 1_709_082_319, path: 'test/baza/test_locks.rb', commit_id: 'a9f5f94cf28f29a64d5dd96d0ee23b4174572847', original_commit_id: 'e8c6f94274d14ed3cb26fe71467a9c3f229df59c', user: { login: 'test', id: 88_084_038 }, body: 'definitely a typo', created_at: '2024-08-08T09:42:46Z', updated_at: '2024-08-08T09:42:46Z', reactions: { url: 'https://api.github.com/repos/zerocracy/baza/pulls/comments/1709082319/reactions', total_count: 0 }, start_line: 'null', original_start_line: 'null', start_side: 'null', line: 'null', original_line: 62, side: 'RIGHT', original_position: 25, in_reply_to_id: 1_709_082_318, position: 'null', subject_type: 'line' } ] end |
#pull_request_review_comment_reactions(_name, _comment) ⇒ Object
692 693 694 695 696 697 698 699 700 701 702 703 |
# File 'lib/fbe/octo.rb', line 692 def pull_request_review_comment_reactions(_name, _comment) [ { id: 248_923_574, user: { login: 'user', id: 8_086_956 }, content: 'heart' } ] end |
#random_time ⇒ Object
140 141 142 |
# File 'lib/fbe/octo.rb', line 140 def random_time Time.now - rand(10_000) end |
#rate_limit ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/fbe/octo.rb', line 149 def rate_limit o = Object.new def o.remaining 100 end o end |
#release(_url) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/fbe/octo.rb', line 224 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
217 218 219 220 221 222 |
# File 'lib/fbe/octo.rb', line 217 def releases(_repo, _opts = {}) [ release('https://github...'), release('https://gith') ] end |
#repositories(_user = nil) ⇒ Object
157 158 159 160 161 162 |
# File 'lib/fbe/octo.rb', line 157 def repositories(_user = nil) [ repository('yegor256/judges'), repository('yegor256/factbase') ] end |
#repository(name) ⇒ Object
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 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/fbe/octo.rb', line 238 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: name == 'zerocracy/datum', 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
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 |
# File 'lib/fbe/octo.rb', line 432 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 }, { id: 42, created_at: Time.now, actor: { id: 42 }, type: 'PullRequestEvent', repo: { id: repo }, payload: { action: 'closed', number: 172, ref_type: 'tag', ref: 'foo', pull_request: { url: 'https://api.github.com/repos/yegor256/judges/pulls/93', id: 1_990_323_142, node_id: 'PR_kwDOL6GCO852oevG', number: 172, state: 'closed', locked: false, title: '#999 new feature', user: { login: 'test', id: 88_084_038, node_id: 'MDQ6VXNlcjE2NDYwMjA=', type: 'User', site_admin: false }, base: { label: 'zerocracy:master', ref: 'master', user: { login: 'zerocracy', id: 24_234_201 }, repo: { id: repo, node_id: 'R_kgDOK2_4Aw', name: 'baza', full_name: 'zerocracy/baza', private: false } }, head: { ref: 'zerocracy/baza' }, merged_at: Time.now, comments: 2, review_comments: 2, commits: 1, additions: 3, deletions: 3, changed_files: 2 } } } ] end |
#repository_workflow_runs(repo, _opts = {}) ⇒ Object
174 175 176 177 178 179 180 181 182 |
# File 'lib/fbe/octo.rb', line 174 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
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 |
# File 'lib/fbe/octo.rb', line 332 def search_issues(query, = {}) if query.include?('type:pr') && query.include?('is:unmerged') { total_count: 1, incomplete_results: false, items: [ { id: 42, number: 10, title: 'Awesome PR 10' } ] } elsif query.include?('type:pr') { total_count: 2, incomplete_results: false, items: [ { id: 42, number: 10, title: 'Awesome PR 10' }, { id: 43, number: 11, title: 'Awesome PR 11' } ] } else { total_count: 1, incomplete_results: false, items: [ { number: 42, labels: [ { name: 'bug' } ] } ] } end end |
#user(name) ⇒ Object
164 165 166 167 168 169 170 171 172 |
# File 'lib/fbe/octo.rb', line 164 def user(name) login = name login = name == 526_301 ? 'yegor256' : 'torvalds' if login.is_a?(Integer) { id: 444, login:, type: name == 29_139_614 ? 'Bot' : 'User' } end |
#workflow_run(repo, id) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/fbe/octo.rb', line 184 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 |
#workflow_run_usage(_repo, _id) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/fbe/octo.rb', line 199 def workflow_run_usage(_repo, _id) { billable: { UBUNTU: { total_ms: 0, jobs: 1, job_runs: [ { job_id: 1, duration_ms: 0 } ] } }, run_duration_ms: 53_000 } end |