Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ module.exports = ->

# Browser build of NoFlo
noflo_browser:
options:
webpack:
module:
loaders: [
{ test: /\.coffee$/, loader: "coffee-loader" }
{ test: /\.json$/, loader: "json-loader" }
{ test: /\.fbp$/, loader: "fbp-loader" }
]
resolve:
extensions: [".coffee", ".js"]
node:
net: 'empty'
tls: 'empty'
fs: 'empty'
target: 'web'
ignores: [
/bin\/coffee/
/tv4/
]
build:
files:
'browser/noflo-github.js': ['component.json']
Expand Down
23 changes: 14 additions & 9 deletions components/CreateBlob.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
noflo = require 'noflo'
octo = require 'octo'
github = require 'github'

exports.getComponent = ->
c = new noflo.Component
Expand All @@ -26,15 +26,20 @@ exports.getComponent = ->
async: true
forwardGroups: true
, (data, groups, out, callback) ->
api = octo.api()
api.token c.params.token if c.params.token
api = new github
unless c.params.token
return callback new Error 'token required'
api.authenticate
type: 'token'
token: c.params.token

req = api.post "/repos/#{data.repository}/git/blobs",
[org, repoName] = data.repository.split '/'
api.gitdata.createBlob
owner: org
repo: repoName
content: data.content
encoding: 'utf-8'
req.on 'success', (res) ->
out.send res.body.sha
, (err, res) ->
return callback err if err
out.send res.sha
do callback
req.on 'error', (err) ->
callback err.error or err.body
do req
23 changes: 14 additions & 9 deletions components/CreateCommit.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
noflo = require 'noflo'
octo = require 'octo'
github = require 'github'

exports.getComponent = ->
c = new noflo.Component
Expand Down Expand Up @@ -32,16 +32,21 @@ exports.getComponent = ->
async: true
forwardGroups: true
, (data, groups, out, callback) ->
api = octo.api()
api.token c.params.token if c.params.token
api = new github
unless c.params.token
return callback new Error 'token required'
api.authenticate
type: 'token'
token: c.params.token

req = api.post "/repos/#{data.repository}/git/commits",
[org, repoName] = data.repository.split '/'
api.gitdata.createCommit
owner: org
repo: repoName
message: data.message
tree: data.tree
parents: data.parents or []
req.on 'success', (res) ->
out.send res.body.sha
, (err, res) ->
return callback err if err
out.send res.sha
do callback
req.on 'error', (err) ->
callback err.error or err.body
do req
20 changes: 10 additions & 10 deletions components/CreateOrgRepository.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
noflo = require 'noflo'
octo = require 'octo'
github = require 'github'

exports.getComponent = ->
c = new noflo.Component
Expand All @@ -26,19 +26,19 @@ exports.getComponent = ->
async: true
forwardGroups: true
, (data, groups, out, callback) ->
api = octo.api()
api = new github
unless c.params.token
return callback new Error 'token required'
api.token c.params.token
api.authenticate
type: 'token'
token: c.params.token

request = api.post "/orgs/#{data.org}/repos",
api.repos.createForOrg
org: data.org
name: data.in

request.on 'success', (res) ->
, (err, res) ->
return callback err if err
out.beginGroup data.in
out.send res.body
out.endGroup()
callback()
request.on 'error', (err) ->
callback err.error or err.body
do request
do callback
67 changes: 38 additions & 29 deletions components/CreateOrphanBranch.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
noflo = require 'noflo'
octo = require 'octo'
github = require 'github'

exports.getComponent = ->
c = new noflo.Component
Expand All @@ -21,7 +21,7 @@ exports.getComponent = ->
c.outPorts.add 'error',
datatype: 'object'

c.getOcto = -> octo
c.getApi = -> new github

noflo.helpers.WirePattern c,
in: ['branch', 'repository']
Expand All @@ -30,45 +30,54 @@ exports.getComponent = ->
async: true
forwardGroups: true
, (data, groups, out, callback) ->
api = octo.api()
api.token c.params.token if c.params.token
api = new github
unless c.params.token
return callback new Error 'token required'
api.authenticate
type: 'token'
token: c.params.token

