File tree Expand file tree Collapse file tree 2 files changed +34
-4
lines changed
Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -51,9 +51,14 @@ export class Octokit {
5151 }
5252
5353 if ( options . auth ) {
54- requestDefaults . headers . authorization = withAuthorizationPrefix (
55- options . auth
56- ) ;
54+ if ( typeof options . auth === "string" ) {
55+ requestDefaults . headers . authorization = withAuthorizationPrefix (
56+ options . auth
57+ ) ;
58+ } else {
59+ // @ts -ignore
60+ hook . wrap ( "request" , options . auth . hook ) ;
61+ }
5762 }
5863
5964 this . request = request . defaults ( requestDefaults ) ;
Original file line number Diff line number Diff line change 11import { Agent } from "http" ;
22
3+ import { request as Request } from "@octokit/request" ;
34import { Octokit } from "." ;
45
56export type OctokitOptions = {
6- auth ?: string ;
7+ auth ?: string | AutenticationHook ;
78 request ?: OctokitRequestOptions ;
89 [ option : string ] : any ;
910} ;
1011
12+ interface AutenticationHook {
13+ ( options ?: any ) : any ;
14+
15+ hook : (
16+ request : typeof Request ,
17+ options : Endpoint
18+ ) => ReturnType < typeof Request > ;
19+ }
20+
1121export type Plugin = ( octokit : Octokit , options ?: OctokitOptions ) => void ;
1222
1323// TODO: deduplicate
@@ -60,6 +70,21 @@ export type Parameters = {
6070 [ parameter : string ] : any ;
6171} ;
6272
73+ /**
74+ * Relative or absolute URL. Examples: `'/orgs/:org'`, `https://example.com/foo/bar`
75+ */
76+ export type Url = string ;
77+
78+ /**
79+ * Request method
80+ */
81+ export type Method = "DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT" ;
82+
83+ export type Endpoint = Parameters & {
84+ method : Method ;
85+ url : Url ;
86+ } ;
87+
6388export type RequestHeaders = {
6489 /**
6590 * Avoid setting `accept`, use `mediaFormat.{format|previews}` instead.
You can’t perform that action at this time.
0 commit comments