diff --git a/src/app/credExplorer/App.js b/src/app/credExplorer/App.js index c5e20b9..7d31759 100644 --- a/src/app/credExplorer/App.js +++ b/src/app/credExplorer/App.js @@ -17,7 +17,7 @@ import {type EdgeEvaluator} from "../../core/attribution/pagerank"; import {WeightConfig} from "./WeightConfig"; import type {PagerankNodeDecomposition} from "../../core/attribution/pagerankNodeDecomposition"; import RepositorySelect from "./RepositorySelect"; -import type {Repo} from "./repoRegistry"; +import type {Repo} from "../../core/repo"; import * as NullUtil from "../../util/null"; @@ -135,18 +135,16 @@ export class App extends React.Component { } const githubPromise = new GithubAdapter() - .load(selectedRepo.owner, selectedRepo.name) + .load(selectedRepo) .then((adapter) => { const graph = adapter.graph(); return {graph, adapter}; }); - const gitPromise = new GitAdapter() - .load(selectedRepo.owner, selectedRepo.name) - .then((adapter) => { - const graph = adapter.graph(); - return {graph, adapter}; - }); + const gitPromise = new GitAdapter().load(selectedRepo).then((adapter) => { + const graph = adapter.graph(); + return {graph, adapter}; + }); Promise.all([gitPromise, githubPromise]).then((graphsAndAdapters) => { const graph = Graph.merge(graphsAndAdapters.map((x) => x.graph)); diff --git a/src/app/credExplorer/PagerankTable.test.js b/src/app/credExplorer/PagerankTable.test.js index a936007..1b8091f 100644 --- a/src/app/credExplorer/PagerankTable.test.js +++ b/src/app/credExplorer/PagerankTable.test.js @@ -81,7 +81,7 @@ async function example() { backwardName: "is fooed by", }, ], - load: (_unused_repoOwner, _unused_repoName) => { + load: (_unused_repo) => { throw new Error("unused"); }, }), @@ -109,7 +109,7 @@ async function example() { backwardName: "is barred by", }, ], - load: (_unused_repoOwner, _unused_repoName) => { + load: (_unused_repo) => { throw new Error("unused"); }, }), @@ -125,7 +125,7 @@ async function example() { edgePrefix: () => EdgeAddress.fromParts(["xox"]), nodeTypes: () => [], edgeTypes: () => [], - load: (_unused_repoOwner, _unused_repoName) => { + load: (_unused_repo) => { throw new Error("unused"); }, }), @@ -141,7 +141,7 @@ async function example() { nodeTypes: () => [], edgeTypes: () => [], name: () => "unused", - load: (_unused_repoOwner, _unused_repoName) => { + load: (_unused_repo) => { throw new Error("unused"); }, }), diff --git a/src/app/credExplorer/RepositorySelect.js b/src/app/credExplorer/RepositorySelect.js index 1f1ed92..91ec623 100644 --- a/src/app/credExplorer/RepositorySelect.js +++ b/src/app/credExplorer/RepositorySelect.js @@ -7,7 +7,8 @@ import deepEqual from "lodash.isequal"; import * as NullUtil from "../../util/null"; import type {LocalStore} from "../localStore"; -import {type Repo, fromJSON, REPO_REGISTRY_API} from "./repoRegistry"; +import {fromJSON, REPO_REGISTRY_API} from "./repoRegistry"; +import {type Repo, stringToRepo, repoToString} from "../../core/repo"; export const REPO_KEY = "selectedRepository"; export type Status = @@ -66,26 +67,6 @@ export default class RepositorySelect extends React.Component { } } -function validateRepo(repo: Repo) { - const validRe = /^[A-Za-z0-9_-]+$/; - if (!repo.owner.match(validRe)) { - throw new Error(`Invalid repository owner: ${JSON.stringify(repo.owner)}`); - } - if (!repo.name.match(validRe)) { - throw new Error(`Invalid repository name: ${JSON.stringify(repo.name)}`); - } -} - -function repoStringToRepo(x: string): Repo { - const pieces = x.split("/"); - if (pieces.length !== 2) { - throw new Error(`Invalid repo string: ${x}`); - } - const repo = {owner: pieces[0], name: pieces[1]}; - validateRepo(repo); - return repo; -} - export async function loadStatus(localStore: LocalStore): Promise { try { const response = await fetch(REPO_REGISTRY_API); @@ -147,15 +128,14 @@ export class PureRepositorySelect extends React.PureComponent< Please choose a repository to inspect:{" "} {selectedRepo != null && (