-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
127 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
noflo = require 'noflo' | ||
|
||
exports.getComponent = -> | ||
c = new noflo.Component | ||
c.inPorts.add 'in', | ||
datatype: 'object' | ||
c.outPorts.add 'existing', | ||
datatype: 'array' | ||
c.outPorts.add 'new', | ||
datatype: 'object' | ||
|
||
noflo.helpers.WirePattern c, | ||
out: ['existing', 'new'] | ||
async: true | ||
, (data, groups, out, callback) -> | ||
unless data.state?.projects?.length | ||
# No local projects, pass | ||
out.new.send data | ||
do callback | ||
return | ||
|
||
existing = data.state.projects.filter (project) -> | ||
project.gist is data.payload.graph | ||
unless existing.length | ||
out.new.send data | ||
do callback | ||
return | ||
|
||
out.existing.send [ | ||
'project' | ||
existing[0].id | ||
existing[0].main | ||
] | ||
do callback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
noflo = require 'noflo' | ||
octo = require 'octo' | ||
path = require 'path' | ||
|
||
exports.getComponent = -> | ||
c = new noflo.Component | ||
c.inPorts.add 'in', | ||
datatype: 'object' | ||
c.outPorts.add 'graph', | ||
datatype: 'object' | ||
c.outPorts.add 'component', | ||
datatype: 'object' | ||
c.outPorts.add 'project', | ||
datatype: 'object' | ||
c.outPorts.add 'error', | ||
datatype: 'object' | ||
|
||
noflo.helpers.WirePattern c, | ||
out: ['graph', 'component', 'project'] | ||
async: true | ||
, (data, groups, out, callback) -> | ||
api = octo.api() | ||
api.token data.state.user['github-token'] if data.state.user?['github-token'] | ||
|
||
project = | ||
id: data.payload.graph | ||
gist: data.payload.graph | ||
|
||
request = api.get "/gists/#{data.payload.graph}" | ||
request.on 'success', (res) -> | ||
for name, file of res.body.files | ||
basename = path.basename name, path.extname name | ||
if path.extname(name) is '.json' | ||
# JSON graph | ||
graph = JSON.parse file.content | ||
graph.properties = {} unless graph.properties | ||
graph.properties.project = project.id | ||
graph.properties.id = "#{project.id}_#{basename}" | ||
project.main = graph.properties.id unless project.main | ||
project.name = graph.properties.name unless project.name | ||
if graph.properties?.environment?.type | ||
project.type = graph.properties.environment.type unless project.type | ||
out.graph.send graph | ||
continue | ||
# Component | ||
component = | ||
name: basename | ||
language: file.language | ||
project: project.id | ||
code: file.content | ||
tests: '' | ||
out.component.send component | ||
continue | ||
out.project.send project | ||
do callback | ||
request.on 'error', (err) -> | ||
callback err.error or err.body | ||
do request |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
INPORT=Dispatch.IN:IN | ||
OUTPORT=Dispatch.PASS:PASS | ||
OUTPORT=NewActions.OUT:NEW | ||
|
||
'github:open,github:gist' -> ROUTES Dispatch(ui/DispatchAction) | ||
|
||
# New actions generated by this middleware | ||
'application:hash' -> ACTION ApplicationRedirectAction(ui/SetAction) | ||
ApplicationRedirectAction OUT -> IN NewActions(core/Merge) | ||
'project:save:graph' -> ACTION SaveGraphAction(ui/SetAction) | ||
SaveGraphAction OUT -> IN NewActions(core/Merge) | ||
'project:save:component' -> ACTION SaveComponentAction(ui/SetAction) | ||
SaveComponentAction OUT -> IN NewActions(core/Merge) | ||
'project:save:project' -> ACTION SaveProjectAction(ui/SetAction) | ||
SaveProjectAction OUT -> IN NewActions(core/Merge) | ||
'github:error' -> ACTION ErrorAction(ui/SetAction) | ||
ErrorAction OUT -> IN NewActions(core/Merge) | ||
|
||
# Downloading a GitHub project | ||
Dispatch HANDLE[0] -> IN Output(core/Output) | ||
|
||
# Downloading a gist example | ||
# First check if we already have a local version of the gist | ||
Dispatch HANDLE[1] -> IN CheckGist(ui/CheckGistExists) | ||
# If it already exists, redirect | ||
CheckGist EXISTING -> IN ApplicationRedirectAction | ||
# If not, download as new project | ||
CheckGist NEW -> IN GetGist(ui/GistToProject) | ||
GetGist GRAPH -> IN LoadGraph(graph/LoadJson) OUT -> IN SaveGraphAction | ||
GetGist COMPONENT -> IN SaveComponentAction | ||
GetGist PROJECT -> IN SaveProjectAction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters