| 1 | import { execFile } from 'node:child_process'; |
| 2 | import { mkdtempSync, readFileSync |
| 3 | import { tmpdir } |
| 4 | import path from 'node:path |
| 5 | import { promisify } |
| 6 | |
| 7 | import type { INestApplication |
| 8 | import request from 'supertest |
| 9 | import TestAgent from 'supertest/lib/agent.js |
| 10 | import { afterAll, beforeAll |
| 11 | |
| 12 | import { GH_E2E_HOST, runGh |
| 13 | import { recordGhRequests, writeGhCapture |
| 14 | import { apiKey, hasBackends |
| 15 | |
| 16 | describe.skipIf(!hasBackends |
| 17 | let app: |
| 18 | let owner: |
| 19 | let configDir: |
| 20 | const username = |
| 21 | let api: |
| 22 | let token: |
| 23 | |
| 24 | const gh = |
| 25 | runGh(args, { |
| 26 | const ok = |
| 27 | args: string[] |
| 28 | options: { |
| 29 | ) => { |
| 30 | const result = |
| 31 | expect(result, result |
| 32 | return result.stdout |
| 33 | }; |
| 34 | |
| 35 | beforeAll(async () |
| 36 | const { key, |
| 37 | ({ app } |
| 38 | { |
| 39 | BETTER_AUTH_URL: `https://${GH_E2E_HOST |
| 40 | WEB_APP_URL: `https://web.${GH_E2E_HOST |
| 41 | }, |
| 42 | 443, |
| 43 | { key, cert |
| 44 | (app) => |
| 45 | )); |
| 46 | owner = await |
| 47 | configDir = mkdtempSync( |
| 48 | // The app serves the self-signed e2e certificate, which supertest must be told to trust. |
| 49 | api = request. |
| 50 | await api |
| 51 | .post('/api/repositories') |
| 52 | .set('cookie', |
| 53 | .send({ name: |
| 54 | .expect(201); |
| 55 | const work = |
| 56 | const git = |
| 57 | promisify(execFile)('git |
| 58 | cwd: work, |
| 59 | env: { ...process |
| 60 | }); |
| 61 | await git('init |
| 62 | writeFileSync( |
| 63 | path.join(work |
| 64 | '# Tools\n\nHello from Ghost.\n', |
| 65 | ); |
| 66 | await git('add |
| 67 | await git( |
| 68 | '-c', |
| 69 | 'user.name=E2E', |
| 70 | '-c', |
| 71 | 'user.email=e2e@example.com', |
| 72 | 'commit', |
| 73 | '-qm', |
| 74 | 'readme', |
| 75 | ); |
| 76 | await git( |
| 77 | 'push', |
| 78 | '-q', |
| 79 | `https://${username}:${ |
| 80 | 'main', |
| 81 | ); |
| 82 | // Two branches for the gh pr cases: one to merge, one to close and reopen. |
| 83 | for (const [branch |
| 84 | ['feature', 'feature.txt' |
| 85 | ['chore', 'chore.txt' |
| 86 | ]) { |
| 87 | await git('checkout |
| 88 | writeFileSync(path.join |
| 89 | await git('add |
| 90 | await git( |
| 91 | '-c', |
| 92 | 'user.name=E2E', |
| 93 | '-c', |
| 94 | 'user.email=e2e@example.com', |
| 95 | 'commit', |
| 96 | '-qm', |
| 97 | `Add ${file}`, |
| 98 | ); |
| 99 | await git( |
| 100 | 'push', |
| 101 | '-q', |
| 102 | `https://${username}:${ |
| 103 | branch, |
| 104 | ); |
| 105 | } |
| 106 | for (const title |
| 107 | await api |
| 108 | .post(`/api/repositories/${username |
| 109 | .set('cookie', |
| 110 | .send({ title |
| 111 | .expect(201); |
| 112 | } |
| 113 | await api |
| 114 | .post(`/api/repositories/${username |
| 115 | .set('cookie', |
| 116 | .send({ body: |
| 117 | .expect(201); |
| 118 | await api |
| 119 | .post(`/api/repositories/${username |
| 120 | .set('cookie', |
| 121 | .send({ name: |
| 122 | .expect(201); |
| 123 | }); |
| 124 | |
| 125 | // A key allows 120 requests a minute, which the whole suite on one key would pass. |
| 126 | beforeEach(async () |
| 127 | token = await |
| 128 | }); |
| 129 | |
| 130 | afterAll(async () |
| 131 | writeGhCapture({ login: |
| 132 | await app?.close |
| 133 | if (configDir) rmSync |
| 134 | }); |
| 135 | |
| 136 | it('reaches /api/graphql through gh api graphql', |
| 137 | const out = |
| 138 | expect(JSON.parse |
| 139 | }); |
| 140 | it('logs in with a pasted token and reports it in auth status', |
| 141 | const login = |
| 142 | ['auth', 'login' |
| 143 | { configDir, input: |
| 144 | ); |
| 145 | expect(login, login |
| 146 | const status = |
| 147 | configDir, |
| 148 | }); |
| 149 | expect(status, status |
| 150 | expect(status.stdout |
| 151 | }); |
| 152 | |
| 153 | it('answers gh api user', |
| 154 | expect(JSON.parse |
| 155 | login: username, |
| 156 | }); |
| 157 | }); |
| 158 | |
| 159 | it('views a repository with its README', |
| 160 | const out = |
| 161 | expect(out).toContain |
| 162 | expect(out).toContain |
| 163 | }); |
| 164 | |
| 165 | it('views a repository as JSON', |
| 166 | const out = |
| 167 | 'repo', |
| 168 | 'view', |
| 169 | `${GH_E2E_HOST}/${username |
| 170 | '--json', |
| 171 | 'name,owner,visibility,defaultBranchRef', |
| 172 | ]); |
| 173 | expect(JSON.parse |
| 174 | name: 'tools', |
| 175 | owner: { login: username |
| 176 | visibility: 'PUBLIC', |
| 177 | defaultBranchRef: { name: ' |
| 178 | }); |
| 179 | }); |
| 180 | |
| 181 | it('clones a repository', |
| 182 | const target = |
| 183 | await ok(['repo |
| 184 | expect(readFileSync(path |
| 185 | 'Hello from Ghost.', |
| 186 | ); |
| 187 | }); |
| 188 | |
| 189 | it('lists issues', |
| 190 | const out = |
| 191 | 'issue', |
| 192 | 'list', |
| 193 | '-R', |
| 194 | `${GH_E2E_HOST}/${username |
| 195 | '--json', |
| 196 | 'number,title,state,labels,author,url', |
| 197 | ]); |
| 198 | const issues = |
| 199 | expect(issues.map |
| 200 | expect.arrayContaining(['Broken build |
| 201 | ); |
| 202 | expect(issues[0] |
| 203 | }); |
| 204 | |
| 205 | it('views an issue with comments', |
| 206 | const repo = |
| 207 | expect(await ok |
| 208 | 'Broken build', |
| 209 | ); |
| 210 | // Without a terminal, --comments prints only the comments. |
| 211 | expect( |
| 212 | await ok(['issue |
| 213 | ).toContain('Seen it too' |
| 214 | }); |
| 215 | |
| 216 | it('filters issues by state, label, author and assignee', |
| 217 | const out = |
| 218 | 'issue', |
| 219 | 'list', |
| 220 | '-R', |
| 221 | `${GH_E2E_HOST}/${username |
| 222 | '--state', |
| 223 | 'all', |
| 224 | '--author', |
| 225 | username, |
| 226 | '--json', |
| 227 | 'number', |
| 228 | ]); |
| 229 | expect(JSON.parse |
| 230 | }); |
| 231 | |
| 232 | it('searches issues', |
| 233 | const out = |
| 234 | 'issue', |
| 235 | 'list', |
| 236 | '-R', |
| 237 | `${GH_E2E_HOST}/${username |
| 238 | '--search', |
| 239 | 'build', |
| 240 | '--json', |
| 241 | 'title', |
| 242 | ]); |
| 243 | expect(JSON.parse |
| 244 | }); |
| 245 | |
| 246 | it('creates an issue with a label and an assignee', |
| 247 | const out = |
| 248 | 'issue', |
| 249 | 'create', |
| 250 | '-R', |
| 251 | `${GH_E2E_HOST}/${username |
| 252 | '--title', |
| 253 | 'Made by gh', |
| 254 | '--body', |
| 255 | 'Body', |
| 256 | '--label', |
| 257 | 'bug', |
| 258 | '--assignee', |
| 259 | username, |
| 260 | ]); |
| 261 | expect(out).toMatch |
| 262 | }); |
| 263 | |
| 264 | it('comments on, edits, closes and reopens an issue', |
| 265 | const repo = |
| 266 | await ok(['issue |
| 267 | await ok([ |
| 268 | 'issue', |
| 269 | 'edit', |
| 270 | '1', |
| 271 | '-R', |
| 272 | repo, |
| 273 | '--title', |
| 274 | 'Broken build (edited)', |
| 275 | '--add-label', |
| 276 | 'bug', |
| 277 | ]); |
| 278 | await ok(['issue |
| 279 | expect( |
| 280 | JSON.parse( |
| 281 | await ok([ |
| 282 | 'issue', |
| 283 | 'view', |
| 284 | '1', |
| 285 | '-R', |
| 286 | repo, |
| 287 | '--json', |
| 288 | 'state,title,labels', |
| 289 | ]), |
| 290 | ), |
| 291 | ).toMatchObject({ |
| 292 | state: 'CLOSED', |
| 293 | title: 'Broken build (edited)', |
| 294 | labels: [{ name: |
| 295 | }); |
| 296 | await ok(['issue |
| 297 | }); |
| 298 | |
| 299 | it('creates, edits, lists, clones and deletes labels', |
| 300 | const repo = |
| 301 | await ok([ |
| 302 | 'label', |
| 303 | 'create', |
| 304 | 'gh-made', |
| 305 | '-R', |
| 306 | repo, |
| 307 | '--color', |
| 308 | 'D93F0B', |
| 309 | '--description', |
| 310 | 'From gh', |
| 311 | ]); |
| 312 | await ok([ |
| 313 | 'label', |
| 314 | 'edit', |
| 315 | 'gh-made', |
| 316 | '-R', |
| 317 | repo, |
| 318 | '--name', |
| 319 | 'gh-edited', |
| 320 | '--color', |
| 321 | '0E8A16', |
| 322 | ]); |
| 323 | const labels = |
| 324 | await ok([ |
| 325 | 'label', |
| 326 | 'list', |
| 327 | '-R', |
| 328 | repo, |
| 329 | '--json', |
| 330 | 'name,color,description', |
| 331 | ]), |
| 332 | ); |
| 333 | expect(labels).toContainEqual |
| 334 | name: 'gh-edited', |
| 335 | color: '0e8a16', |
| 336 | description: 'From gh', |
| 337 | }); |
| 338 | |
| 339 | await api |
| 340 | .post('/api/repositories') |
| 341 | .set('cookie', |
| 342 | .send({ name: |
| 343 | .expect(201); |
| 344 | const target = |
| 345 | await ok(['label |
| 346 | const cloned = |
| 347 | await ok(['label |
| 348 | ); |
| 349 | expect(cloned).toContainEqual |
| 350 | |
| 351 | await ok(['label |
| 352 | const after = |
| 353 | await ok(['label |
| 354 | ); |
| 355 | expect(after).not |
| 356 | }); |
| 357 | |
| 358 | it('pages REST issue lists with gh api --paginate and edits a comment by id', |
| 359 | const repo = |
| 360 | const all = |
| 361 | await ok([ |
| 362 | 'api', |
| 363 | `${repo}/issues?state=all&per_page=1`, |
| 364 | '--paginate', |
| 365 | '--slurp', |
| 366 | ]), |
| 367 | ); |
| 368 | const single = |
| 369 | await ok(['api |
| 370 | ); |
| 371 | expect(all.flat |
| 372 | |
| 373 | const comment = |
| 374 | await ok(['api |
| 375 | ); |
| 376 | const edited = |
| 377 | await ok([ |
| 378 | 'api', |
| 379 | '-X', |
| 380 | 'PATCH', |
| 381 | `${repo}/issues/comments/${comment |
| 382 | '-f', |
| 383 | 'body=Edited via REST', |
| 384 | ]), |
| 385 | ); |
| 386 | expect(edited).toMatchObject |
| 387 | }); |
| 388 | |
| 389 | describe('gh pr', |
| 390 | const repo = |
| 391 | let number: |
| 392 | const view = |
| 393 | JSON.parse( |
| 394 | await ok(['pr |
| 395 | ); |
| 396 | |
| 397 | it('creates a pull request', |
| 398 | const out = |
| 399 | 'pr', |
| 400 | 'create', |
| 401 | '-R', |
| 402 | repo(), |
| 403 | '--head', |
| 404 | 'feature', |
| 405 | '--base', |
| 406 | 'main', |
| 407 | '--title', |
| 408 | 'Add a feature', |
| 409 | '--body', |
| 410 | 'Body from gh', |
| 411 | ]); |
| 412 | const match = |
| 413 | expect(match, out |
| 414 | number = match! |
| 415 | }); |
| 416 | |
| 417 | it('lists pull requests', |
| 418 | const list = |
| 419 | await ok([ |
| 420 | 'pr', |
| 421 | 'list', |
| 422 | '-R', |
| 423 | repo(), |
| 424 | '--json', |
| 425 | 'number,title,state,headRefName,baseRefName,isDraft,author', |
| 426 | ]), |
| 427 | ); |
| 428 | expect(list).toContainEqual |
| 429 | expect.objectContaining({ |
| 430 | number: Number(number |
| 431 | title: 'Add a feature', |
| 432 | state: 'OPEN', |
| 433 | headRefName: 'feature', |
| 434 | baseRefName: 'main', |
| 435 | isDraft: false, |
| 436 | author: expect.objectContaining |
| 437 | }), |
| 438 | ); |
| 439 | }); |
| 440 | |
| 441 | it('views a pull request', |
| 442 | expect( |
| 443 | await view( |
| 444 | 'number,title,body,state,headRefName,baseRefName,additions,deletions,changedFiles,files,commits,reviewDecision,mergeable,url', |
| 445 | ), |
| 446 | ).toMatchObject({ |
| 447 | number: Number(number |
| 448 | title: 'Add a feature', |
| 449 | body: 'Body from gh', |
| 450 | state: 'OPEN', |
| 451 | headRefName: 'feature', |
| 452 | baseRefName: 'main', |
| 453 | additions: 1, |
| 454 | deletions: 0, |
| 455 | changedFiles: 1, |
| 456 | files: [expect.objectContaining |
| 457 | commits: [ |
| 458 | expect.objectContaining({ |
| 459 | ], |
| 460 | url: expect.stringMatching |
| 461 | new RegExp(`/ |
| 462 | ), |
| 463 | }); |
| 464 | }); |
| 465 | |
| 466 | it('comments on a pull request and views it with comments', |
| 467 | await ok(['pr |
| 468 | expect( |
| 469 | await ok(['pr |
| 470 | ).toContain('Looks good' |
| 471 | }); |
| 472 | |
| 473 | it('shows pull request status', |
| 474 | expect(await ok |
| 475 | 'Add a feature', |
| 476 | ); |
| 477 | }); |
| 478 | |
| 479 | it('shows a pull request diff', |
| 480 | expect(await ok |
| 481 | 'diff --git a/feature.txt b/feature.txt', |
| 482 | ); |
| 483 | }); |
| 484 | |
| 485 | it('edits a pull request', |
| 486 | await ok([ |
| 487 | 'pr', |
| 488 | 'edit', |
| 489 | number, |
| 490 | '-R', |
| 491 | repo(), |
| 492 | '--title', |
| 493 | 'Add a feature (edited)', |
| 494 | '--add-label', |
| 495 | 'bug', |
| 496 | ]); |
| 497 | expect(await view |
| 498 | title: 'Add a feature (edited)', |
| 499 | labels: [expect.objectContaining |
| 500 | }); |
| 501 | }); |
| 502 | |
| 503 | it('converts a pull request to a draft and back', |
| 504 | await ok(['pr |
| 505 | expect(await view |
| 506 | await ok(['pr |
| 507 | expect(await view |
| 508 | }); |
| 509 | |
| 510 | it('checks out a pull request', |
| 511 | const target = |
| 512 | await ok(['repo |
| 513 | await ok(['pr |
| 514 | const { stdout |
| 515 | 'git', |
| 516 | ['rev-parse', '--abbrev-ref' |
| 517 | { cwd: target |
| 518 | ); |
| 519 | expect(stdout.trim |
| 520 | expect(readFileSync(path |
| 521 | 'feature\n', |
| 522 | ); |
| 523 | }); |
| 524 | |
| 525 | it('closes and reopens a pull request', |
| 526 | const out = |
| 527 | 'pr', |
| 528 | 'create', |
| 529 | '-R', |
| 530 | repo(), |
| 531 | '--head', |
| 532 | 'chore', |
| 533 | '--base', |
| 534 | 'main', |
| 535 | '--title', |
| 536 | 'A chore', |
| 537 | '--body', |
| 538 | '', |
| 539 | ]); |
| 540 | const chore = |
| 541 | await ok(['pr |
| 542 | expect( |
| 543 | JSON.parse( |
| 544 | await ok(['pr |
| 545 | ), |
| 546 | ).toEqual({ state |
| 547 | await ok(['pr |
| 548 | expect( |
| 549 | JSON.parse( |
| 550 | await ok(['pr |
| 551 | ), |
| 552 | ).toEqual({ state |
| 553 | }); |
| 554 | |
| 555 | it('merges a pull request', |
| 556 | await ok(['pr |
| 557 | expect(await view |
| 558 | state: 'MERGED', |
| 559 | mergedAt: expect.any |
| 560 | }); |
| 561 | }); |
| 562 | }); |
| 563 | |
| 564 | describe('gh release', |
| 565 | const repo = |
| 566 | const view = |
| 567 | JSON.parse( |
| 568 | await ok(['release |
| 569 | ); |
| 570 | const asset = |
| 571 | const file = |
| 572 | writeFileSync(file, ` |
| 573 | return file; |
| 574 | }; |
| 575 | |
| 576 | it('creates a release with an asset', |
| 577 | const out = |
| 578 | 'release', |
| 579 | 'create', |
| 580 | 'v1.0', |
| 581 | asset('notes.txt'), |
| 582 | '-R', |
| 583 | repo(), |
| 584 | '--target', |
| 585 | 'main', |
| 586 | '--title', |
| 587 | 'First release', |
| 588 | '--notes', |
| 589 | 'Notes from gh', |
| 590 | ]); |
| 591 | expect(out).toContain |
| 592 | }); |
| 593 | |
| 594 | it('lists releases', |
| 595 | expect( |
| 596 | JSON.parse( |
| 597 | await ok([ |
| 598 | 'release', |
| 599 | 'list', |
| 600 | '-R', |
| 601 | repo(), |
| 602 | '--json', |
| 603 | 'tagName,name,isDraft,isPrerelease,isLatest,publishedAt', |
| 604 | ]), |
| 605 | ), |
| 606 | ).toContainEqual( |
| 607 | expect.objectContaining({ |
| 608 | tagName: 'v1.0', |
| 609 | name: 'First release', |
| 610 | isDraft: false, |
| 611 | isPrerelease: false, |
| 612 | isLatest: true, |
| 613 | }), |
| 614 | ); |
| 615 | }); |
| 616 | |
| 617 | it('views a release', |
| 618 | expect( |
| 619 | await view( |
| 620 | 'v1.0', |
| 621 | 'tagName,name,body,isDraft,isPrerelease,author,assets,targetCommitish,url', |
| 622 | ), |
| 623 | ).toMatchObject({ |
| 624 | tagName: 'v1.0', |
| 625 | name: 'First release', |
| 626 | body: 'Notes from gh', |
| 627 | isDraft: false, |
| 628 | isPrerelease: false, |
| 629 | author: expect.objectContaining |
| 630 | assets: [expect.objectContaining |
| 631 | url: expect.stringMatching |
| 632 | new RegExp(`/ |
| 633 | ), |
| 634 | }); |
| 635 | }); |
| 636 | |
| 637 | it('views the latest release', |
| 638 | expect( |
| 639 | JSON.parse( |
| 640 | await ok(['release |
| 641 | ), |
| 642 | ).toEqual({ tagName |
| 643 | }); |
| 644 | |
| 645 | it('creates a draft release', |
| 646 | await ok([ |
| 647 | 'release', |
| 648 | 'create', |
| 649 | 'v2.0', |
| 650 | '-R', |
| 651 | repo(), |
| 652 | '--target', |
| 653 | 'main', |
| 654 | '--draft', |
| 655 | '--notes', |
| 656 | 'Not yet', |
| 657 | ]); |
| 658 | expect(await view |
| 659 | }); |
| 660 | |
| 661 | it('uploads an asset', |
| 662 | await ok(['release |
| 663 | expect(await view |
| 664 | assets: expect.arrayContaining |
| 665 | expect.objectContaining({ |
| 666 | ]), |
| 667 | }); |
| 668 | }); |
| 669 | |
| 670 | it('downloads an asset', |
| 671 | const dir = |
| 672 | await ok([ |
| 673 | 'release', |
| 674 | 'download', |
| 675 | 'v1.0', |
| 676 | '-R', |
| 677 | repo(), |
| 678 | '--pattern', |
| 679 | 'notes.txt', |
| 680 | '--dir', |
| 681 | dir, |
| 682 | ]); |
| 683 | expect(readFileSync(path |
| 684 | 'notes.txt\n', |
| 685 | ); |
| 686 | }); |
| 687 | |
| 688 | it('deletes an asset', |
| 689 | await ok([ |
| 690 | 'release', |
| 691 | 'delete-asset', |
| 692 | 'v1.0', |
| 693 | 'extra.txt', |
| 694 | '-R', |
| 695 | repo(), |
| 696 | '--yes', |
| 697 | ]); |
| 698 | expect(await view |
| 699 | assets: [expect.objectContaining |
| 700 | }); |
| 701 | }); |
| 702 | |
| 703 | it('edits a release', |
| 704 | await ok([ |
| 705 | 'release', |
| 706 | 'edit', |
| 707 | 'v1.0', |
| 708 | '-R', |
| 709 | repo(), |
| 710 | '--title', |
| 711 | 'First release (edited)', |
| 712 | '--notes', |
| 713 | 'Edited notes', |
| 714 | '--prerelease', |
| 715 | ]); |
| 716 | expect(await view |
| 717 | name: 'First release (edited)', |
| 718 | body: 'Edited notes', |
| 719 | isPrerelease: true, |
| 720 | }); |
| 721 | }); |
| 722 | |
| 723 | it('deletes a release and its tag', |
| 724 | await ok([ |
| 725 | 'release', |
| 726 | 'delete', |
| 727 | 'v1.0', |
| 728 | '-R', |
| 729 | repo(), |
| 730 | '--yes', |
| 731 | '--cleanup-tag', |
| 732 | ]); |
| 733 | expect( |
| 734 | (await gh([' |
| 735 | ).not.toBe( |
| 736 | }); |
| 737 | }); |
| 738 | |
| 739 | it('creates a repository', |
| 740 | const out = |
| 741 | 'repo', |
| 742 | 'create', |
| 743 | `${GH_E2E_HOST}/${username |
| 744 | '--private', |
| 745 | '--description', |
| 746 | 'from gh', |
| 747 | ]); |
| 748 | expect(out).toContain |
| 749 | }); |
| 750 | |
| 751 | it('adds and lists SSH keys', |
| 752 | // A fingerprint belongs to one account, so each run adds a fresh key. |
| 753 | await promisify(execFile |
| 754 | '-q', |
| 755 | '-t', |
| 756 | 'ed25519', |
| 757 | '-N', |
| 758 | '', |
| 759 | '-f', |
| 760 | path.join(configDir |
| 761 | ]); |
| 762 | const keyFile = |
| 763 | await ok(['ssh-key |
| 764 | expect(await ok |
| 765 | }); |
| 766 | it('logs in through the device flow', |
| 767 | const dir = |
| 768 | const login = |
| 769 | [ |
| 770 | 'auth', |
| 771 | 'login', |
| 772 | '--hostname', |
| 773 | GH_E2E_HOST!, |
| 774 | '--web', |
| 775 | '--git-protocol', |
| 776 | 'https', |
| 777 | '--skip-ssh-key', |
| 778 | ], |
| 779 | { configDir: dir |
| 780 | ); |
| 781 | const [, userCode] |
| 782 | await api |
| 783 | .get('/api/auth/device') |
| 784 | .query({ user_code: |
| 785 | .set('cookie', |
| 786 | .expect(200); |
| 787 | await api |
| 788 | .post('/api/auth/device/approve') |
| 789 | .set('cookie', |
| 790 | .send({ userCode: |
| 791 | .expect(200); |
| 792 | const result = |
| 793 | expect(result, result |
| 794 | // gh auth status lists scopes only for ghp_ and gho_ tokens, so read the header gh got them from. |
| 795 | const root = |
| 796 | expect(root.stdout |
| 797 | /^X-Oauth-Scopes: repo, read:org, gist\r?$/im, |
| 798 | ); |
| 799 | rmSync(dir, { |
| 800 | }, 60_000); |
| 801 | |
| 802 | it('widens scopes with gh auth refresh', |
| 803 | const dir = |
| 804 | await runGh(['auth |
| 805 | configDir: dir, |
| 806 | input: await scopedKey |
| 807 | }); |
| 808 | const refresh = |
| 809 | [ |
| 810 | 'auth', |
| 811 | 'refresh', |
| 812 | '--hostname', |
| 813 | GH_E2E_HOST!, |
| 814 | '--scopes', |
| 815 | 'admin:public_key', |
| 816 | ], |
| 817 | { configDir: dir |
| 818 | ); |
| 819 | const [, userCode] |
| 820 | await api |
| 821 | .get('/api/auth/device') |
| 822 | .query({ user_code: |
| 823 | .set('cookie', |
| 824 | .expect(200); |
| 825 | await api |
| 826 | .post('/api/auth/device/approve') |
| 827 | .set('cookie', |
| 828 | .send({ userCode: |
| 829 | .expect(200); |
| 830 | expect((await refresh |
| 831 | const root = |
| 832 | expect(root.stdout |
| 833 | /^X-Oauth-Scopes: .*\badmin:public_key\b/ |
| 834 | ); |
| 835 | rmSync(dir, { |
| 836 | }, 60_000); |
| 837 | }); |