From 93fdb82080d7fbf86c340715134a699d3de47ff0 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sun, 15 Dec 2024 11:24:43 -0500 Subject: [PATCH] feat: use octokit-from-auth package --- README.md | 17 +- package.json | 2 +- pnpm-lock.yaml | 303 ++++++++++++++++++++++++++- src/pruneGitHubNotifications.test.ts | 38 +--- src/pruneGitHubNotifications.ts | 10 +- src/types.ts | 1 + 6 files changed, 318 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index ce32037b..1b5e8f1d 100644 --- a/README.md +++ b/README.md @@ -23,18 +23,17 @@ npx prune-github-notifications ``` -[`get-github-auth-token`](https://github.com/JoshuaKGoldberg/get-github-auth-token) is used to retrieve a GitHub auth token from `process.env.GH_TOKEN` or executing `gh auth token`. - ### CLI Options -| Option | Type | Default | Description | -| ------------- | ---------- | -------------------------------------------------------------------- | ------------------------------------------------------------- | -| `--bandwidth` | `number` | `6` | Maximum parallel requests to start at once. | -| `--reason` | `string[]` | `["subscribed"]` | Notification reason(s) to filter to. | -| `--title` | `string[]` | `["^chore\(deps\): update .+ to", /^build\(deps-dev\): bump .+ to"]` | Notification title regular expressions to filter to. | -| `--watch` | `number` | `0` | A seconds interval to continuously re-run this on, if truthy. | +| Option | Type | Default | Description | +| ------------- | ---------- | -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | +| `--auth` | `string` | `process.env.GH_TOKEN` or executing `gh auth token` | Auth token for GitHub from [`octokit-from-auth`](https://github.com/JoshuaKGoldberg/octokit-from-auth). | +| `--bandwidth` | `number` | `6` | Maximum parallel requests to start at once. | +| `--reason` | `string[]` | `["subscribed"]` | Notification reason(s) to filter to. | +| `--title` | `string[]` | `["^chore\(deps\): update .+ to", /^build\(deps-dev\): bump .+ to"]` | Notification title regular expressions to filter to. | +| `--watch` | `number` | `0` | A seconds interval to continuously re-run this on, if truthy. | -For example, providing all options on the CLI: +For example, providing all functional options on the CLI: ```shell npx prune-github-notifications --bandwidth 10 --reason subscribed --title "^chore.+ update .+ to" diff --git a/package.json b/package.json index 65bffd2b..56988551 100644 --- a/package.json +++ b/package.json @@ -35,8 +35,8 @@ }, "dependencies": { "chalk": "^5.3.0", - "get-github-auth-token": "^0.1.0", "octokit": "^3.1.2", + "octokit-from-auth": "^0.2.0", "throttled-queue": "^2.1.4", "zod": "^3.22.4" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0d88c2e3..72c1602c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,12 +11,12 @@ importers: chalk: specifier: ^5.3.0 version: 5.3.0 - get-github-auth-token: - specifier: ^0.1.0 - version: 0.1.0 octokit: specifier: ^3.1.2 version: 3.2.0 + octokit-from-auth: + specifier: ^0.2.0 + version: 0.2.0 throttled-queue: specifier: ^2.1.4 version: 2.1.4 @@ -685,6 +685,7 @@ packages: '@humanwhocodes/config-array@0.13.0': resolution: {integrity: sha512-DZLEEqFWQFiyK6h5YIeynKx7JlvCYWL0cImfSRXZ9l4Sg2efkFGTuFf6vzXjK1cq6IYkU+Eg/JizXw+TD2vRNw==} engines: {node: '>=10.10.0'} + deprecated: Use @eslint/config-array instead '@humanwhocodes/module-importer@1.0.1': resolution: {integrity: sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==} @@ -692,6 +693,7 @@ packages: '@humanwhocodes/object-schema@2.0.3': resolution: {integrity: sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==} + deprecated: Use @eslint/object-schema instead '@humanwhocodes/retry@0.2.4': resolution: {integrity: sha512-Ttl/jHpxfS3st5sxwICYfk4pOH0WrLI1SpW283GgQL7sCWU7EHIOhX4b4fkIxr3tkfzwg8+FNojtzsIEE7Ecgg==} @@ -770,34 +772,70 @@ packages: resolution: {integrity: sha512-g3uEsGOQCBl1+W1rgfwoRFUIR6PtvB2T1E4RpygeUU5LrLvlOqcxrt5lfykIeRpUPpupreGJUYl70fqMDXdTpw==} engines: {node: '>= 18'} + '@octokit/app@15.1.1': + resolution: {integrity: sha512-fk8xrCSPTJGpyBdBNI+DcZ224dm0aApv4vi6X7/zTmANXlegKV2Td+dJ+fd7APPaPN7R+xttUsj2Fm+AFDSfMQ==} + engines: {node: '>= 18'} + '@octokit/auth-app@6.1.1': resolution: {integrity: sha512-VrTtzRpyuT5nYGUWeGWQqH//hqEZDV+/yb6+w5wmWpmmUA1Tx950XsAc2mBBfvusfcdF2E7w8jZ1r1WwvfZ9pA==} engines: {node: '>= 18'} + '@octokit/auth-app@7.1.3': + resolution: {integrity: sha512-GZdkOp2kZTIy5dG9oXqvzUAZiPvDx4C/lMlN6yQjtG9d/+hYa7W8WXTJoOrXE8UdfL9A/sZMl206dmtkl9lwVQ==} + engines: {node: '>= 18'} + '@octokit/auth-oauth-app@7.1.0': resolution: {integrity: sha512-w+SyJN/b0l/HEb4EOPRudo7uUOSW51jcK1jwLa+4r7PA8FPFpoxEnHBHMITqCsc/3Vo2qqFjgQfz/xUUvsSQnA==} engines: {node: '>= 18'} + '@octokit/auth-oauth-app@8.1.1': + resolution: {integrity: sha512-5UtmxXAvU2wfcHIPPDWzVSAWXVJzG3NWsxb7zCFplCWEmMCArSZV0UQu5jw5goLQXbFyOr5onzEH37UJB3zQQg==} + engines: {node: '>= 18'} + '@octokit/auth-oauth-device@6.1.0': resolution: {integrity: sha512-FNQ7cb8kASufd6Ej4gnJ3f1QB5vJitkoV1O0/g6e6lUsQ7+VsSNRHRmFScN2tV4IgKA12frrr/cegUs0t+0/Lw==} engines: {node: '>= 18'} + '@octokit/auth-oauth-device@7.1.1': + resolution: {integrity: sha512-HWl8lYueHonuyjrKKIup/1tiy0xcmQCdq5ikvMO1YwkNNkxb6DXfrPjrMYItNLyCP/o2H87WuijuE+SlBTT8eg==} + engines: {node: '>= 18'} + '@octokit/auth-oauth-user@4.1.0': resolution: {integrity: sha512-FrEp8mtFuS/BrJyjpur+4GARteUCrPeR/tZJzD8YourzoVhRics7u7we/aDcKv+yywRNwNi/P4fRi631rG/OyQ==} engines: {node: '>= 18'} + '@octokit/auth-oauth-user@5.1.1': + resolution: {integrity: sha512-rRkMz0ErOppdvEfnemHJXgZ9vTPhBuC6yASeFaB7I2yLMd7QpjfrL1mnvRPlyKo+M6eeLxrKanXJ9Qte29SRsw==} + engines: {node: '>= 18'} + '@octokit/auth-token@4.0.0': resolution: {integrity: sha512-tY/msAuJo6ARbK6SPIxZrPBms3xPbfwBrulZe0Wtr/DIY9lje2HeV1uoebShn6mx7SjCHif6EjMvoREj+gZ+SA==} engines: {node: '>= 18'} + '@octokit/auth-token@5.1.1': + resolution: {integrity: sha512-rh3G3wDO8J9wSjfI436JUKzHIxq8NaiL0tVeB2aXmG6p/9859aUOAjA9pmSPNGGZxfwmaJ9ozOJImuNVJdpvbA==} + engines: {node: '>= 18'} + '@octokit/auth-unauthenticated@5.0.1': resolution: {integrity: sha512-oxeWzmBFxWd+XolxKTc4zr+h3mt+yofn4r7OfoIkR/Cj/o70eEGmPsFbueyJE2iBAGpjgTnEOKM3pnuEGVmiqg==} engines: {node: '>= 18'} + '@octokit/auth-unauthenticated@6.1.0': + resolution: {integrity: sha512-zPSmfrUAcspZH/lOFQnVnvjQZsIvmfApQH6GzJrkIunDooU1Su2qt2FfMTSVPRp7WLTQyC20Kd55lF+mIYaohQ==} + engines: {node: '>= 18'} + '@octokit/core@5.2.0': resolution: {integrity: sha512-1LFfa/qnMQvEOAdzlQymH0ulepxbxnCYAKJZfMci/5XJyIHWgEYnDmgnKakbTh7CH2tFQ5O60oYDvns4i9RAIg==} engines: {node: '>= 18'} + '@octokit/core@6.1.2': + resolution: {integrity: sha512-hEb7Ma4cGJGEUNOAVmyfdB/3WirWMg5hDuNFVejGEDFqupeOysLc2sG6HJxY2etBp5YQu5Wtxwi020jS9xlUwg==} + engines: {node: '>= 18'} + + '@octokit/endpoint@10.1.1': + resolution: {integrity: sha512-JYjh5rMOwXMJyUpj028cu0Gbp7qe/ihxfJMLc8VZBMMqSwLgOxDI1911gV4Enl1QSavAQNJcwmwBF9M0VvLh6Q==} + engines: {node: '>= 18'} + '@octokit/endpoint@9.0.5': resolution: {integrity: sha512-ekqR4/+PCLkEBF6qgj8WqJfvDq65RH85OAgrtnVp1mSxaXF03u2xW/hUdweGS5654IlC0wkNYC18Z50tSYTAFw==} engines: {node: '>= 18'} @@ -806,30 +844,61 @@ packages: resolution: {integrity: sha512-r+oZUH7aMFui1ypZnAvZmn0KSqAUgE1/tUXIWaqUCa1758ts/Jio84GZuzsvUkme98kv0WFY8//n0J1Z+vsIsQ==} engines: {node: '>= 18'} + '@octokit/graphql@8.1.1': + resolution: {integrity: sha512-ukiRmuHTi6ebQx/HFRCXKbDlOh/7xEV6QUXaE7MJEKGNAncGI/STSbOkl12qVXZrfZdpXctx5O9X1AIaebiDBg==} + engines: {node: '>= 18'} + '@octokit/oauth-app@6.1.0': resolution: {integrity: sha512-nIn/8eUJ/BKUVzxUXd5vpzl1rwaVxMyYbQkNZjHrF7Vk/yu98/YDF/N2KeWO7uZ0g3b5EyiFXFkZI8rJ+DH1/g==} engines: {node: '>= 18'} + '@octokit/oauth-app@7.1.3': + resolution: {integrity: sha512-EHXbOpBkSGVVGF1W+NLMmsnSsJRkcrnVmDKt0TQYRBb6xWfWzoi9sBD4DIqZ8jGhOWO/V8t4fqFyJ4vDQDn9bg==} + engines: {node: '>= 18'} + '@octokit/oauth-authorization-url@6.0.2': resolution: {integrity: sha512-CdoJukjXXxqLNK4y/VOiVzQVjibqoj/xHgInekviUJV73y/BSIcwvJ/4aNHPBPKcPWFnd4/lO9uqRV65jXhcLA==} engines: {node: '>= 18'} + '@octokit/oauth-authorization-url@7.1.1': + resolution: {integrity: sha512-ooXV8GBSabSWyhLUowlMIVd9l1s2nsOGQdlP2SQ4LnkEsGXzeCvbSbCPdZThXhEFzleGPwbapT0Sb+YhXRyjCA==} + engines: {node: '>= 18'} + '@octokit/oauth-methods@4.1.0': resolution: {integrity: sha512-4tuKnCRecJ6CG6gr0XcEXdZtkTDbfbnD5oaHBmLERTjTMZNi2CbfEHZxPU41xXLDG4DfKf+sonu00zvKI9NSbw==} engines: {node: '>= 18'} + '@octokit/oauth-methods@5.1.2': + resolution: {integrity: sha512-C5lglRD+sBlbrhCUTxgJAFjWgJlmTx5bQ7Ch0+2uqRjYv7Cfb5xpX4WuSC9UgQna3sqRGBL9EImX9PvTpMaQ7g==} + engines: {node: '>= 18'} + '@octokit/openapi-types@20.0.0': resolution: {integrity: sha512-EtqRBEjp1dL/15V7WiX5LJMIxxkdiGJnabzYx5Apx4FkQIFgAfKumXeYAqqJCj1s+BMX4cPFIFC4OLCR6stlnA==} '@octokit/openapi-types@22.2.0': resolution: {integrity: sha512-QBhVjcUa9W7Wwhm6DBFu6ZZ+1/t/oYxqc2tp81Pi41YNuJinbFRx8B133qVOrAaBbF7D/m0Et6f9/pZt9Rc+tg==} + '@octokit/openapi-webhooks-types@8.5.1': + resolution: {integrity: sha512-i3h1b5zpGSB39ffBbYdSGuAd0NhBAwPyA3QV3LYi/lx4lsbZiu7u2UHgXVUR6EpvOI8REOuVh1DZTRfHoJDvuQ==} + '@octokit/plugin-paginate-graphql@4.0.1': resolution: {integrity: sha512-R8ZQNmrIKKpHWC6V2gum4x9LG2qF1RxRjo27gjQcG3j+vf2tLsEfE7I/wRWEPzYMaenr1M+qDAtNcwZve1ce1A==} engines: {node: '>= 18'} peerDependencies: '@octokit/core': '>=5' + '@octokit/plugin-paginate-graphql@5.2.4': + resolution: {integrity: sha512-pLZES1jWaOynXKHOqdnwZ5ULeVR6tVVCMm+AUbp0htdcyXDU95WbkYdU4R2ej1wKj5Tu94Mee2Ne0PjPO9cCyA==} + engines: {node: '>= 18'} + peerDependencies: + '@octokit/core': '>=6' + + '@octokit/plugin-paginate-rest@11.3.6': + resolution: {integrity: sha512-zcvqqf/+TicbTCa/Z+3w4eBJcAxCFymtc0UAIsR3dEVoNilWld4oXdscQ3laXamTszUZdusw97K8+DrbFiOwjw==} + engines: {node: '>= 18'} + peerDependencies: + '@octokit/core': '>=6' + '@octokit/plugin-paginate-rest@9.2.1': resolution: {integrity: sha512-wfGhE/TAkXZRLjksFXuDZdmGnJQHvtU/joFQdweXUgzo1XwvBCD4o4+75NtFfjfLK5IwLf9vHTfSiU3sLRYpRw==} engines: {node: '>= 18'} @@ -848,26 +917,52 @@ packages: peerDependencies: '@octokit/core': '5' + '@octokit/plugin-rest-endpoint-methods@13.2.6': + resolution: {integrity: sha512-wMsdyHMjSfKjGINkdGKki06VEkgdEldIGstIEyGX0wbYHGByOwN/KiM+hAAlUwAtPkP3gvXtVQA9L3ITdV2tVw==} + engines: {node: '>= 18'} + peerDependencies: + '@octokit/core': '>=6' + '@octokit/plugin-retry@6.0.1': resolution: {integrity: sha512-SKs+Tz9oj0g4p28qkZwl/topGcb0k0qPNX/i7vBKmDsjoeqnVfFUquqrE/O9oJY7+oLzdCtkiWSXLpLjvl6uog==} engines: {node: '>= 18'} peerDependencies: '@octokit/core': '>=5' + '@octokit/plugin-retry@7.1.2': + resolution: {integrity: sha512-XOWnPpH2kJ5VTwozsxGurw+svB2e61aWlmk5EVIYZPwFK5F9h4cyPyj9CIKRyMXMHSwpIsI3mPOdpMmrRhe7UQ==} + engines: {node: '>= 18'} + peerDependencies: + '@octokit/core': '>=6' + '@octokit/plugin-throttling@8.2.0': resolution: {integrity: sha512-nOpWtLayKFpgqmgD0y3GqXafMFuKcA4tRPZIfu7BArd2lEZeb1988nhWhwx4aZWmjDmUfdgVf7W+Tt4AmvRmMQ==} engines: {node: '>= 18'} peerDependencies: '@octokit/core': ^5.0.0 + '@octokit/plugin-throttling@9.3.2': + resolution: {integrity: sha512-FqpvcTpIWFpMMwIeSoypoJXysSAQ3R+ALJhXXSG1HTP3YZOIeLmcNcimKaXxTcws+Sh6yoRl13SJ5r8sXc1Fhw==} + engines: {node: '>= 18'} + peerDependencies: + '@octokit/core': ^6.0.0 + '@octokit/request-error@5.1.0': resolution: {integrity: sha512-GETXfE05J0+7H2STzekpKObFe765O5dlAKUTLNGeH+x47z7JjXHfsHKo5z21D/o/IOZTUEI6nyWyR+bZVP/n5Q==} engines: {node: '>= 18'} + '@octokit/request-error@6.1.5': + resolution: {integrity: sha512-IlBTfGX8Yn/oFPMwSfvugfncK2EwRLjzbrpifNaMY8o/HTEAFqCA1FZxjD9cWvSKBHgrIhc4CSBIzMxiLsbzFQ==} + engines: {node: '>= 18'} + '@octokit/request@8.4.0': resolution: {integrity: sha512-9Bb014e+m2TgBeEJGEbdplMVWwPmL1FPtggHQRkV+WVsMggPtEkLKPlcVYm/o8xKLkpJ7B+6N8WfQMtDLX2Dpw==} engines: {node: '>= 18'} + '@octokit/request@9.1.3': + resolution: {integrity: sha512-V+TFhu5fdF3K58rs1pGUJIDH5RZLbZm5BI+MNF+6o/ssFNT4vWlCh/tVpF3NxGtP15HUxTTMUbsG5llAuU2CZA==} + engines: {node: '>= 18'} + '@octokit/rest@20.1.0': resolution: {integrity: sha512-STVO3itHQLrp80lvcYB2UIKoeil5Ctsgd2s1AM+du3HqZIR35ZH7WE9HLwUOLXH0myA0y3AGNPo8gZtcgIbw0g==} engines: {node: '>= 18'} @@ -878,10 +973,17 @@ packages: '@octokit/types@13.5.0': resolution: {integrity: sha512-HdqWTf5Z3qwDVlzCrP8UJquMwunpDiMPt5er+QjGzL4hqr/vBVY/MauQgS1xWxCDT1oMx1EULyqxncdCY/NVSQ==} + '@octokit/types@13.6.2': + resolution: {integrity: sha512-WpbZfZUcZU77DrSW4wbsSgTPfKcp286q3ItaIgvSbBpZJlu6mnYXAkjZz6LVZPXkEvLIM8McanyZejKTYUHipA==} + '@octokit/webhooks-methods@4.1.0': resolution: {integrity: sha512-zoQyKw8h9STNPqtm28UGOYFE7O6D4Il8VJwhAtMHFt2C4L0VQT1qGKLeefUOqHNs1mNRYSadVv7x0z8U2yyeWQ==} engines: {node: '>= 18'} + '@octokit/webhooks-methods@5.1.0': + resolution: {integrity: sha512-yFZa3UH11VIxYnnoOYCVoJ3q4ChuSOk2IVBBQ0O3xtKX4x9bmKb/1t+Mxixv2iUhzMdOl1qeWJqEhouXXzB3rQ==} + engines: {node: '>= 18'} + '@octokit/webhooks-types@7.4.0': resolution: {integrity: sha512-FE2V+QZ2UYlh+9wWd5BPLNXG+J/XUD/PPq0ovS+nCcGX4+3qVbi3jYOmCTW48hg9SBBLtInx9+o7fFt4H5iP0Q==} @@ -889,6 +991,10 @@ packages: resolution: {integrity: sha512-CyuLJ0/P7bKZ+kIYw+fnkeVdhUzNuDKgNSI7pU/m7Nod0T7kP+s4s2f0pNmG9HL8/RZN1S0ZWTDll3VTMrFLAw==} engines: {node: '>= 18'} + '@octokit/webhooks@13.4.1': + resolution: {integrity: sha512-I5YPUtfWidh+OzyrlDahJsUpkpGK0kCTmDRbuqGmlCUzOtxdEkX3R4d6Cd08ijQYwkVXQJanPdbKuZBeV2NMaA==} + engines: {node: '>= 18'} + '@pkgjs/parseargs@0.11.0': resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} engines: {node: '>=14'} @@ -1309,6 +1415,9 @@ packages: before-after-hook@2.2.3: resolution: {integrity: sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==} + before-after-hook@3.0.2: + resolution: {integrity: sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A==} + binary-extensions@2.3.0: resolution: {integrity: sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==} engines: {node: '>=8'} @@ -3082,10 +3191,18 @@ packages: resolution: {integrity: sha512-byy+U7gp+FVwmyzKPYhW2h5l3crpmGsxl7X2s8y43IgxvG4g3QZ6CffDtsNQy1WsmZpQbO+ybo0AlW7TY6DcBQ==} engines: {node: '>= 0.4'} + octokit-from-auth@0.2.0: + resolution: {integrity: sha512-UMo+WQkWi1PS/HZ15SMM1sgPhhXykqPJKCCAi6R0+JAhTbLBcfeKCJ3AwUVdJBJQKSQ37BUqPpME4iGAjZQtkw==} + engines: {node: '>=18.3.0'} + octokit@3.2.0: resolution: {integrity: sha512-f25eJ/8ITwF2BdwymOjK9I5ll9Azt8UbfHE2u5ho0gVdgfpIZkUgMGbQjbvgOYGbtIAYxh7ghH3BUbZrYal1Gw==} engines: {node: '>= 18'} + octokit@4.0.2: + resolution: {integrity: sha512-wbqF4uc1YbcldtiBFfkSnquHtECEIpYD78YUXI6ri1Im5OO2NLo6ZVpRdbJpdnpZ05zMrVPssNiEo6JQtea+Qg==} + engines: {node: '>= 18'} + once@1.4.0: resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} @@ -3789,6 +3906,10 @@ packages: to-space-case@1.0.0: resolution: {integrity: sha512-rLdvwXZ39VOn1IxGL3V6ZstoTbwLRckQmn/U8ZDLuWwIXNpuZDhQ3AiRUlhTbOXFVE9C+dR51wM0CBDhk31VcA==} + toad-cache@3.7.0: + resolution: {integrity: sha512-/m8M+2BJUpoJdgAHoG+baCwBT+tf2VraSfkBgl0Y00qIWt41DJ8R5B8nsEw0I58YwF5IZH6z24/2TobDKnqSWw==} + engines: {node: '>=12'} + toml@3.0.0: resolution: {integrity: sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==} @@ -3931,9 +4052,15 @@ packages: universal-github-app-jwt@1.1.2: resolution: {integrity: sha512-t1iB2FmLFE+yyJY9+3wMx0ejB+MQpEVkH0gQv7dR6FZyltyq+ZZO0uDpbopxhrZ3SLEO4dCEkIujOMldEQ2iOA==} + universal-github-app-jwt@2.2.0: + resolution: {integrity: sha512-G5o6f95b5BggDGuUfKDApKaCgNYy2x7OdHY0zSMF081O0EJobw+1130VONhrA7ezGSV2FNOGyM+KQpQZAr9bIQ==} + universal-user-agent@6.0.1: resolution: {integrity: sha512-yCzhz6FN2wU1NiiQRogkTQszlQSlpWaw8SvVegAc+bDxbzHgh1vX8uIe8OYyMH6DwH+sdTJsgMl36+mSMdRJIQ==} + universal-user-agent@7.0.2: + resolution: {integrity: sha512-0JCqzSKnStlRRQfCdowvqy3cy0Dvtlb8xecj/H8JFZuCze4rwjPZQOgvFvn0Ws/usCHQFGpyr+pB9adaGwXn4Q==} + universalify@2.0.1: resolution: {integrity: sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==} engines: {node: '>= 10.0.0'} @@ -4678,6 +4805,16 @@ snapshots: '@octokit/types': 12.6.0 '@octokit/webhooks': 12.2.0 + '@octokit/app@15.1.1': + dependencies: + '@octokit/auth-app': 7.1.3 + '@octokit/auth-unauthenticated': 6.1.0 + '@octokit/core': 6.1.2 + '@octokit/oauth-app': 7.1.3 + '@octokit/plugin-paginate-rest': 11.3.6(@octokit/core@6.1.2) + '@octokit/types': 13.5.0 + '@octokit/webhooks': 13.4.1 + '@octokit/auth-app@6.1.1': dependencies: '@octokit/auth-oauth-app': 7.1.0 @@ -4690,6 +4827,17 @@ snapshots: universal-github-app-jwt: 1.1.2 universal-user-agent: 6.0.1 + '@octokit/auth-app@7.1.3': + dependencies: + '@octokit/auth-oauth-app': 8.1.1 + '@octokit/auth-oauth-user': 5.1.1 + '@octokit/request': 9.1.3 + '@octokit/request-error': 6.1.5 + '@octokit/types': 13.5.0 + toad-cache: 3.7.0 + universal-github-app-jwt: 2.2.0 + universal-user-agent: 7.0.2 + '@octokit/auth-oauth-app@7.1.0': dependencies: '@octokit/auth-oauth-device': 6.1.0 @@ -4700,6 +4848,14 @@ snapshots: btoa-lite: 1.0.0 universal-user-agent: 6.0.1 + '@octokit/auth-oauth-app@8.1.1': + dependencies: + '@octokit/auth-oauth-device': 7.1.1 + '@octokit/auth-oauth-user': 5.1.1 + '@octokit/request': 9.1.3 + '@octokit/types': 13.5.0 + universal-user-agent: 7.0.2 + '@octokit/auth-oauth-device@6.1.0': dependencies: '@octokit/oauth-methods': 4.1.0 @@ -4707,6 +4863,13 @@ snapshots: '@octokit/types': 13.5.0 universal-user-agent: 6.0.1 + '@octokit/auth-oauth-device@7.1.1': + dependencies: + '@octokit/oauth-methods': 5.1.2 + '@octokit/request': 9.1.3 + '@octokit/types': 13.5.0 + universal-user-agent: 7.0.2 + '@octokit/auth-oauth-user@4.1.0': dependencies: '@octokit/auth-oauth-device': 6.1.0 @@ -4716,13 +4879,28 @@ snapshots: btoa-lite: 1.0.0 universal-user-agent: 6.0.1 + '@octokit/auth-oauth-user@5.1.1': + dependencies: + '@octokit/auth-oauth-device': 7.1.1 + '@octokit/oauth-methods': 5.1.2 + '@octokit/request': 9.1.3 + '@octokit/types': 13.5.0 + universal-user-agent: 7.0.2 + '@octokit/auth-token@4.0.0': {} + '@octokit/auth-token@5.1.1': {} + '@octokit/auth-unauthenticated@5.0.1': dependencies: '@octokit/request-error': 5.1.0 '@octokit/types': 12.6.0 + '@octokit/auth-unauthenticated@6.1.0': + dependencies: + '@octokit/request-error': 6.1.5 + '@octokit/types': 13.5.0 + '@octokit/core@5.2.0': dependencies: '@octokit/auth-token': 4.0.0 @@ -4733,6 +4911,21 @@ snapshots: before-after-hook: 2.2.3 universal-user-agent: 6.0.1 + '@octokit/core@6.1.2': + dependencies: + '@octokit/auth-token': 5.1.1 + '@octokit/graphql': 8.1.1 + '@octokit/request': 9.1.3 + '@octokit/request-error': 6.1.5 + '@octokit/types': 13.5.0 + before-after-hook: 3.0.2 + universal-user-agent: 7.0.2 + + '@octokit/endpoint@10.1.1': + dependencies: + '@octokit/types': 13.5.0 + universal-user-agent: 7.0.2 + '@octokit/endpoint@9.0.5': dependencies: '@octokit/types': 13.5.0 @@ -4744,6 +4937,12 @@ snapshots: '@octokit/types': 13.5.0 universal-user-agent: 6.0.1 + '@octokit/graphql@8.1.1': + dependencies: + '@octokit/request': 9.1.3 + '@octokit/types': 13.5.0 + universal-user-agent: 7.0.2 + '@octokit/oauth-app@6.1.0': dependencies: '@octokit/auth-oauth-app': 7.1.0 @@ -4755,8 +4954,21 @@ snapshots: '@types/aws-lambda': 8.10.137 universal-user-agent: 6.0.1 + '@octokit/oauth-app@7.1.3': + dependencies: + '@octokit/auth-oauth-app': 8.1.1 + '@octokit/auth-oauth-user': 5.1.1 + '@octokit/auth-unauthenticated': 6.1.0 + '@octokit/core': 6.1.2 + '@octokit/oauth-authorization-url': 7.1.1 + '@octokit/oauth-methods': 5.1.2 + '@types/aws-lambda': 8.10.137 + universal-user-agent: 7.0.2 + '@octokit/oauth-authorization-url@6.0.2': {} + '@octokit/oauth-authorization-url@7.1.1': {} + '@octokit/oauth-methods@4.1.0': dependencies: '@octokit/oauth-authorization-url': 6.0.2 @@ -4765,14 +4977,32 @@ snapshots: '@octokit/types': 13.5.0 btoa-lite: 1.0.0 + '@octokit/oauth-methods@5.1.2': + dependencies: + '@octokit/oauth-authorization-url': 7.1.1 + '@octokit/request': 9.1.3 + '@octokit/request-error': 6.1.5 + '@octokit/types': 13.5.0 + '@octokit/openapi-types@20.0.0': {} '@octokit/openapi-types@22.2.0': {} + '@octokit/openapi-webhooks-types@8.5.1': {} + '@octokit/plugin-paginate-graphql@4.0.1(@octokit/core@5.2.0)': dependencies: '@octokit/core': 5.2.0 + '@octokit/plugin-paginate-graphql@5.2.4(@octokit/core@6.1.2)': + dependencies: + '@octokit/core': 6.1.2 + + '@octokit/plugin-paginate-rest@11.3.6(@octokit/core@6.1.2)': + dependencies: + '@octokit/core': 6.1.2 + '@octokit/types': 13.6.2 + '@octokit/plugin-paginate-rest@9.2.1(@octokit/core@5.2.0)': dependencies: '@octokit/core': 5.2.0 @@ -4787,6 +5017,11 @@ snapshots: '@octokit/core': 5.2.0 '@octokit/types': 12.6.0 + '@octokit/plugin-rest-endpoint-methods@13.2.6(@octokit/core@6.1.2)': + dependencies: + '@octokit/core': 6.1.2 + '@octokit/types': 13.6.2 + '@octokit/plugin-retry@6.0.1(@octokit/core@5.2.0)': dependencies: '@octokit/core': 5.2.0 @@ -4794,18 +5029,35 @@ snapshots: '@octokit/types': 12.6.0 bottleneck: 2.19.5 + '@octokit/plugin-retry@7.1.2(@octokit/core@6.1.2)': + dependencies: + '@octokit/core': 6.1.2 + '@octokit/request-error': 6.1.5 + '@octokit/types': 13.5.0 + bottleneck: 2.19.5 + '@octokit/plugin-throttling@8.2.0(@octokit/core@5.2.0)': dependencies: '@octokit/core': 5.2.0 '@octokit/types': 12.6.0 bottleneck: 2.19.5 + '@octokit/plugin-throttling@9.3.2(@octokit/core@6.1.2)': + dependencies: + '@octokit/core': 6.1.2 + '@octokit/types': 13.5.0 + bottleneck: 2.19.5 + '@octokit/request-error@5.1.0': dependencies: '@octokit/types': 13.5.0 deprecation: 2.3.1 once: 1.4.0 + '@octokit/request-error@6.1.5': + dependencies: + '@octokit/types': 13.5.0 + '@octokit/request@8.4.0': dependencies: '@octokit/endpoint': 9.0.5 @@ -4813,6 +5065,13 @@ snapshots: '@octokit/types': 13.5.0 universal-user-agent: 6.0.1 + '@octokit/request@9.1.3': + dependencies: + '@octokit/endpoint': 10.1.1 + '@octokit/request-error': 6.1.5 + '@octokit/types': 13.5.0 + universal-user-agent: 7.0.2 + '@octokit/rest@20.1.0': dependencies: '@octokit/core': 5.2.0 @@ -4828,8 +5087,14 @@ snapshots: dependencies: '@octokit/openapi-types': 22.2.0 + '@octokit/types@13.6.2': + dependencies: + '@octokit/openapi-types': 22.2.0 + '@octokit/webhooks-methods@4.1.0': {} + '@octokit/webhooks-methods@5.1.0': {} + '@octokit/webhooks-types@7.4.0': {} '@octokit/webhooks@12.2.0': @@ -4839,6 +5104,12 @@ snapshots: '@octokit/webhooks-types': 7.4.0 aggregate-error: 3.1.0 + '@octokit/webhooks@13.4.1': + dependencies: + '@octokit/openapi-webhooks-types': 8.5.1 + '@octokit/request-error': 6.1.5 + '@octokit/webhooks-methods': 5.1.0 + '@pkgjs/parseargs@0.11.0': optional: true @@ -5280,6 +5551,8 @@ snapshots: before-after-hook@2.2.3: {} + before-after-hook@3.0.2: {} + binary-extensions@2.3.0: {} bl@4.1.0: @@ -7274,6 +7547,11 @@ snapshots: has-symbols: 1.0.3 object-keys: 1.1.1 + octokit-from-auth@0.2.0: + dependencies: + get-github-auth-token: 0.1.0 + octokit: 4.0.2 + octokit@3.2.0: dependencies: '@octokit/app': 14.1.0 @@ -7287,6 +7565,19 @@ snapshots: '@octokit/request-error': 5.1.0 '@octokit/types': 12.6.0 + octokit@4.0.2: + dependencies: + '@octokit/app': 15.1.1 + '@octokit/core': 6.1.2 + '@octokit/oauth-app': 7.1.3 + '@octokit/plugin-paginate-graphql': 5.2.4(@octokit/core@6.1.2) + '@octokit/plugin-paginate-rest': 11.3.6(@octokit/core@6.1.2) + '@octokit/plugin-rest-endpoint-methods': 13.2.6(@octokit/core@6.1.2) + '@octokit/plugin-retry': 7.1.2(@octokit/core@6.1.2) + '@octokit/plugin-throttling': 9.3.2(@octokit/core@6.1.2) + '@octokit/request-error': 6.1.5 + '@octokit/types': 13.5.0 + once@1.4.0: dependencies: wrappy: 1.0.2 @@ -8070,6 +8361,8 @@ snapshots: dependencies: to-no-case: 1.0.2 + toad-cache@3.7.0: {} + toml@3.0.0: {} tr46@1.0.1: @@ -8209,8 +8502,12 @@ snapshots: '@types/jsonwebtoken': 9.0.6 jsonwebtoken: 9.0.2 + universal-github-app-jwt@2.2.0: {} + universal-user-agent@6.0.1: {} + universal-user-agent@7.0.2: {} + universalify@2.0.1: {} update-notifier@7.0.0: diff --git a/src/pruneGitHubNotifications.test.ts b/src/pruneGitHubNotifications.test.ts index b02d524f..534f9151 100644 --- a/src/pruneGitHubNotifications.test.ts +++ b/src/pruneGitHubNotifications.test.ts @@ -2,14 +2,6 @@ import { describe, expect, it, vi } from "vitest"; import { pruneGitHubNotifications } from "./pruneGitHubNotifications.js"; -const mockGetGitHubAuthToken = vi.fn(); - -vi.mock("get-github-auth-token", () => ({ - get getGitHubAuthToken() { - return mockGetGitHubAuthToken; - }, -})); - const mockRequest = vi.fn().mockResolvedValue({ data: [ { @@ -43,30 +35,15 @@ const mockRequest = vi.fn().mockResolvedValue({ ], }); -vi.mock("octokit", () => ({ - Octokit: class MockOctokit { - request = mockRequest; - }, +vi.mock("octokit-from-auth", () => ({ + octokitFromAuth: () => + Promise.resolve({ + request: mockRequest, + }), })); describe("pruneGitHubNotifications", () => { - it("throws an error when auth is not available", async () => { - mockGetGitHubAuthToken.mockResolvedValue({ - error: "Oh no!", - succeeded: false, - }); - - await expect(async () => { - await pruneGitHubNotifications(); - }).rejects.toMatchInlineSnapshot(`[Error: Oh no!]`); - }); - it("unsubscribes from threads based on default filters when no filters are provided", async () => { - mockGetGitHubAuthToken.mockResolvedValue({ - succeeded: true, - token: "abc123", - }); - await pruneGitHubNotifications(); expect(mockRequest.mock.calls).toMatchInlineSnapshot(` @@ -102,11 +79,6 @@ describe("pruneGitHubNotifications", () => { }); it("unsubscribes from threads based on custom filters when custom filters are provided", async () => { - mockGetGitHubAuthToken.mockResolvedValue({ - succeeded: true, - token: "abc123", - }); - await pruneGitHubNotifications({ filters: { reason: new Set(["other-reason"]), title: [/other title/] }, }); diff --git a/src/pruneGitHubNotifications.ts b/src/pruneGitHubNotifications.ts index 21463e90..c1522125 100644 --- a/src/pruneGitHubNotifications.ts +++ b/src/pruneGitHubNotifications.ts @@ -1,5 +1,4 @@ -import { getGitHubAuthToken } from "get-github-auth-token"; -import { Octokit } from "octokit"; +import { octokitFromAuth } from "octokit-from-auth"; import throttledQueue from "throttled-queue"; import { createThreadFilter } from "./createThreadFilter.js"; @@ -16,15 +15,12 @@ type ThrottledQueue = ( ) => (fn: () => Promise | Return) => Promise; export async function pruneGitHubNotifications({ + auth, bandwidth = defaultOptions.bandwidth, filters, }: PruneGitHubNotificationsOptions = {}): Promise { - const auth = await getGitHubAuthToken(); - if (!auth.succeeded) { - throw new Error(auth.error); - } + const octokit = await octokitFromAuth({ auth }); - const octokit = new Octokit({ auth: auth.token }); const notifications = await octokit.request("GET /notifications", { headers: { "X-GitHub-Api-Version": "2022-11-28", diff --git a/src/types.ts b/src/types.ts index 8f911a0d..16c6ad01 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,5 @@ export interface PruneGitHubNotificationsOptions { + auth?: string; bandwidth?: number; filters?: Partial; }