Skip to content
This repository was archived by the owner on Dec 30, 2024. It is now read-only.

Commit 93e4ec3

Browse files
authored
Merge pull request #3 from Helveg/main
Added `octokitScope` to define scope of octokit instance.
2 parents 8238084 + 6fafa16 commit 93e4ec3

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/interfaces/octokit-module-options.interface.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { ModuleMetadata, Type } from '@nestjs/common';
1+
import { ModuleMetadata, Scope, Type } from '@nestjs/common';
22
import { Octokit } from 'octokit';
33

44
export interface OctokitModuleOptions {
55
isGlobal?: boolean;
66
octokitOptions?: ConstructorParameters<typeof Octokit>[0];
77
plugins?: Parameters<typeof Octokit['plugin']>;
8+
octokitScope?: Scope;
89
}
910

1011
export type AsyncOctokitModuleOptions = Omit<OctokitModuleOptions, 'isGlobal'>;
@@ -24,4 +25,5 @@ export interface OctokitModuleAsyncOptions
2425
...args: any[]
2526
) => Promise<AsyncOctokitModuleOptions> | AsyncOctokitModuleOptions;
2627
inject?: any[];
28+
octokitScope?: Scope,
2729
}

src/octokit.module.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DynamicModule, Module, Provider } from '@nestjs/common';
1+
import { DynamicModule, Module, Provider, Scope } from '@nestjs/common';
22
import { Octokit } from 'octokit';
33
import {
44
OctokitModuleAsyncOptions,
@@ -20,6 +20,7 @@ export class OctokitModule {
2020
providers: [
2121
{
2222
provide: OCTOKIT,
23+
scope: options.octokitScope || Scope.DEFAULT,
2324
useValue: this.instantiateOctokit(options),
2425
},
2526
],
@@ -33,6 +34,7 @@ export class OctokitModule {
3334
useFactory: (options: OctokitModuleOptions) =>
3435
this.instantiateOctokit(options),
3536
provide: OCTOKIT,
37+
scope: options.octokitScope || Scope.DEFAULT,
3638
inject: [OCTOKIT_OPTIONS],
3739
};
3840
return {
@@ -89,7 +91,10 @@ export class OctokitModule {
8991
if (options.plugins) {
9092
MyOctokit = MyOctokit.plugin(...options.plugins);
9193
}
92-
93-
return new MyOctokit(options.octokitOptions);
94+
let instanceOptions: OctokitModuleOptions["octokitOptions"] = {...options.octokitOptions};
95+
if (typeof instanceOptions?.auth === "function") {
96+
instanceOptions.auth = instanceOptions.auth();
97+
}
98+
return new MyOctokit(instanceOptions);
9499
}
95100
}

0 commit comments

Comments
 (0)