[org, repoName] = data.repository.split '/'
# First check if the branch already exists
branchReq = api.get "/repos/#{data.repository}/branches/#{data.branch}"
branchReq.on 'success', (branchRes) ->
out.send data.branch
callback()
branchReq.on 'error', ->
api.repos.getBranch
owner: org
repo: repoName
branch: data.branch
, (err) ->
unless err
out.send data.branch
do callback
return
# Missing branch, we need to create an empty commit, and then a reference to it
treeReq = api.post "/repos/#{data.repository}/git/trees",
api.gitdata.createTree
owner: org
repo: repoName
tree: [
path: 'README.md'
content: data.branch
mode: '100644'
type: 'blob'
]
treeReq.on 'success', (treeRes) ->
return callback new Error 'No SHA' unless treeRes.body.sha
, (err, tree) ->
return callback err if err
return callback new Error 'No SHA' unless tree.sha

commitReq = api.post "/repos/#{data.repository}/git/commits",
api.gitdata.createCommit
owner: org
repo: repoName
message: 'Initial'
tree: treeRes.body.sha
tree: tree.sha
parents: []
commitReq.on 'success', (commitRes) ->
refReq = api.post "/repos/#{data.repository}/git/refs",
, (err, commit) ->
return callback err if err
return callback new Error 'No commit SHA' unless commit.sha

api.gitdata.createReference
owner: org
repo: repoName
ref: "refs/heads/#{data.branch}"
sha: commitRes.body.sha
refReq.on 'success', (refRes) ->
sha: commit.sha
, (err) ->
return callback err if err
out.send data.branch
callback()
refReq.on 'error', (error) ->
callback error.error or error.body
do refReq

commitReq.on 'error', (error) ->
callback error.error or error.body
do commitReq
treeReq.on 'error', (error) ->
callback error.error or error.body
do treeReq
do branchReq
20 changes: 10 additions & 10 deletions components/CreateRepository.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
noflo = require 'noflo'
octo = require 'octo'
github = require 'github'

exports.getComponent = ->
c = new noflo.Component
Expand All @@ -10,6 +10,7 @@ exports.getComponent = ->
c.inPorts.add 'token',
datatype: 'string'
description: 'GitHub API token'
required: true
c.outPorts.add 'out',
datatype: 'object'
c.outPorts.add 'error',
Expand All @@ -23,19 +24,18 @@ exports.getComponent = ->
async: true
forwardGroups: true
, (data, groups, out, callback) ->
api = octo.api()
api = new github
unless c.params.token
return callback new Error 'token required'
api.token c.params.token
api.authenticate
type: 'token'
token: c.params.token

request = api.post '/user/repos',
api.repos.create
name: data

request.on 'success', (res) ->
, (err, res) ->
return callback err if err
out.beginGroup data
out.send res.body
out.send res
out.endGroup()
callback()
request.on 'error', (err) ->
callback err.error or err.body
do request
23 changes: 14 additions & 9 deletions components/CreateTree.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
noflo = require 'noflo'
octo = require 'octo'
github = require 'github'

exports.getComponent = ->
c = new noflo.Component
Expand Down Expand Up @@ -29,15 +29,20 @@ exports.getComponent = ->
async: true
forwardGroups: true
, (data, groups, out, callback) ->
api = octo.api()
api.token c.params.token if c.params.token
api = new github
unless c.params.token
return callback new Error 'token required'
api.authenticate
type: 'token'
token: c.params.token

req = api.post "/repos/#{data.repository}/git/trees",
[org, repoName] = data.repository.split '/'
api.gitdata.createTree
owner: org
repo: repoName
tree: data.tree
base_tree: c.params.base
req.on 'success', (res) ->
out.send res.body
, (err, res) ->
return callback err if err
out.send res
do callback
req.on 'error', (err) ->
callback err.error or err.body
do req
25 changes: 15 additions & 10 deletions components/GetBlob.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
noflo = require 'noflo'
octo = require 'octo'
github = require 'github'

exports.getComponent = ->
c = new noflo.Component
Expand Down Expand Up @@ -28,19 +28,24 @@ exports.getComponent = ->
async: true
forwardGroups: true
, (data, groups, out, callback) ->
api = octo.api()
api.token c.params.token if c.params.token
api = new github
unless c.params.token
return callback new Error 'token required'
api.authenticate
type: 'token'
token: c.params.token

request = api.get "/repos/#{data.repository}/git/blobs/#{data.sha}"
request.on 'success', (res) ->
unless res.body
return callback new Error 'no result available'
[org, repoName] = data.repository.split '/'
api.gitdata.getBlob
owner: org
repo: repoName
sha: data.sha
, (err, res) ->
return callback err if err
return callback new Error 'no result available' unless res
out.beginGroup data.repository
out.beginGroup data.sha
out.send res.body
out.endGroup()
out.endGroup()
do callback
request.on 'error', (err) ->
callback err.error or err.body
do request
Loading