@@ -4,23 +4,51 @@ import { retry } from "@octokit/plugin-retry";
44import { throttling } from "@octokit/plugin-throttling" ;
55import { Octokit } from "@octokit/rest" ;
66import _ from "lodash" ;
7+ import { assertDefined } from "ts-extras" ;
8+ import type { Writable } from "type-fest" ;
79
8- import * as custom from "../config/config.js " ;
9- import * as defaults from "../config/default.js " ;
10+ import * as custom from "../config/config.ts " ;
11+ import * as defaults from "../config/default.ts " ;
1012
11- import commands from "./commands/index.js" ;
12- import Template from "./structures/template.js" ;
13+ import commands , {
14+ type CommandAliases ,
15+ type CommandPayload ,
16+ } from "./commands/index.ts" ;
17+ import Template from "./structures/template.ts" ;
18+
19+ const MyOctokit : typeof Octokit &
20+ ( new (
21+ ...args : any [ ]
22+ ) => ReturnType < typeof retry > & ReturnType < typeof throttling > ) =
23+ Octokit . plugin ( retry , throttling ) ;
24+
25+ export class Client extends MyOctokit {
26+ cfg : Writable < typeof defaults > ;
27+ commands : Map <
28+ string ,
29+ {
30+ run : (
31+ this : Client ,
32+ payload : CommandPayload ,
33+ commenter : string ,
34+ args : string ,
35+ ) => Promise < unknown > ;
36+ aliasPath : ( commands : CommandAliases ) => string [ ] ;
37+ }
38+ > ;
39+
40+ invites : Map < string , number > ;
41+ templates : Map < string , Template > ;
1342
14- export class Client extends Octokit . plugin ( retry , throttling ) {
1543 constructor ( ) {
16- const cfg = _ . merge ( { } , defaults , custom ) ;
44+ const cfg : Writable < typeof defaults > = _ . merge ( { } , defaults , custom ) ;
1745 super ( {
1846 auth : cfg . auth . oAuthToken ,
1947 retry : {
20- enabled : process . env . NODE_ENV !== "test" ,
48+ enabled : process . env [ " NODE_ENV" ] !== "test" ,
2149 } ,
2250 throttle : {
23- enabled : process . env . NODE_ENV !== "test" ,
51+ enabled : process . env [ " NODE_ENV" ] !== "test" ,
2452 onRateLimit : ( retryAfter , { method, url } , _octokit , retryCount ) => {
2553 if ( retryCount < 3 ) {
2654 this . log . warn (
@@ -36,8 +64,9 @@ export class Client extends Octokit.plugin(retry, throttling) {
3664 retryCount + 1
3765 } times for ${ method } ${ url } ; aborting`,
3866 ) ;
67+ return ; // eslint-disable-line no-useless-return
3968 } ,
40- onSecondaryRateLimit : ( retryAfter , { method, url } ) => {
69+ onSecondaryRateLimit : ( _retryAfter , { method, url } ) => {
4170 this . log . warn (
4271 `Secondary rate limit detected for ${ method } ${ url } ; aborting` ,
4372 ) ;
@@ -62,6 +91,7 @@ export class Client extends Octokit.plugin(retry, throttling) {
6291 ) ;
6392 for ( const file of templates ) {
6493 const [ name ] = file . split ( ".md" ) ;
94+ assertDefined ( name ) ;
6595 const content = fs . readFileSync (
6696 new URL ( `../config/templates/${ file } ` , import . meta. url ) ,
6797 "utf8" ,
0 commit comments