diff --git a/src/v3/cli/commands/loadPlugin.js b/src/v3/cli/commands/loadPlugin.js index 7588bd8..6954050 100644 --- a/src/v3/cli/commands/loadPlugin.js +++ b/src/v3/cli/commands/loadPlugin.js @@ -5,6 +5,7 @@ import mkdirp from "mkdirp"; import path from "path"; import {loadGithubData} from "../../plugins/github/loadGithubData"; +import {loadGitData} from "../../plugins/git/loadGitData"; import {pluginNames, sourcecredDirectoryFlag} from "../common"; export default class PluginGraphCommand extends Command { @@ -79,6 +80,9 @@ function loadPlugin({basedir, plugin, repoOwner, repoName, githubToken}) { }); } break; + case "git": + loadGitData({repoOwner, repoName, outputDirectory}); + break; default: console.error("fatal: Unknown plugin: " + (plugin: empty)); process.exitCode = 1; diff --git a/src/v3/cli/common.js b/src/v3/cli/common.js index eae6057..6fe081e 100644 --- a/src/v3/cli/common.js +++ b/src/v3/cli/common.js @@ -4,9 +4,9 @@ import {flags} from "@oclif/command"; import os from "os"; import path from "path"; -export type PluginName = "github"; +export type PluginName = "github" | "git"; export function pluginNames(): PluginName[] { - return ["github"]; + return ["github", "git"]; } function defaultStorageDirectory() { diff --git a/src/v3/plugins/git/loadGitData.js b/src/v3/plugins/git/loadGitData.js new file mode 100644 index 0000000..9f8c62a --- /dev/null +++ b/src/v3/plugins/git/loadGitData.js @@ -0,0 +1,24 @@ +// @flow + +import fs from "fs-extra"; +import path from "path"; + +import cloneAndLoadRepository from "./cloneAndLoadRepository"; +import {createGraph} from "./createGraph"; + +export type Options = {| + +repoOwner: string, + +repoName: string, + +outputDirectory: string, +|}; + +export function loadGitData(options: Options): Promise { + const repository = cloneAndLoadRepository( + options.repoOwner, + options.repoName + ); + const graph = createGraph(repository); + const blob = JSON.stringify(graph); + const outputFilename = path.join(options.outputDirectory, "graph.json"); + return fs.writeFile(outputFilename, blob); +}