Remove the `repositoryName` field from Addresses (#195)

See [#190] for context.

The change is almost entirely straightforward; the only "interesting"
decision I made was to move the repo owner and repo name into the string
id for the Artifact Plugin addresses, as the id would otherwise not be
unique.

[#190]: https://github.com/sourcecred/sourcecred/issues/190#issuecomment-386362870
This commit is contained in:
Dandelion Mané 2018-05-03 11:12:02 -07:00 committed by GitHub
parent 082515e16a
commit b4474e6bd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 379 additions and 832 deletions

View File

@ -2,11 +2,11 @@
exports[`address AddressMap stringifies to JSON 1`] = `
Object {
"{\\"id\\":\\"mansion\\",\\"pluginName\\":\\"houseville\\",\\"repositoryName\\":\\"sourcecred/suburbia\\",\\"type\\":\\"HOME\\"}": Object {
"{\\"id\\":\\"mansion\\",\\"pluginName\\":\\"houseville\\",\\"type\\":\\"HOME\\"}": Object {
"baths": 5,
"beds": 10,
},
"{\\"id\\":\\"mattressStore\\",\\"pluginName\\":\\"houseville\\",\\"repositoryName\\":\\"sourcecred/suburbia\\",\\"type\\":\\"BUSINESS\\"}": Object {
"{\\"id\\":\\"mattressStore\\",\\"pluginName\\":\\"houseville\\",\\"type\\":\\"BUSINESS\\"}": Object {
"baths": 1,
"beds": 99,
},
@ -19,28 +19,25 @@ Array [
Object {
"id": "mansion",
"pluginName": "houseville",
"repositoryName": "sourcecred/suburbia",
"type": "HOME",
},
"{\\"id\\":\\"mansion\\",\\"pluginName\\":\\"houseville\\",\\"repositoryName\\":\\"sourcecred/suburbia\\",\\"type\\":\\"HOME\\"}",
"{\\"id\\":\\"mansion\\",\\"pluginName\\":\\"houseville\\",\\"type\\":\\"HOME\\"}",
],
Array [
Object {
"id": "mansion",
"pluginName": "houseville",
"repositoryName": "sourcecred/suburbia",
"type": "HOME",
},
"{\\"id\\":\\"mansion\\",\\"pluginName\\":\\"houseville\\",\\"repositoryName\\":\\"sourcecred/suburbia\\",\\"type\\":\\"HOME\\"}",
"{\\"id\\":\\"mansion\\",\\"pluginName\\":\\"houseville\\",\\"type\\":\\"HOME\\"}",
],
Array [
Object {
"id": "mattressStore",
"pluginName": "houseville",
"repositoryName": "sourcecred/suburbia",
"type": "BUSINESS",
},
"{\\"id\\":\\"mattressStore\\",\\"pluginName\\":\\"houseville\\",\\"repositoryName\\":\\"sourcecred/suburbia\\",\\"type\\":\\"BUSINESS\\"}",
"{\\"id\\":\\"mattressStore\\",\\"pluginName\\":\\"houseville\\",\\"type\\":\\"BUSINESS\\"}",
],
]
`;

View File

@ -3,11 +3,10 @@
exports[`graph #Graph JSON functions should serialize a simple graph 1`] = `
Object {
"edges": Object {
"{\\"id\\":\\"crab-self-assessment\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"SILLY\\"}": Object {
"{\\"id\\":\\"crab-self-assessment\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"type\\":\\"SILLY\\"}": Object {
"dst": Object {
"id": "razorclaw_crab#2",
"pluginName": "hill_cooking_pot",
"repositoryName": "sourcecred/eventide",
"type": "FOOD",
},
"payload": Object {
@ -16,15 +15,13 @@ Object {
"src": Object {
"id": "razorclaw_crab#2",
"pluginName": "hill_cooking_pot",
"repositoryName": "sourcecred/eventide",
"type": "FOOD",
},
},
"{\\"id\\":\\"hero_of_time#0@again_cooks@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"ACTION\\"}": Object {
"{\\"id\\":\\"hero_of_time#0@again_cooks@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"type\\":\\"ACTION\\"}": Object {
"dst": Object {
"id": "hero_of_time#0",
"pluginName": "hill_cooking_pot",
"repositoryName": "sourcecred/eventide",
"type": "PC",
},
"payload": Object {
@ -34,15 +31,13 @@ Object {
"src": Object {
"id": "seafood_fruit_mix#3",
"pluginName": "hill_cooking_pot",
"repositoryName": "sourcecred/eventide",
"type": "FOOD",
},
},
"{\\"id\\":\\"hero_of_time#0@cooks@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"ACTION\\"}": Object {
"{\\"id\\":\\"hero_of_time#0@cooks@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"type\\":\\"ACTION\\"}": Object {
"dst": Object {
"id": "hero_of_time#0",
"pluginName": "hill_cooking_pot",
"repositoryName": "sourcecred/eventide",
"type": "PC",
},
"payload": Object {
@ -51,97 +46,86 @@ Object {
"src": Object {
"id": "seafood_fruit_mix#3",
"pluginName": "hill_cooking_pot",
"repositoryName": "sourcecred/eventide",
"type": "FOOD",
},
},
"{\\"id\\":\\"hero_of_time#0@eats@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"ACTION\\"}": Object {
"{\\"id\\":\\"hero_of_time#0@eats@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"type\\":\\"ACTION\\"}": Object {
"dst": Object {
"id": "seafood_fruit_mix#3",
"pluginName": "hill_cooking_pot",
"repositoryName": "sourcecred/eventide",
"type": "FOOD",
},
"payload": Object {},
"src": Object {
"id": "hero_of_time#0",
"pluginName": "hill_cooking_pot",
"repositoryName": "sourcecred/eventide",
"type": "PC",
},
},
"{\\"id\\":\\"hero_of_time#0@grabs@razorclaw_crab#2\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"ACTION\\"}": Object {
"{\\"id\\":\\"hero_of_time#0@grabs@razorclaw_crab#2\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"type\\":\\"ACTION\\"}": Object {
"dst": Object {
"id": "hero_of_time#0",
"pluginName": "hill_cooking_pot",
"repositoryName": "sourcecred/eventide",
"type": "PC",
},
"payload": Object {},
"src": Object {
"id": "razorclaw_crab#2",
"pluginName": "hill_cooking_pot",
"repositoryName": "sourcecred/eventide",
"type": "FOOD",
},
},
"{\\"id\\":\\"hero_of_time#0@picks@mighty_bananas#1\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"ACTION\\"}": Object {
"{\\"id\\":\\"hero_of_time#0@picks@mighty_bananas#1\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"type\\":\\"ACTION\\"}": Object {
"dst": Object {
"id": "hero_of_time#0",
"pluginName": "hill_cooking_pot",
"repositoryName": "sourcecred/eventide",
"type": "PC",
},
"payload": Object {},
"src": Object {
"id": "mighty_bananas#1",
"pluginName": "hill_cooking_pot",
"repositoryName": "sourcecred/eventide",
"type": "FOOD",
},
},
"{\\"id\\":\\"mighty_bananas#1@included_in@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"INGREDIENT\\"}": Object {
"{\\"id\\":\\"mighty_bananas#1@included_in@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"type\\":\\"INGREDIENT\\"}": Object {
"dst": Object {
"id": "mighty_bananas#1",
"pluginName": "hill_cooking_pot",
"repositoryName": "sourcecred/eventide",
"type": "FOOD",
},
"payload": Object {},
"src": Object {
"id": "seafood_fruit_mix#3",
"pluginName": "hill_cooking_pot",
"repositoryName": "sourcecred/eventide",
"type": "FOOD",
},
},
"{\\"id\\":\\"razorclaw_crab#2@included_in@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"INGREDIENT\\"}": Object {
"{\\"id\\":\\"razorclaw_crab#2@included_in@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"type\\":\\"INGREDIENT\\"}": Object {
"dst": Object {
"id": "razorclaw_crab#2",
"pluginName": "hill_cooking_pot",
"repositoryName": "sourcecred/eventide",
"type": "FOOD",
},
"payload": Object {},
"src": Object {
"id": "seafood_fruit_mix#3",
"pluginName": "hill_cooking_pot",
"repositoryName": "sourcecred/eventide",
"type": "FOOD",
},
},
},
"nodes": Object {
"{\\"id\\":\\"hero_of_time#0\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"PC\\"}": Object {
"{\\"id\\":\\"hero_of_time#0\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"type\\":\\"PC\\"}": Object {
"payload": Object {},
},
"{\\"id\\":\\"mighty_bananas#1\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"FOOD\\"}": Object {
"{\\"id\\":\\"mighty_bananas#1\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"type\\":\\"FOOD\\"}": Object {
"payload": Object {},
},
"{\\"id\\":\\"razorclaw_crab#2\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"FOOD\\"}": Object {
"{\\"id\\":\\"razorclaw_crab#2\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"type\\":\\"FOOD\\"}": Object {
"payload": Object {},
},
"{\\"id\\":\\"seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"FOOD\\"}": Object {
"{\\"id\\":\\"seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"type\\":\\"FOOD\\"}": Object {
"payload": Object {
"effect": Array [
"attack_power",

View File

@ -4,7 +4,6 @@ import deepEqual from "lodash.isequal";
import stringify from "json-stable-stringify";
export type Address = {|
+repositoryName: string,
+pluginName: string,
+id: string,
+type: string,

View File

@ -15,7 +15,6 @@ describe("address", () => {
|};
function makeAddress(type: "HOME" | "BUSINESS", id: string): Address {
return {
repositoryName: "sourcecred/suburbia",
pluginName: "houseville",
id,
type,
@ -160,12 +159,10 @@ describe("address", () => {
pluginName: "foo",
type: "bar",
id: "zoombat",
repositoryName: "oregano",
};
const a2 = {
id: "zoombat",
type: "bar",
repositoryName: "oregano",
pluginName: "foo",
};
expect(toString(a1)).toEqual(toString(a2));

View File

@ -416,7 +416,6 @@ describe("graph", () => {
id,
type,
pluginName: "graph-test",
repositoryName: "sourcecred",
};
}

View File

@ -9,7 +9,6 @@ import {Graph} from "./graph";
export function makeAddress(id: string, type: string): Address {
return {
repositoryName: "sourcecred/eventide",
pluginName: "hill_cooking_pot",
id,
type,

View File

@ -28,10 +28,10 @@ export function artifactAddress(
repoName: string,
artifactName: string
): Address {
const baseId = artifactName.toLowerCase().replace(NON_SLUG_CHARACTER, "-");
const baseName = artifactName.toLowerCase().replace(NON_SLUG_CHARACTER, "-");
const baseId = `${repoOwner}/${repoName}/${baseName}`;
function address(id) {
return {
repositoryName: `${repoOwner}/${repoName}`,
pluginName: ARTIFACT_PLUGIN_NAME,
id,
type: ARTIFACT_NODE_TYPE,

View File

@ -5,14 +5,14 @@ import {artifactAddress} from "./artifactPlugin";
describe("artifactPlugin", () => {
describe("artifactAddress", () => {
it("formats the repository name", () => {
it("repositoryName included in id", () => {
const a = artifactAddress(
new Graph(),
"not-sourcecred",
"not-artifact-plugin",
"Sample artifact!"
);
expect(a.repositoryName).toEqual("not-sourcecred/not-artifact-plugin");
expect(a.id.startsWith("not-sourcecred/not-artifact-plugin")).toBe(true);
});
it("slugifies the artifact name", () => {
@ -22,7 +22,9 @@ describe("artifactPlugin", () => {
"not-artifact-plugin",
"Sample artifact!"
);
expect(a.id).toEqual("sample-artifact-");
expect(a.id).toEqual(
"not-sourcecred/not-artifact-plugin/sample-artifact-"
);
});
it("resolves collisions", () => {
@ -42,9 +44,9 @@ describe("artifactPlugin", () => {
});
}
expect(ids).toEqual([
"sample-artifact-",
"sample-artifact--0",
"sample-artifact--1",
"not-sourcecred/not-artifact-plugin/sample-artifact-",
"not-sourcecred/not-artifact-plugin/sample-artifact--0",
"not-sourcecred/not-artifact-plugin/sample-artifact--1",
]);
});
});

View File

@ -32,7 +32,6 @@ function createTestData(): * {
id: string
): Address {
return {
repositoryName: "sourcecred/tests",
pluginName,
id,
type,

View File

@ -32,7 +32,7 @@ export class GithubGraphFetcher extends React.Component<Props> {
const {repoOwner, repoName, githubApiToken} = this.props.settings;
fetchGithubRepo(repoOwner, repoName, githubApiToken)
.then((json) => {
return Promise.resolve(parse(`${repoOwner}/${repoName}`, json));
return Promise.resolve(parse(json));
})
.then((graph) => {
this.props.onCreateGraph(graph);

View File

@ -75,7 +75,7 @@ exports[`ContributionList renders some test data in the default state 1`] = `
</thead>
<tbody>
<tr
key="{\\"repositoryName\\":\\"sourcecred/tests\\",\\"pluginName\\":\\"sourcecred/example-plugin-a\\",\\"id\\":\\"one\\",\\"type\\":\\"small\\"}"
key="{\\"pluginName\\":\\"sourcecred/example-plugin-a\\",\\"id\\":\\"one\\",\\"type\\":\\"small\\"}"
>
<td>
the number 111
@ -88,7 +88,7 @@ exports[`ContributionList renders some test data in the default state 1`] = `
</td>
</tr>
<tr
key="{\\"repositoryName\\":\\"sourcecred/tests\\",\\"pluginName\\":\\"sourcecred/example-plugin-a\\",\\"id\\":\\"two\\",\\"type\\":\\"small\\"}"
key="{\\"pluginName\\":\\"sourcecred/example-plugin-a\\",\\"id\\":\\"two\\",\\"type\\":\\"small\\"}"
>
<td>
the number 234
@ -101,7 +101,7 @@ exports[`ContributionList renders some test data in the default state 1`] = `
</td>
</tr>
<tr
key="{\\"repositoryName\\":\\"sourcecred/tests\\",\\"pluginName\\":\\"sourcecred/example-plugin-a\\",\\"id\\":\\"three\\",\\"type\\":\\"big\\"}"
key="{\\"pluginName\\":\\"sourcecred/example-plugin-a\\",\\"id\\":\\"three\\",\\"type\\":\\"big\\"}"
>
<td>
the number 616
@ -114,7 +114,7 @@ exports[`ContributionList renders some test data in the default state 1`] = `
</td>
</tr>
<tr
key="{\\"repositoryName\\":\\"sourcecred/tests\\",\\"pluginName\\":\\"sourcecred/example-plugin-b\\",\\"id\\":\\"four\\",\\"type\\":\\"very true\\"}"
key="{\\"pluginName\\":\\"sourcecred/example-plugin-b\\",\\"id\\":\\"four\\",\\"type\\":\\"very true\\"}"
>
<td>
TRUE!
@ -127,7 +127,7 @@ exports[`ContributionList renders some test data in the default state 1`] = `
</td>
</tr>
<tr
key="{\\"repositoryName\\":\\"sourcecred/tests\\",\\"pluginName\\":\\"sourcecred/example-plugin-c\\",\\"id\\":\\"five\\",\\"type\\":\\"ctype\\"}"
key="{\\"pluginName\\":\\"sourcecred/example-plugin-c\\",\\"id\\":\\"five\\",\\"type\\":\\"ctype\\"}"
>
<td
colSpan={3}
@ -220,7 +220,7 @@ exports[`ContributionList updates the node table when a filter is selected 1`] =
</thead>
<tbody>
<tr
key="{\\"repositoryName\\":\\"sourcecred/tests\\",\\"pluginName\\":\\"sourcecred/example-plugin-a\\",\\"id\\":\\"one\\",\\"type\\":\\"small\\"}"
key="{\\"pluginName\\":\\"sourcecred/example-plugin-a\\",\\"id\\":\\"one\\",\\"type\\":\\"small\\"}"
>
<td>
the number 111
@ -233,7 +233,7 @@ exports[`ContributionList updates the node table when a filter is selected 1`] =
</td>
</tr>
<tr
key="{\\"repositoryName\\":\\"sourcecred/tests\\",\\"pluginName\\":\\"sourcecred/example-plugin-a\\",\\"id\\":\\"two\\",\\"type\\":\\"small\\"}"
key="{\\"pluginName\\":\\"sourcecred/example-plugin-a\\",\\"id\\":\\"two\\",\\"type\\":\\"small\\"}"
>
<td>
the number 234

View File

@ -13,7 +13,7 @@ require("../testUtil").configureEnzyme();
describe("githubPluginAdapter", () => {
it("operates on the example repo", () => {
const graph = parse("sourcecred/example-repo", exampleRepoData);
const graph = parse(exampleRepoData);
const result = graph
.nodes()

File diff suppressed because it is too large Load Diff

View File

@ -37,16 +37,9 @@ import {
} from "./types";
class GitGraphCreator {
repositoryName: string;
constructor(repositoryName) {
this.repositoryName = repositoryName;
}
makeAddress(type: NodeType | EdgeType, id: string): Address {
return {
pluginName: GIT_PLUGIN_NAME,
repositoryName: this.repositoryName,
type,
id,
};
@ -215,8 +208,7 @@ class GitGraphCreator {
}
export function createGraph(
repository: Repository,
repositoryName: string
repository: Repository
): Graph<NodePayload, EdgePayload> {
return new GitGraphCreator(repositoryName).createGraph(repository);
return new GitGraphCreator().createGraph(repository);
}

View File

@ -21,11 +21,11 @@ const makeData = () => cloneDeep(require("./demoData/example-git"));
describe("createGraph", () => {
it("processes a simple repository", () => {
expect(createGraph(makeData(), "sourcecred/example-git")).toMatchSnapshot();
expect(createGraph(makeData())).toMatchSnapshot();
});
it("has no dangling edges", () => {
const graph = createGraph(makeData(), "sourcecred/example-git");
const graph = createGraph(makeData());
graph.edges().forEach((edge) => {
expect(graph.node(edge.src)).toEqual(expect.anything());
expect(graph.node(edge.dst)).toEqual(expect.anything());
@ -34,11 +34,10 @@ describe("createGraph", () => {
it("has all commits, each with correct edges", () => {
const data = makeData();
const graph = createGraph(data, "sourcecred/example-git");
const graph = createGraph(data);
Object.keys(data.commits).forEach((hash) => {
const address = {
pluginName: GIT_PLUGIN_NAME,
repositoryName: "sourcecred/example-git",
type: COMMIT_NODE_TYPE,
id: hash,
};
@ -64,11 +63,10 @@ describe("createGraph", () => {
it("has all trees, each with correct edges", () => {
const data = makeData();
const graph = createGraph(data, "sourcecred/example-git");
const graph = createGraph(data);
Object.keys(data.trees).forEach((hash) => {
const address = {
pluginName: GIT_PLUGIN_NAME,
repositoryName: "sourcecred/example-git",
type: TREE_NODE_TYPE,
id: hash,
};
@ -105,12 +103,11 @@ describe("createGraph", () => {
it("has all tree entries, each with correct edges", () => {
const data = makeData();
const graph = createGraph(data, "sourcecred/example-git");
const graph = createGraph(data);
Object.keys(data.trees).forEach((hash) => {
const tree = data.trees[hash];
const treeAddress = {
pluginName: GIT_PLUGIN_NAME,
repositoryName: "sourcecred/example-git",
type: TREE_NODE_TYPE,
id: hash,
};
@ -121,7 +118,6 @@ describe("createGraph", () => {
Object.keys(tree.entries).forEach((name) => {
const entryAddress = {
pluginName: GIT_PLUGIN_NAME,
repositoryName: "sourcecred/example-git",
type: TREE_ENTRY_NODE_TYPE,
id: treeEntryId(hash, name),
};
@ -192,11 +188,10 @@ describe("createGraph", () => {
test("HEAD^{tree}:src/quantum_gravity.py with correct contents", () => {
const data = makeData();
const graph = createGraph(data, "sourcecred/example-git");
const graph = createGraph(data);
const headCommitAddress = {
pluginName: GIT_PLUGIN_NAME,
repositoryName: "sourcecred/example-git",
type: COMMIT_NODE_TYPE,
id: headCommitHash,
};
@ -221,11 +216,10 @@ describe("createGraph", () => {
test("HEAD^{tree}:pygravitydefier with no contents", () => {
const data = makeData();
const graph = createGraph(data, "sourcecred/example-git");
const graph = createGraph(data);
const headCommitAddress = {
pluginName: GIT_PLUGIN_NAME,
repositoryName: "sourcecred/example-git",
type: COMMIT_NODE_TYPE,
id: headCommitHash,
};

View File

@ -7,7 +7,6 @@ Object {
"address": Object {
"id": "https://github.com/decentralion",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
"type": "AUTHOR",
},
"payload": Object {
@ -25,7 +24,6 @@ Object {
"address": Object {
"id": "https://github.com/sourcecred/example-repo/issues/6#issuecomment-373768442",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
"type": "COMMENT",
},
"payload": Object {
@ -40,7 +38,6 @@ Object {
"address": Object {
"id": "https://github.com/sourcecred/example-repo/issues/1",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
"type": "ISSUE",
},
"payload": Object {
@ -57,7 +54,6 @@ Object {
"address": Object {
"id": "https://github.com/sourcecred/example-repo/pull/3",
"pluginName": "sourcecred/github-beta",
"repositoryName": "sourcecred/example-repo",
"type": "PULL_REQUEST",
},
"payload": Object {

File diff suppressed because it is too large Load Diff

View File

@ -48,11 +48,9 @@ function assertEntityType(e: Entity, t: NodeType) {
}
export class Repository {
repositoryName: string;
graph: Graph<NodePayload, EdgePayload>;
constructor(repositoryName: string, graph: Graph<NodePayload, EdgePayload>) {
this.repositoryName = repositoryName;
constructor(graph: Graph<NodePayload, EdgePayload>) {
this.graph = graph;
}

View File

@ -12,8 +12,8 @@ import {
PULL_REQUEST_REVIEW_COMMENT_NODE_TYPE,
} from "./types";
describe("GitHub porcelain API", () => {
const graph = parse("sourcecred/example-repo", exampleRepoData);
const repo = new Repository("sourcecred/example-repo", graph);
const graph = parse(exampleRepoData);
const repo = new Repository(graph);
function issueOrPRByNumber(n: number): Issue | PullRequest {
const result = repo.issueOrPRByNumber(n);
if (result == null) {

View File

@ -34,28 +34,24 @@ import {Graph, edgeID} from "../../core/graph";
import {findReferences} from "./findReferences";
export function parse(
repositoryName: string,
repositoryJSON: RepositoryJSON
): Graph<NodePayload, EdgePayload> {
const parser = new GithubParser(repositoryName);
const parser = new GithubParser();
parser.addData(repositoryJSON);
parser.addReferenceEdges();
return parser.graph;
}
class GithubParser {
repositoryName: string;
graph: Graph<NodePayload, EdgePayload>;
constructor(repositoryName: string) {
this.repositoryName = repositoryName;
constructor() {
this.graph = new Graph();
}
makeNodeAddress(type: NodeType, url: string): Address {
return {
pluginName: PLUGIN_NAME,
repositoryName: this.repositoryName,
type,
id: url,
};
@ -64,7 +60,6 @@ class GithubParser {
makeEdgeAddress(type: EdgeType, src: Address, dst: Address): Address {
return {
pluginName: PLUGIN_NAME,
repositoryName: this.repositoryName,
type,
id: edgeID(src, dst),
};

View File

@ -26,7 +26,7 @@ describe("GithubParser", () => {
}
describe("whole repo parsing", () => {
const graph = parse("sourcecred/example-repo", exampleRepoData);
const graph = parse(exampleRepoData);
it("parses the entire example-repo as expected", () => {
expect(graph).toMatchSnapshot();
@ -114,7 +114,7 @@ describe("GithubParser", () => {
},
},
};
return parse("sourcecred/example-repo", exampleData);
return parse(exampleData);
}
describe("issue parsing", () => {