Switch to LoadContext based loading (#1622)

This naming is temporary, as the old loading code is removed it
will be named load and replace the existing function.
This commit is contained in:
Robin van Boven 2020-02-04 22:28:24 +01:00 committed by GitHub
parent f3cfab636e
commit 361961c59f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 4 deletions

View File

@ -23,6 +23,7 @@ import {type Weights as WeightsT} from "../core/weights";
import {loadWeightedGraph} from "./loadWeightedGraph";
import {DataDirectory} from "../backend/dataDirectory";
import {type CacheProvider} from "../backend/cache";
import {LoadContext} from "../backend/loadContext";
export type LoadOptions = {|
+project: Project,
@ -33,6 +34,26 @@ export type LoadOptions = {|
+githubToken: ?GithubToken,
|};
export async function loadContext(
options: LoadOptions,
reporter: TaskReporter
): Promise<void> {
const {
sourcecredDirectory,
githubToken,
project,
params,
weightsOverrides,
} = options;
const data = new DataDirectory(sourcecredDirectory);
const context = new LoadContext({cache: data, githubToken, reporter});
const result = await context.load(project, {
params: params || {},
weightsOverrides,
});
data.storeProject(project, result);
}
/**
* Loads and computes cred for a project.
*

View File

@ -8,7 +8,7 @@ import {LoggingTaskReporter} from "../util/taskReporter";
import type {Command} from "./command";
import * as Common from "./common";
import * as Weights from "../core/weights";
import {load} from "../api/load";
import {loadContext as load} from "../api/load";
import {declaration as discourseDeclaration} from "../plugins/discourse/declaration";
import {type Project, createProject} from "../core/project";

View File

@ -7,7 +7,7 @@ import type {Command} from "./command";
import * as Common from "./common";
import * as Weights from "../core/weights";
import {projectFromJSON} from "../core/project";
import {load} from "../api/load";
import {loadContext as load} from "../api/load";
import {specToProject} from "../plugins/github/specToProject";
import fs from "fs-extra";
import {type PluginDeclaration} from "../analysis/pluginDeclaration";

View File

@ -16,9 +16,9 @@ import {makeRepoId, stringToRepoId} from "../plugins/github/repoId";
import {validateToken} from "../plugins/github/token";
import {defaultParams} from "../analysis/timeline/params";
jest.mock("../api/load", () => ({load: jest.fn()}));
jest.mock("../api/load", () => ({loadContext: jest.fn()}));
type JestMockFn = $Call<typeof jest.fn>;
const load: JestMockFn = (require("../api/load").load: any);
const load: JestMockFn = (require("../api/load").loadContext: any);
describe("cli/load", () => {
const exampleGithubToken = validateToken("0".repeat(40));