From adec1b0b5d40ca364873b0b725015b82ae6e515d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dandelion=20Man=C3=A9?= Date: Fri, 10 Jan 2020 19:01:06 -0800 Subject: [PATCH] Move `repoId.js` from `core` to `plugins/github` (#1535) In the early days of the project, we used GitHub repository ids as the core way of identifiying projects. This was a weird choice, since it's so specific to the GitHub plugin. In #1238 we added a (theoretically) agnostic type in `Project`, although in practice it's still pretty coupled. Still, it will be best to move the `RepoId` type out of `core` and to the GitHub plugin where it belongs. This leaves a few "awkard" imports from plugin code, (e.g. in the api module), but generally the places that are importing `RepoId` were already importing stuff from Discourse and Identity plugins. In either case, I'd rather have the awkwardness of depending on the RepoId in core places be obvious (from the dependency on plugin code) rather than giving a false appearance that RepoIds are really a core concept. Test plan: `yarn test` passes. --- src/api/load.test.js | 2 +- src/cli/genProject.js | 2 +- src/cli/load.test.js | 2 +- src/core/project.js | 2 +- src/core/project.test.js | 2 +- src/core/project_io.test.js | 2 +- src/plugins/git/cloneAndLoadRepository.js | 2 +- src/plugins/git/gitGateway.js | 2 +- src/plugins/git/loadRepository.js | 6 +----- src/plugins/git/loadRepository.test.js | 2 +- src/plugins/git/render.js | 2 +- src/plugins/git/render.test.js | 2 +- src/plugins/git/types.js | 2 +- src/plugins/github/bin/fetchAndPrintGithubRepo.js | 2 +- src/plugins/github/fetchGithubOrg.js | 2 +- src/plugins/github/fetchGithubRepo.js | 2 +- src/plugins/github/githubGitGateway.js | 2 +- src/plugins/github/githubGitGateway.test.js | 2 +- src/plugins/github/loadGithubData.js | 2 +- src/plugins/github/loadGraph.js | 2 +- src/plugins/github/parseReferences.js | 2 +- src/{core => plugins/github}/repoId.js | 0 src/{core => plugins/github}/repoId.test.js | 2 +- src/plugins/github/specToProject.js | 6 +----- src/plugins/github/specToProject.test.js | 2 +- src/plugins/github/urlIdParse.js | 2 +- src/plugins/identity/alias.js | 2 +- 27 files changed, 26 insertions(+), 34 deletions(-) rename src/{core => plugins/github}/repoId.js (100%) rename src/{core => plugins/github}/repoId.test.js (98%) diff --git a/src/api/load.test.js b/src/api/load.test.js index 4ffa137..63dbb0e 100644 --- a/src/api/load.test.js +++ b/src/api/load.test.js @@ -14,7 +14,7 @@ import { getProjectIds, loadProject, } from "../core/project_io"; -import {makeRepoId} from "../core/repoId"; +import {makeRepoId} from "../plugins/github/repoId"; import {defaultWeights} from "../analysis/weights"; import {NodeAddress, Graph} from "../core/graph"; import {node} from "../core/graphTestUtil"; diff --git a/src/cli/genProject.js b/src/cli/genProject.js index 533daa1..bae9272 100644 --- a/src/cli/genProject.js +++ b/src/cli/genProject.js @@ -14,7 +14,7 @@ import { projectToJSON, createProject as defaultProject, } from "../core/project"; -import {type RepoId} from "../core/repoId"; +import {type RepoId} from "../plugins/github/repoId"; import {specToProject} from "../plugins/github/specToProject"; import * as NullUtil from "../util/null"; diff --git a/src/cli/load.test.js b/src/cli/load.test.js index 36e2275..b170903 100644 --- a/src/cli/load.test.js +++ b/src/cli/load.test.js @@ -13,7 +13,7 @@ import * as Common from "./common"; import {defaultParams, partialParams} from "../analysis/timeline/params"; import {declaration as githubDeclaration} from "../plugins/github/declaration"; import {createProject} from "../core/project"; -import {makeRepoId, stringToRepoId} from "../core/repoId"; +import {makeRepoId, stringToRepoId} from "../plugins/github/repoId"; jest.mock("../api/load", () => ({load: jest.fn()})); type JestMockFn = $Call; diff --git a/src/core/project.js b/src/core/project.js index 7551633..8762324 100644 --- a/src/core/project.js +++ b/src/core/project.js @@ -1,7 +1,7 @@ // @flow import base64url from "base64url"; -import {type RepoId} from "../core/repoId"; +import {type RepoId} from "../plugins/github/repoId"; import {toCompat, fromCompat, type Compatible} from "../util/compat"; import {type Identity} from "../plugins/identity/identity"; import {type DiscourseServer} from "../plugins/discourse/loadDiscourse"; diff --git a/src/core/project.test.js b/src/core/project.test.js index af41e38..12e0937 100644 --- a/src/core/project.test.js +++ b/src/core/project.test.js @@ -10,7 +10,7 @@ import { createProject, } from "./project"; -import {makeRepoId} from "./repoId"; +import {makeRepoId} from "../plugins/github/repoId"; import {toCompat} from "../util/compat"; describe("core/project", () => { diff --git a/src/core/project_io.test.js b/src/core/project_io.test.js index fb9a83b..5746a3b 100644 --- a/src/core/project_io.test.js +++ b/src/core/project_io.test.js @@ -19,7 +19,7 @@ import { loadProject, } from "./project_io"; -import {makeRepoId} from "./repoId"; +import {makeRepoId} from "../plugins/github/repoId"; describe("core/project_io", () => { const foobar = deepFreeze(makeRepoId("foo", "bar")); diff --git a/src/plugins/git/cloneAndLoadRepository.js b/src/plugins/git/cloneAndLoadRepository.js index ff394cc..48ef6a4 100644 --- a/src/plugins/git/cloneAndLoadRepository.js +++ b/src/plugins/git/cloneAndLoadRepository.js @@ -4,7 +4,7 @@ import tmp from "tmp"; import {localGit} from "./gitUtils"; import type {Repository} from "./types"; import {loadRepository} from "./loadRepository"; -import type {RepoId} from "../../core/repoId"; +import type {RepoId} from "../../plugins/github/repoId"; /** * Load Git repository data from a fresh clone of a GitHub repo. Loads diff --git a/src/plugins/git/gitGateway.js b/src/plugins/git/gitGateway.js index d64c7c4..06bf590 100644 --- a/src/plugins/git/gitGateway.js +++ b/src/plugins/git/gitGateway.js @@ -1,6 +1,6 @@ // @flow -import type {RepoId} from "../../core/repoId"; +import type {RepoId} from "../../plugins/github/repoId"; import type {Hash} from "./types"; export type URL = string; diff --git a/src/plugins/git/loadRepository.js b/src/plugins/git/loadRepository.js index 9a21187..d940de7 100644 --- a/src/plugins/git/loadRepository.js +++ b/src/plugins/git/loadRepository.js @@ -13,11 +13,7 @@ import * as MapUtil from "../../util/map"; import type {GitDriver} from "./gitUtils"; import type {Repository, Commit} from "./types"; import {localGit} from "./gitUtils"; -import { - repoIdToString, - type RepoId, - type RepoIdString, -} from "../../core/repoId"; +import {repoIdToString, type RepoId, type RepoIdString} from "../github/repoId"; /** * Load a Git repository from disk into memory. The `rootRef` should be diff --git a/src/plugins/git/loadRepository.test.js b/src/plugins/git/loadRepository.test.js index b200b66..cbef668 100644 --- a/src/plugins/git/loadRepository.test.js +++ b/src/plugins/git/loadRepository.test.js @@ -2,7 +2,7 @@ import tmp from "tmp"; -import {makeRepoId, repoIdToString} from "../../core/repoId"; +import {makeRepoId, repoIdToString} from "../github/repoId"; import {createExampleRepo} from "./example/exampleRepo"; import {localGit} from "./gitUtils"; import {loadRepository} from "./loadRepository"; diff --git a/src/plugins/git/render.js b/src/plugins/git/render.js index 6603e96..7596593 100644 --- a/src/plugins/git/render.js +++ b/src/plugins/git/render.js @@ -4,7 +4,7 @@ import React from "react"; import Link from "../../webutil/Link"; import * as N from "./nodes"; import type {Repository} from "./types"; -import {type RepoIdString, stringToRepoId} from "../../core/repoId"; +import {type RepoIdString, stringToRepoId} from "../github/repoId"; import type {GitGateway} from "./gitGateway"; export function description( diff --git a/src/plugins/git/render.test.js b/src/plugins/git/render.test.js index d98f220..4edc34f 100644 --- a/src/plugins/git/render.test.js +++ b/src/plugins/git/render.test.js @@ -4,7 +4,7 @@ import deepFreeze from "deep-freeze"; import * as N from "./nodes"; import {shallow} from "enzyme"; import {description} from "./render"; -import {type RepoId, repoIdToString, makeRepoId} from "../../core/repoId"; +import {type RepoId, repoIdToString, makeRepoId} from "../github/repoId"; import type {Repository, Hash, Commit} from "./types"; import type {GitGateway, URL} from "./gitGateway"; import Link from "../../webutil/Link"; diff --git a/src/plugins/git/types.js b/src/plugins/git/types.js index 38ea152..6115594 100644 --- a/src/plugins/git/types.js +++ b/src/plugins/git/types.js @@ -1,6 +1,6 @@ // @flow -import type {RepoIdString} from "../../core/repoId"; +import type {RepoIdString} from "../github/repoId"; export type Repository = {| +commits: {[Hash]: Commit}, diff --git a/src/plugins/github/bin/fetchAndPrintGithubRepo.js b/src/plugins/github/bin/fetchAndPrintGithubRepo.js index 138c670..48c9745 100644 --- a/src/plugins/github/bin/fetchAndPrintGithubRepo.js +++ b/src/plugins/github/bin/fetchAndPrintGithubRepo.js @@ -16,7 +16,7 @@ import stringify from "json-stable-stringify"; import tmp from "tmp"; import fetchGithubRepo from "../fetchGithubRepo"; -import {makeRepoId} from "../../../core/repoId"; +import {makeRepoId} from "../repoId"; function parseArgs() { const argv = process.argv.slice(2); diff --git a/src/plugins/github/fetchGithubOrg.js b/src/plugins/github/fetchGithubOrg.js index dfa7faa..ce9b817 100644 --- a/src/plugins/github/fetchGithubOrg.js +++ b/src/plugins/github/fetchGithubOrg.js @@ -1,6 +1,6 @@ // @flow -import {type RepoId, makeRepoId} from "../../core/repoId"; +import {type RepoId, makeRepoId} from "./repoId"; import * as Queries from "../../graphql/queries"; import {postQuery} from "./fetchGithubRepo"; diff --git a/src/plugins/github/fetchGithubRepo.js b/src/plugins/github/fetchGithubRepo.js index 0f5f62a..2c6f7c7 100644 --- a/src/plugins/github/fetchGithubRepo.js +++ b/src/plugins/github/fetchGithubRepo.js @@ -9,7 +9,7 @@ import fetch from "isomorphic-fetch"; import path from "path"; import retry from "retry"; -import {type RepoId, repoIdToString} from "../../core/repoId"; +import {type RepoId, repoIdToString} from "./repoId"; import {Mirror} from "../../graphql/mirror"; import * as Queries from "../../graphql/queries"; import {stringify, inlineLayout, type Body} from "../../graphql/queries"; diff --git a/src/plugins/github/githubGitGateway.js b/src/plugins/github/githubGitGateway.js index 0157592..2f0c456 100644 --- a/src/plugins/github/githubGitGateway.js +++ b/src/plugins/github/githubGitGateway.js @@ -1,6 +1,6 @@ // @flow -import {type RepoId} from "../../core/repoId"; +import {type RepoId} from "./repoId"; import type {Hash} from "../git/types"; import type {GitGateway, URL} from "../git/gitGateway"; diff --git a/src/plugins/github/githubGitGateway.test.js b/src/plugins/github/githubGitGateway.test.js index 9c50ce3..c08d912 100644 --- a/src/plugins/github/githubGitGateway.test.js +++ b/src/plugins/github/githubGitGateway.test.js @@ -1,6 +1,6 @@ // @flow -import {makeRepoId} from "../../core/repoId"; +import {makeRepoId} from "./repoId"; import {GithubGitGateway} from "./githubGitGateway"; describe("src/plugins/github/githubGitGateway", () => { diff --git a/src/plugins/github/loadGithubData.js b/src/plugins/github/loadGithubData.js index fe550d6..8f64680 100644 --- a/src/plugins/github/loadGithubData.js +++ b/src/plugins/github/loadGithubData.js @@ -6,7 +6,7 @@ import pako from "pako"; import fetchGithubRepo from "./fetchGithubRepo"; import {RelationalView} from "./relationalView"; -import type {RepoId} from "../../core/repoId"; +import type {RepoId} from "./repoId"; export type Options = {| +token: string, diff --git a/src/plugins/github/loadGraph.js b/src/plugins/github/loadGraph.js index df5520c..cb4cb0f 100644 --- a/src/plugins/github/loadGraph.js +++ b/src/plugins/github/loadGraph.js @@ -4,7 +4,7 @@ import {TaskReporter} from "../../util/taskReporter"; import {createGraph} from "./createGraph"; import fetchGithubRepo from "./fetchGithubRepo"; import {RelationalView} from "./relationalView"; -import {type RepoId, repoIdToString} from "../../core/repoId"; +import {type RepoId, repoIdToString} from "./repoId"; import {Graph} from "../../core/graph"; export type Options = {| diff --git a/src/plugins/github/parseReferences.js b/src/plugins/github/parseReferences.js index 61bedf1..06dc3e0 100644 --- a/src/plugins/github/parseReferences.js +++ b/src/plugins/github/parseReferences.js @@ -1,7 +1,7 @@ // @flow import {textBlocks} from "./parseMarkdown"; -import {githubOwnerPattern, githubRepoPattern} from "../../core/repoId"; +import {githubOwnerPattern, githubRepoPattern} from "./repoId"; export type ParsedReference = {| // "@user" or "#123" or "https://github.com/owner/name/..." diff --git a/src/core/repoId.js b/src/plugins/github/repoId.js similarity index 100% rename from src/core/repoId.js rename to src/plugins/github/repoId.js diff --git a/src/core/repoId.test.js b/src/plugins/github/repoId.test.js similarity index 98% rename from src/core/repoId.test.js rename to src/plugins/github/repoId.test.js index a7813ab..b3c4599 100644 --- a/src/core/repoId.test.js +++ b/src/plugins/github/repoId.test.js @@ -8,7 +8,7 @@ import { type RepoIdString, } from "./repoId"; -describe("core/repoId", () => { +describe("plugins/github/repoId", () => { describe("RepoId type", () => { it("manually constructing a RepoId is illegal", () => { // $ExpectFlowError diff --git a/src/plugins/github/specToProject.js b/src/plugins/github/specToProject.js index b0ba1b6..a608359 100644 --- a/src/plugins/github/specToProject.js +++ b/src/plugins/github/specToProject.js @@ -1,11 +1,7 @@ // @flow import {type Project, createProject} from "../../core/project"; -import { - stringToRepoId, - githubOwnerPattern, - githubRepoPattern, -} from "../../core/repoId"; +import {stringToRepoId, githubOwnerPattern, githubRepoPattern} from "./repoId"; import {fetchGithubOrg} from "./fetchGithubOrg"; /** diff --git a/src/plugins/github/specToProject.test.js b/src/plugins/github/specToProject.test.js index d77eae1..b8fdf99 100644 --- a/src/plugins/github/specToProject.test.js +++ b/src/plugins/github/specToProject.test.js @@ -1,7 +1,7 @@ // @flow import {specToProject} from "./specToProject"; -import {stringToRepoId} from "../../core/repoId"; +import {stringToRepoId} from "./repoId"; import {type Project, createProject} from "../../core/project"; jest.mock("./fetchGithubOrg", () => ({fetchGithubOrg: jest.fn()})); type JestMockFn = $Call; diff --git a/src/plugins/github/urlIdParse.js b/src/plugins/github/urlIdParse.js index 2729cc2..c5a9362 100644 --- a/src/plugins/github/urlIdParse.js +++ b/src/plugins/github/urlIdParse.js @@ -1,6 +1,6 @@ // @flow -import {githubOwnerPattern, githubRepoPattern} from "../../core/repoId"; +import {githubOwnerPattern, githubRepoPattern} from "./repoId"; const urlBase = "^https?://github\\.com"; const repoUrl = `${urlBase}/(?:${githubOwnerPattern})/(?:${githubRepoPattern})/`; diff --git a/src/plugins/identity/alias.js b/src/plugins/identity/alias.js index 1b3e949..75fb283 100644 --- a/src/plugins/identity/alias.js +++ b/src/plugins/identity/alias.js @@ -1,7 +1,7 @@ // @flow import {type NodeAddressT} from "../../core/graph"; -import {githubOwnerPattern} from "../../core/repoId"; +import {githubOwnerPattern} from "../github/repoId"; import {loginAddress as githubAddress} from "../github/nodes"; import {userAddress as discourseAddress} from "../discourse/address";