|
1 | 1 | import { Context } from 'probot'; |
2 | 2 | import { defaultConfig } from '~common/consts'; |
3 | 3 | import { Severity } from '~common/enums'; |
4 | | -import { CacheKey, Config } from '~common/types'; |
| 4 | +import { Config } from '~common/types'; |
5 | 5 | import { appConfig, cacheConfig } from '~configs'; |
6 | 6 | import { UserError } from '~errors'; |
7 | | -import { decodeBase64ToText, merge, parseYaml } from '~helpers'; |
| 7 | +import { decodeBase64ToText, getUserApiKeyCacheKey, getUserConfigCacheKey, merge, parseYaml } from '~helpers'; |
8 | 8 | import { configSchema } from '~schemas'; |
9 | 9 | import { CacheService } from './cache.service'; |
10 | 10 | import { GitHubService } from './github.service'; |
11 | 11 | import { QueueService } from './queue.service'; |
12 | 12 |
|
13 | 13 | export class ConfigService { |
14 | | - private static instance: ConfigService; |
15 | | - |
16 | | - private constructor( |
| 14 | + constructor( |
17 | 15 | private readonly cacheService: CacheService, |
18 | 16 | private readonly queueService: QueueService |
19 | 17 | ) {} |
20 | 18 |
|
21 | | - public static getInstance(): ConfigService { |
22 | | - if (!ConfigService.instance) { |
23 | | - ConfigService.instance = new ConfigService(CacheService.getInstance(), QueueService.getInstance()); |
24 | | - } |
25 | | - |
26 | | - return ConfigService.instance; |
27 | | - } |
28 | | - |
29 | 19 | async getApiKey(context: Context): Promise<string> { |
30 | 20 | try { |
31 | 21 | const { owner, repo } = context.repo(); |
32 | | - const apiKeyCacheKey: CacheKey = `github/${owner}/${repo}:key`; |
| 22 | + const apiKeyCacheKey = getUserApiKeyCacheKey(owner, repo); |
33 | 23 | const cachedApiKey = await this.cacheService.get<string>(apiKeyCacheKey); |
34 | 24 |
|
35 | 25 | if (cachedApiKey) { |
@@ -61,7 +51,7 @@ export class ConfigService { |
61 | 51 | } |
62 | 52 |
|
63 | 53 | async getConfig(context: Context<'pull_request'>, apiKey: string): Promise<Config> { |
64 | | - const configCacheKey: CacheKey = `github/${apiKey}:config`; |
| 54 | + const configCacheKey = getUserConfigCacheKey(apiKey); |
65 | 55 | const cachedConfig = await this.cacheService.get<Config>(configCacheKey); |
66 | 56 |
|
67 | 57 | if (cachedConfig) { |
|
0 commit comments