Third entity: Github fork

This commit is contained in:
askeluv
2019-03-08 20:04:03 +08:00
parent 55fd71c5e1
commit 9f69d2cb76
17 changed files with 310 additions and 15 deletions

View File

@@ -3,9 +3,9 @@ import { Connection, ConnectionOptions, createConnection } from 'typeorm';
import { logUtils } from '@0x/utils';
import { GithubSource } from '../data_sources/github';
import { GithubPullRequest, GithubRepo } from '../entities';
import { GithubFork, GithubPullRequest, GithubRepo } from '../entities';
import * as ormConfig from '../ormconfig';
import { parseGithubPulls, parseGithubRepo } from '../parsers/github';
import { parseGithubForks, parseGithubPulls, parseGithubRepo } from '../parsers/github';
import { handleError } from '../utils';
const GITHUB_OWNER = '0xProject';
@@ -41,5 +41,19 @@ let connection: Connection;
await GithubPullRequestRepository.save(pulls);
}
// get forks and save
const GithubForkRepository = connection.getRepository(GithubFork);
numberOfRecords = RECORDS_PER_PAGE;
page = 1;
while (numberOfRecords === RECORDS_PER_PAGE) {
logUtils.log(`Fetching Github forks from API, page: ${page}.`);
const rawForks = await githubSource.getGithubForksAsync(page);
const forks = parseGithubForks(rawForks, observedTimestamp);
numberOfRecords = forks.length;
page++;
logUtils.log(`Saving ${forks.length} forks to database.`);
await GithubForkRepository.save(forks);
}
process.exit(0);
})().catch(handleError);