Expose `commitAddress` from the Git plugin (#199)
For the GitHub plugin to create edges pointing to commits from the Git plugin, it needs a way to create the appropriate address given the commit's hash. This commit exposes that functionality by moving `makeAddress` out of the "createGraph" module and into a new "address" module, and using it to implement `commitAddress`. Test plan: The code is so trivial that I don't think it merits testing.
This commit is contained in:
parent
136cfa839c
commit
9cbfa35a3a
|
@ -0,0 +1,17 @@
|
||||||
|
// @flow
|
||||||
|
|
||||||
|
import type {Address} from "../../core/address";
|
||||||
|
import type {EdgeType, NodeType} from "./types";
|
||||||
|
import {COMMIT_NODE_TYPE, GIT_PLUGIN_NAME} from "./types";
|
||||||
|
|
||||||
|
export function _makeAddress(type: NodeType | EdgeType, id: string): Address {
|
||||||
|
return {
|
||||||
|
pluginName: GIT_PLUGIN_NAME,
|
||||||
|
type,
|
||||||
|
id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function commitAddress(hash: string): Address {
|
||||||
|
return _makeAddress(COMMIT_NODE_TYPE, hash);
|
||||||
|
}
|
|
@ -1,17 +1,14 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import type {Address} from "../../core/address";
|
|
||||||
import type {Edge, Node} from "../../core/graph";
|
import type {Edge, Node} from "../../core/graph";
|
||||||
import type {
|
import type {
|
||||||
BlobNodePayload,
|
BlobNodePayload,
|
||||||
Commit,
|
Commit,
|
||||||
EdgePayload,
|
EdgePayload,
|
||||||
EdgeType,
|
|
||||||
HasContentsEdgePayload,
|
HasContentsEdgePayload,
|
||||||
Hash,
|
Hash,
|
||||||
IncludesEdgePayload,
|
IncludesEdgePayload,
|
||||||
NodePayload,
|
NodePayload,
|
||||||
NodeType,
|
|
||||||
Repository,
|
Repository,
|
||||||
SubmoduleCommitPayload,
|
SubmoduleCommitPayload,
|
||||||
Tree,
|
Tree,
|
||||||
|
@ -22,7 +19,6 @@ import {Graph, edgeID} from "../../core/graph";
|
||||||
import {
|
import {
|
||||||
BLOB_NODE_TYPE,
|
BLOB_NODE_TYPE,
|
||||||
COMMIT_NODE_TYPE,
|
COMMIT_NODE_TYPE,
|
||||||
GIT_PLUGIN_NAME,
|
|
||||||
HAS_CONTENTS_EDGE_TYPE,
|
HAS_CONTENTS_EDGE_TYPE,
|
||||||
HAS_PARENT_EDGE_TYPE,
|
HAS_PARENT_EDGE_TYPE,
|
||||||
HAS_TREE_EDGE_TYPE,
|
HAS_TREE_EDGE_TYPE,
|
||||||
|
@ -35,16 +31,9 @@ import {
|
||||||
submoduleCommitId,
|
submoduleCommitId,
|
||||||
treeEntryId,
|
treeEntryId,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
import {_makeAddress} from "./address";
|
||||||
|
|
||||||
class GitGraphCreator {
|
class GitGraphCreator {
|
||||||
makeAddress(type: NodeType | EdgeType, id: string): Address {
|
|
||||||
return {
|
|
||||||
pluginName: GIT_PLUGIN_NAME,
|
|
||||||
type,
|
|
||||||
id,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
createGraph(repository: Repository): Graph<NodePayload, EdgePayload> {
|
createGraph(repository: Repository): Graph<NodePayload, EdgePayload> {
|
||||||
const treeAndNameToSubmoduleUrls = this.treeAndNameToSubmoduleUrls(
|
const treeAndNameToSubmoduleUrls = this.treeAndNameToSubmoduleUrls(
|
||||||
repository
|
repository
|
||||||
|
@ -94,15 +83,15 @@ class GitGraphCreator {
|
||||||
|
|
||||||
commitGraph(commit: Commit) {
|
commitGraph(commit: Commit) {
|
||||||
const commitNode = {
|
const commitNode = {
|
||||||
address: this.makeAddress(COMMIT_NODE_TYPE, commit.hash),
|
address: _makeAddress(COMMIT_NODE_TYPE, commit.hash),
|
||||||
payload: {},
|
payload: {},
|
||||||
};
|
};
|
||||||
const treeNode = {
|
const treeNode = {
|
||||||
address: this.makeAddress(TREE_NODE_TYPE, commit.treeHash),
|
address: _makeAddress(TREE_NODE_TYPE, commit.treeHash),
|
||||||
payload: {},
|
payload: {},
|
||||||
};
|
};
|
||||||
const hasTreeEdge = {
|
const hasTreeEdge = {
|
||||||
address: this.makeAddress(
|
address: _makeAddress(
|
||||||
HAS_TREE_EDGE_TYPE,
|
HAS_TREE_EDGE_TYPE,
|
||||||
edgeID(commitNode.address, treeNode.address)
|
edgeID(commitNode.address, treeNode.address)
|
||||||
),
|
),
|
||||||
|
@ -116,9 +105,9 @@ class GitGraphCreator {
|
||||||
.addEdge(hasTreeEdge);
|
.addEdge(hasTreeEdge);
|
||||||
commit.parentHashes.forEach((parentHash, index) => {
|
commit.parentHashes.forEach((parentHash, index) => {
|
||||||
const oneBasedParentIndex = index + 1;
|
const oneBasedParentIndex = index + 1;
|
||||||
const parentAddress = this.makeAddress(COMMIT_NODE_TYPE, parentHash);
|
const parentAddress = _makeAddress(COMMIT_NODE_TYPE, parentHash);
|
||||||
const parentEdge = {
|
const parentEdge = {
|
||||||
address: this.makeAddress(
|
address: _makeAddress(
|
||||||
HAS_PARENT_EDGE_TYPE,
|
HAS_PARENT_EDGE_TYPE,
|
||||||
hasParentEdgeId(commit.hash, oneBasedParentIndex)
|
hasParentEdgeId(commit.hash, oneBasedParentIndex)
|
||||||
),
|
),
|
||||||
|
@ -135,21 +124,21 @@ class GitGraphCreator {
|
||||||
|
|
||||||
treeGraph(tree: Tree, treeAndNameToSubmoduleUrls) {
|
treeGraph(tree: Tree, treeAndNameToSubmoduleUrls) {
|
||||||
const treeNode = {
|
const treeNode = {
|
||||||
address: this.makeAddress(TREE_NODE_TYPE, tree.hash),
|
address: _makeAddress(TREE_NODE_TYPE, tree.hash),
|
||||||
payload: {},
|
payload: {},
|
||||||
};
|
};
|
||||||
const result = new Graph().addNode(treeNode);
|
const result = new Graph().addNode(treeNode);
|
||||||
Object.keys(tree.entries).forEach((name) => {
|
Object.keys(tree.entries).forEach((name) => {
|
||||||
const entry = tree.entries[name];
|
const entry = tree.entries[name];
|
||||||
const entryNode: Node<TreeEntryNodePayload> = {
|
const entryNode: Node<TreeEntryNodePayload> = {
|
||||||
address: this.makeAddress(
|
address: _makeAddress(
|
||||||
TREE_ENTRY_NODE_TYPE,
|
TREE_ENTRY_NODE_TYPE,
|
||||||
treeEntryId(tree.hash, entry.name)
|
treeEntryId(tree.hash, entry.name)
|
||||||
),
|
),
|
||||||
payload: {name},
|
payload: {name},
|
||||||
};
|
};
|
||||||
const entryEdge: Edge<IncludesEdgePayload> = {
|
const entryEdge: Edge<IncludesEdgePayload> = {
|
||||||
address: this.makeAddress(
|
address: _makeAddress(
|
||||||
INCLUDES_EDGE_TYPE,
|
INCLUDES_EDGE_TYPE,
|
||||||
includesEdgeId(tree.hash, entry.name)
|
includesEdgeId(tree.hash, entry.name)
|
||||||
),
|
),
|
||||||
|
@ -171,7 +160,7 @@ class GitGraphCreator {
|
||||||
throw new Error(`Unknown entry type: ${entry.type}`);
|
throw new Error(`Unknown entry type: ${entry.type}`);
|
||||||
}
|
}
|
||||||
const contentsNode: Node<TreeNodePayload> | Node<BlobNodePayload> = {
|
const contentsNode: Node<TreeNodePayload> | Node<BlobNodePayload> = {
|
||||||
address: this.makeAddress(contentsNodeType, entry.hash),
|
address: _makeAddress(contentsNodeType, entry.hash),
|
||||||
payload: (({}: any): {||}),
|
payload: (({}: any): {||}),
|
||||||
};
|
};
|
||||||
return [contentsNode];
|
return [contentsNode];
|
||||||
|
@ -179,7 +168,7 @@ class GitGraphCreator {
|
||||||
// One entry for each possible URL.
|
// One entry for each possible URL.
|
||||||
const urls = treeAndNameToSubmoduleUrls[tree.hash][name];
|
const urls = treeAndNameToSubmoduleUrls[tree.hash][name];
|
||||||
return urls.map((url): Node<SubmoduleCommitPayload> => ({
|
return urls.map((url): Node<SubmoduleCommitPayload> => ({
|
||||||
address: this.makeAddress(
|
address: _makeAddress(
|
||||||
SUBMODULE_COMMIT_NODE_TYPE,
|
SUBMODULE_COMMIT_NODE_TYPE,
|
||||||
submoduleCommitId(entry.hash, url)
|
submoduleCommitId(entry.hash, url)
|
||||||
),
|
),
|
||||||
|
@ -192,7 +181,7 @@ class GitGraphCreator {
|
||||||
})();
|
})();
|
||||||
contentsNodes.forEach((contentsNode) => {
|
contentsNodes.forEach((contentsNode) => {
|
||||||
const contentsEdge: Edge<HasContentsEdgePayload> = {
|
const contentsEdge: Edge<HasContentsEdgePayload> = {
|
||||||
address: this.makeAddress(
|
address: _makeAddress(
|
||||||
HAS_CONTENTS_EDGE_TYPE,
|
HAS_CONTENTS_EDGE_TYPE,
|
||||||
edgeID(entryNode.address, contentsNode.address)
|
edgeID(entryNode.address, contentsNode.address)
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue