File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 1- export function Octokit ( ) { }
1+ import { OctokitOptions , Plugin } from "./types" ;
2+
3+ export class Octokit {
4+ static plugins : Plugin [ ] = [ ] ;
5+ static plugin ( plugins : Plugin | Plugin [ ] ) {
6+ const currentPlugins = this . plugins ;
7+ const newPlugins = Array . isArray ( plugins ) ? plugins : [ plugins ] ;
8+
9+ return class NewOctokit extends this {
10+ static plugins = currentPlugins . concat (
11+ newPlugins . filter ( plugin => ! currentPlugins . includes ( plugin ) )
12+ ) ;
13+ } ;
14+ }
15+
16+ constructor ( options ?: OctokitOptions ) {
17+ // https://stackoverflow.com/a/16345172
18+ const classConstructor = this . constructor as typeof Octokit ;
19+ classConstructor . plugins . forEach ( plugin => plugin ( this , options ) ) ;
20+ }
21+
22+ // allow for plugins to extend the Octokit instance
23+ [ key : string ] : any ;
24+ }
Original file line number Diff line number Diff line change 1+ import { Octokit } from "." ;
2+
3+ export type OctokitOptions = {
4+ [ option : string ] : any ;
5+ } ;
6+
7+ export type Plugin = ( octokit : Octokit , options ?: OctokitOptions ) => void ;
You can’t perform that action at this time.
0 commit comments