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.
This commit is contained in:
Dandelion Mané 2020-01-10 19:01:06 -08:00 committed by GitHub
parent c1f123f352
commit adec1b0b5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 26 additions and 34 deletions

View File

@ -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";

View File

@ -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";

View File

@ -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<typeof jest.fn>;

View File

@ -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";

View File

@ -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", () => {

View File

@ -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"));

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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";

View File

@ -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(

View File

@ -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";

View File

@ -1,6 +1,6 @@
// @flow
import type {RepoIdString} from "../../core/repoId";
import type {RepoIdString} from "../github/repoId";
export type Repository = {|
+commits: {[Hash]: Commit},

View File

@ -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);

View File

@ -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";

View File

@ -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";

View File

@ -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";

View File

@ -1,6 +1,6 @@
// @flow
import {makeRepoId} from "../../core/repoId";
import {makeRepoId} from "./repoId";
import {GithubGitGateway} from "./githubGitGateway";
describe("src/plugins/github/githubGitGateway", () => {

View File

@ -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,

View File

@ -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 = {|

View File

@ -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/..."

View File

@ -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

View File

@ -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";
/**

View File

@ -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<typeof jest.fn>;

View File

@ -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})/`;

View File

@ -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";