-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create External Plugin that reads from disk or url #3114
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`analysis/pluginDeclaration to/fromJSON snapshots on an empty declaration 1`] = `"[{\\"type\\":\\"sourcecred/pluginDeclarations\\",\\"version\\":\\"0.1.0\\"},[{\\"edgePrefix\\":\\"E\\\\u0000\\",\\"edgeTypes\\":[],\\"name\\":\\"empty\\",\\"nodePrefix\\":\\"N\\\\u0000\\",\\"nodeTypes\\":[],\\"userTypes\\":[]}]]"`; | ||
exports[`analysis/pluginDeclaration to/fromJSON snapshots on an empty declaration 1`] = `"[[{\\"type\\":\\"sourcecred/pluginDeclarations\\",\\"version\\":\\"0.1.0\\"},{\\"edgePrefix\\":\\"E\\\\u0000\\",\\"edgeTypes\\":[],\\"name\\":\\"empty\\",\\"nodePrefix\\":\\"N\\\\u0000\\",\\"nodeTypes\\":[],\\"userTypes\\":[]}]]"`; | ||
|
||
exports[`analysis/pluginDeclaration to/fromJSON snapshots on an non-empty declaration 1`] = `"[{\\"type\\":\\"sourcecred/pluginDeclarations\\",\\"version\\":\\"0.1.0\\"},[{\\"edgePrefix\\":\\"E\\\\u0000\\",\\"edgeTypes\\":[{\\"backwardName\\":\\"is pointed to\\",\\"defaultWeight\\":{\\"backwards\\":3,\\"forwards\\":2},\\"description\\":\\"a type\\",\\"forwardName\\":\\"points\\",\\"prefix\\":\\"E\\\\u0000edge\\\\u0000\\"}],\\"name\\":\\"non-empty\\",\\"nodePrefix\\":\\"N\\\\u0000\\",\\"nodeTypes\\":[{\\"defaultWeight\\":2,\\"description\\":\\"a type\\",\\"name\\":\\"node\\",\\"pluralName\\":\\"nodes\\",\\"prefix\\":\\"N\\\\u0000node\\\\u0000\\"}],\\"userTypes\\":[]}]]"`; | ||
exports[`analysis/pluginDeclaration to/fromJSON snapshots on an non-empty declaration 1`] = `"[[{\\"type\\":\\"sourcecred/pluginDeclarations\\",\\"version\\":\\"0.1.0\\"},{\\"edgePrefix\\":\\"E\\\\u0000\\",\\"edgeTypes\\":[{\\"backwardName\\":\\"is pointed to\\",\\"defaultWeight\\":{\\"backwards\\":3,\\"forwards\\":2},\\"description\\":\\"a type\\",\\"forwardName\\":\\"points\\",\\"prefix\\":\\"E\\\\u0000edge\\\\u0000\\"}],\\"name\\":\\"non-empty\\",\\"nodePrefix\\":\\"N\\\\u0000\\",\\"nodeTypes\\":[{\\"defaultWeight\\":2,\\"description\\":\\"a type\\",\\"name\\":\\"node\\",\\"pluralName\\":\\"nodes\\",\\"prefix\\":\\"N\\\\u0000node\\\\u0000\\"}],\\"userTypes\\":[]}]]"`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,36 @@ | ||
// @flow | ||
|
||
import type {Plugin} from "./plugin"; | ||
import {type PluginId, getPluginOwner} from "./pluginId"; | ||
import {GithubPlugin} from "../plugins/github/plugin"; | ||
import {DiscoursePlugin} from "../plugins/discourse/plugin"; | ||
import {DiscordPlugin} from "../plugins/discord/plugin"; | ||
import {InitiativesPlugin} from "../plugins/initiatives/plugin"; | ||
import {EthereumPlugin} from "../plugins/ethereum/plugin"; | ||
import { | ||
ExternalPlugin, | ||
ExternalPluginIdOwner, | ||
} from "../plugins/external/plugin"; | ||
import {DiskStorage} from "../core/storage/disk"; | ||
|
||
/** | ||
* Returns an object mapping owner-name pairs to CLI plugin | ||
* declarations; keys are like `sourcecred/github`. | ||
*/ | ||
// TODO(@decentralion): Fix the type signature here. | ||
export function bundledPlugins(): {[pluginId: string]: Plugin} { | ||
return { | ||
export function getPlugin(pluginId: PluginId): ?Plugin { | ||
const mapping = { | ||
"sourcecred/github": new GithubPlugin(), | ||
"sourcecred/discourse": new DiscoursePlugin(), | ||
"sourcecred/discord": new DiscordPlugin(), | ||
"sourcecred/initiatives": new InitiativesPlugin(), | ||
"sourcecred/ethereum": new EthereumPlugin(), | ||
}; | ||
if (mapping[pluginId.toString()]) return mapping[pluginId.toString()]; | ||
if (getPluginOwner(pluginId) === ExternalPluginIdOwner) | ||
return new ExternalPlugin({ | ||
pluginId, | ||
storage: new DiskStorage(process.cwd()), | ||
}); | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just curious: why not an implicit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will change, probably just a years-old habit from the 1 year in college I spent writing java lol. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// @flow | ||
|
||
import deepFreeze from "deep-freeze"; | ||
import type {PluginDeclaration} from "../../analysis/pluginDeclaration"; | ||
import {type PluginId, getPluginName, getPluginOwner} from "../../api/pluginId"; | ||
import {NodeAddress, EdgeAddress, type NodeAddressT} from "../../core/graph"; | ||
|
||
export function contributionNodeType( | ||
id: PluginId | ||
): {| | ||
+defaultWeight: number, | ||
+description: string, | ||
+name: string, | ||
+pluralName: string, | ||
+prefix: NodeAddressT, | ||
|} { | ||
return deepFreeze({ | ||
name: "Contribution", | ||
pluralName: "Contributions", | ||
prefix: NodeAddress.fromParts([ | ||
getPluginOwner(id), | ||
getPluginName(id), | ||
"CONTRIBUTION", | ||
]), | ||
defaultWeight: 1, | ||
description: "NodeType for a generic contribution", | ||
}); | ||
} | ||
|
||
export function participantNodeType( | ||
id: PluginId | ||
): {| | ||
+defaultWeight: number, | ||
+description: string, | ||
+name: string, | ||
+pluralName: string, | ||
+prefix: NodeAddressT, | ||
|} { | ||
return deepFreeze({ | ||
name: "Participant", | ||
pluralName: "Participant", | ||
prefix: NodeAddress.fromParts([ | ||
getPluginOwner(id), | ||
getPluginName(id), | ||
"PARTICIPANT", | ||
]), | ||
defaultWeight: 1, | ||
description: "NodeType for a generic participant", | ||
}); | ||
} | ||
|
||
function participatedInEdgeType(id: PluginId) { | ||
return deepFreeze({ | ||
forwardName: "participated in", | ||
backwardName: "had participation from", | ||
defaultWeight: {forwards: 1 / 2, backwards: 1}, | ||
prefix: EdgeAddress.fromParts([ | ||
getPluginOwner(id), | ||
getPluginName(id), | ||
"PARTICIPATES_IN", | ||
]), | ||
description: "NodeType for a generic participant-contribution relationship", | ||
}); | ||
} | ||
|
||
export function declaration(id: PluginId): PluginDeclaration { | ||
return deepFreeze({ | ||
name: getPluginName(id), | ||
nodePrefix: NodeAddress.fromParts([getPluginOwner(id), getPluginName(id)]), | ||
edgePrefix: EdgeAddress.fromParts([getPluginOwner(id), getPluginName(id)]), | ||
nodeTypes: [participantNodeType(id), contributionNodeType(id)], | ||
edgeTypes: [participatedInEdgeType(id)], | ||
userTypes: [participantNodeType(id)], | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate this refactoring