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

Commit d780369

Browse files
committed
Merge pull request #221 from ericvw/refactor_githubloader_ctor
Move GithubLoader._initGithubLoader logic into GithubLoader constructor
2 parents 63c9d47 + 0369521 commit d780369

File tree

3 files changed

+23
-28
lines changed

3 files changed

+23
-28
lines changed

src/git/loader/GithubAPI.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,14 @@ import GithubRateInfo = require('../model/GithubRateInfo');
2323

2424
// TODO add OAuth support (here or in HTTPCache)
2525
class GithubAPI extends GithubLoader {
26-
27-
// github's version
2826
private static API_VERSION: string = '3.0.0';
2927
private static FORMAT_VERSION: string = '1.0';
3028
private static CACHE_KEY: string = 'git-api-v' + GithubAPI.API_VERSION + '-fmt' + GithubAPI.FORMAT_VERSION;
3129

3230
static NAME: string = 'GithubAPI';
3331

3432
constructor(urls: GithubURLs, options: JSONPointer, shared: JSONPointer, storeDir: string) {
35-
super(urls, options, shared, storeDir, GithubAPI.NAME);
36-
this._initGithubLoader(GithubAPI.CACHE_KEY, GithubAPI.FORMAT_VERSION);
33+
super(urls, options, shared, storeDir, GithubAPI.CACHE_KEY, GithubAPI.NAME, GithubAPI.FORMAT_VERSION);
3734
}
3835

3936
getBranches(): Promise<any> {

src/git/loader/GithubLoader.ts

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,46 @@ import GithubRateInfo = require('../model/GithubRateInfo');
2020
class GithubLoader {
2121

2222
urls: GithubURLs;
23-
24-
cache: HTTPCache;
2523
options: JSONPointer;
26-
shared: JSONPointer;
27-
28-
storeDir: string;
29-
30-
label: string = 'github-loader';
31-
formatVersion: string = '0.0.0';
24+
cache: HTTPCache;
25+
headers: {[index: string]: string} = {};
3226

33-
headers = {};
27+
constructor(
28+
urls: GithubURLs,
29+
options: JSONPointer,
30+
shared: JSONPointer,
31+
storeDir: string,
32+
cacheKey: string,
33+
label: string,
34+
formatVersion: string) {
3435

35-
constructor(urls: GithubURLs, options: JSONPointer, shared: JSONPointer, storeDir: string, label: string) {
3636
assertVar(urls, GithubURLs, 'urls');
3737
assertVar(options, JSONPointer, 'options');
3838
assertVar(shared, JSONPointer, 'shared');
3939
assertVar(storeDir, 'string', 'storeDir');
40+
assertVar(cacheKey, 'string', 'cacheKey');
41+
assertVar(label, 'string', 'label');
42+
assertVar(formatVersion, 'string', 'formatVersion');
4043

4144
this.urls = urls;
4245
this.options = options;
43-
this.shared = shared;
44-
this.storeDir = storeDir;
45-
this.label = label;
46-
}
4746

48-
_initGithubLoader(cacheKey: string, formatVersion: string): void {
4947
var cache = new CacheOpts();
5048
cache.allowClean = this.options.getBoolean('allowClean', cache.allowClean);
5149
cache.cleanInterval = this.options.getDurationSecs('cacheCleanInterval', cache.cleanInterval / 1000) * 1000;
5250
cache.splitDirLevel = this.options.getNumber('splitDirLevel', cache.splitDirLevel);
5351
cache.splitDirChunk = this.options.getNumber('splitDirChunk', cache.splitDirChunk);
5452
cache.jobTimeout = this.options.getDurationSecs('jobTimeout', cache.jobTimeout / 1000) * 1000;
55-
cache.storeDir = path.join(this.storeDir, cacheKey);
53+
cache.storeDir = path.join(storeDir, cacheKey);
5654

5755
var opts: HTTPOpts = {
5856
cache: cache,
59-
concurrent: this.shared.getNumber('concurrent', 20),
60-
oath: this.shared.getString('oath', null),
61-
strictSSL: this.shared.getBoolean('strictSSL', true)
57+
concurrent: shared.getNumber('concurrent', 20),
58+
oath: shared.getString('oath', null),
59+
strictSSL: shared.getBoolean('strictSSL', true)
6260
};
6361

64-
opts.proxy = (this.shared.getString('proxy')
62+
opts.proxy = (shared.getString('proxy')
6563
|| process.env.HTTPS_PROXY
6664
|| process.env.https_proxy
6765
|| process.env.HTTP_PROXY
@@ -70,7 +68,7 @@ class GithubLoader {
7068

7169
this.cache = new HTTPCache(opts);
7270
// required to have some header
73-
this.headers['user-agent'] = this.label + '-v' + formatVersion;
71+
this.headers['user-agent'] = label + '-v' + formatVersion;
7472
}
7573

7674
copyHeadersTo(target: any, source?: any) {
@@ -81,7 +79,6 @@ class GithubLoader {
8179
}
8280

8381
set verbose(verbose: boolean) {
84-
8582
}
8683
}
8784

src/git/loader/GithubRaw.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ class GithubRaw extends GithubLoader {
2323
private static FORMAT_VERSION: string = '1.0';
2424
private static CACHE_KEY = 'git-raw-fmt' + GithubRaw.FORMAT_VERSION;
2525

26+
static NAME: string = 'GithubRaw';
27+
2628
constructor(urls: GithubURLs, options: JSONPointer, shared: JSONPointer, storeDir: string) {
27-
super(urls, options, shared, storeDir, 'GithubRaw');
28-
this._initGithubLoader(GithubRaw.CACHE_KEY, GithubRaw.FORMAT_VERSION);
29+
super(urls, options, shared, storeDir, GithubRaw.CACHE_KEY, GithubRaw.NAME, GithubRaw.FORMAT_VERSION);
2930
}
3031

3132
getText(ref: string, filePath: string): Promise<string> {

0 commit comments

Comments
 (0)