add loadWeightedGraph modules for plugins (#1602)

This commit adds `loadWeightedGraph` modules for both the GitHub and
Discourse plugins. They will replacing existing (and inconsistently
named) modules which load regular graphs. In addition to loading
the underlying graph, they set weights according to the plugins'
default type-level weights.

The soon-to-be-replaced modules have been marked deprecated.

Another small and vital step towards #1557.

Test plan: The functions that these functions replace are not tested,
because they are IO-heavy composition methods which are painful to test
themselves, and directly depend on well-tested behavior. For the same
reason, no unit tests have been added. Given the nature of the methods
in question, it's unlikely that they'll be sublty broken.
This commit is contained in:
Dandelion Mané 2020-01-30 15:17:32 -08:00 committed by GitHub
parent 4407c4f9fc
commit 1dd7e7a3c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 0 deletions

View File

@ -1,5 +1,13 @@
// @flow
// This module is deprecated, and is being replaced by
// discourse/loadWeightedGraph. Over the course of finishing #1557,
// @decentralion will remove this module and merge its implementation into
// loadWeightedGraph.
//
// This module is untested, because it is an IO-heavy composition of pieces of
// functionality which are individually quite well tested.
import Database from "better-sqlite3";
import base64url from "base64url";
import {Fetcher} from "./fetch";

View File

@ -0,0 +1,24 @@
// @flow
//
// This module is the entry point for clients of the Discourse plugin that
// want to load a completed WeightedGraph containing Discourse data.
//
// This module is untested, because it is an IO-heavy composition of pieces of
// functionality which are individually quite well tested.
import {loadDiscourse, type Options} from "./loadDiscourse";
import {TaskReporter} from "../../util/taskReporter";
import {weightsForDeclaration} from "../../analysis/pluginDeclaration";
import {type WeightedGraph} from "../../core/weightedGraph";
import {declaration} from "./declaration";
export type {Options} from "./loadDiscourse";
export async function loadWeightedGraph(
options: Options,
reporter: TaskReporter
): Promise<WeightedGraph> {
const graph = await loadDiscourse(options, reporter);
const weights = weightsForDeclaration(declaration);
return {graph, weights};
}

View File

@ -1,5 +1,13 @@
// @flow
// This module is deprecated, and is being replaced by
// github/loadWeightedGraph. Over the course of finishing #1557,
// @decentralion will remove this module and merge its implementation into
// loadWeightedGraph.
//
// This module is untested, because it is an IO-heavy composition of pieces of
// functionality which are individually quite well tested.
import {TaskReporter} from "../../util/taskReporter";
import {createGraph} from "./createGraph";
import fetchGithubRepo from "./fetchGithubRepo";

View File

@ -0,0 +1,24 @@
// @flow
//
// This module is the entry point for clients of the GitHub plugin that
// want to load a completed WeightedGraph containing GitHub data.
//
// This module is untested, because it is an IO-heavy composition of pieces of
// functionality which are individually quite well tested.
import {loadGraph, type Options} from "./loadGraph";
import {TaskReporter} from "../../util/taskReporter";
import {weightsForDeclaration} from "../../analysis/pluginDeclaration";
import {type WeightedGraph} from "../../core/weightedGraph";
import {declaration} from "./declaration";
export type {Options} from "./loadGraph";
export async function loadWeightedGraph(
options: Options,
reporter: TaskReporter
): Promise<WeightedGraph> {
const graph = await loadGraph(options, reporter);
const weights = weightsForDeclaration(declaration);
return {graph, weights};
}