-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e0d5d41
Showing
22 changed files
with
3,495 additions
and
0 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,5 @@ | ||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
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,4 @@ | ||
.DS_Store | ||
.idea/ | ||
node_modules/ | ||
npm-debug.log |
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,19 @@ | ||
{ | ||
"curly" : true, | ||
"eqeqeq" : true, | ||
"immed" : true, | ||
"latedef" : true, | ||
"newcap" : true, | ||
"noarg" : true, | ||
"sub" : true, | ||
"undef" : true, | ||
"boss" : true, | ||
"eqnull" : true, | ||
"node" : true, | ||
"quotmark" : "single", | ||
"unused" : true, | ||
"trailing" : true, | ||
"maxparams" : 4, | ||
"maxdepth" : 4, | ||
"predef" : [ "-Promise" ] | ||
} |
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,6 @@ | ||
language: node_js | ||
node_js: | ||
- "0.10" | ||
|
||
before_script: | ||
- npm install -g grunt-cli |
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,35 @@ | ||
module.exports = function ( grunt ) { | ||
'use strict'; | ||
|
||
grunt.initConfig( { | ||
pkg : grunt.file.readJSON( 'package.json' ), | ||
|
||
jshint : { | ||
/* https://github.com/gruntjs/grunt-contrib-jshint */ | ||
all : [ | ||
'Gruntfile.js', | ||
'porcupine.js', | ||
'routes/**/*.js', | ||
'models/**/*.js', | ||
'examples/**/*.js', | ||
'tests/**/*.js', | ||
], | ||
options : { | ||
jshintrc : '.jshintrc', | ||
}, | ||
}, | ||
|
||
nodeunit : { | ||
/* https://github.com/gruntjs/grunt-contrib-nodeunit */ | ||
tests : [ 'tests/**/*Test.js' ], | ||
options : { | ||
reporter : 'verbose', | ||
}, | ||
}, | ||
} ); | ||
|
||
grunt.loadNpmTasks( 'grunt-contrib-jshint' ); | ||
grunt.loadNpmTasks( 'grunt-contrib-nodeunit' ); | ||
|
||
grunt.registerTask( 'test', ['jshint', 'nodeunit'] ); | ||
}; |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Natue <http://www.natue.com.br> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,246 @@ | ||
# Porcupine | ||
|
||
> A NodeJS package to integrate development tools. | ||
# Getting Started | ||
|
||
Porcupine will help you to integrate development tools using NodeJS in an easy and fast way. Porcupine is currently supporting: | ||
|
||
## Github | ||
|
||
- Hooks | ||
- Issue created | ||
- Issue comment created | ||
- Repository push | ||
- Release published | ||
- Calls | ||
- Create issue | ||
- Update issue | ||
- Create issue comment | ||
|
||
## Trello | ||
|
||
- Hooks | ||
- Card created | ||
- Card updated | ||
- Card comment created | ||
- Card attachment created | ||
- Calls | ||
- Update card | ||
|
||
## Jenkins | ||
|
||
- Calls | ||
- Build job | ||
|
||
|
||
# How to use it | ||
|
||
The interaction with Porcupine will happen all via events, both to receive hooks or to make calls. All events with params and returns are listed on [models/events.js](https://github.com/natuelabs/porcupine/blob/master/models/events.js). | ||
|
||
To use it, just require Porcupine, init the configs, port to run and play with the events: | ||
|
||
```js | ||
var porcupine = require( 'porcupine' ); | ||
var eventEmitter = porcupine.getEventEmitter(); | ||
var events = porcupine.getEvents(); | ||
|
||
var config = { | ||
github : { | ||
oauthToken : 'your_token' | ||
}, | ||
trello : { | ||
key : 'your_key', | ||
token : 'your_token' | ||
} | ||
}; | ||
|
||
// By default Backhole will run over the port 3000 | ||
porcupine.init( config, 3000 ); | ||
|
||
function handleTrelloCardCreated ( data ) { | ||
// Create issue on GitHub | ||
eventEmitter.emit( | ||
events.github.issue.create, | ||
{ | ||
owner : 'your_repo_owner', | ||
repo : 'your_repo_name', | ||
title : data.title | ||
}, | ||
function ( err, response ) { | ||
if ( err ) { | ||
console.log( response ); | ||
} | ||
} | ||
); | ||
} | ||
|
||
// Card created on Trello | ||
eventEmitter.on( | ||
events.trello.card.created, | ||
handleTrelloCardCreated | ||
); | ||
``` | ||
|
||
# Config | ||
|
||
To use Porcupine the first action is to send the config object and optionally the port to run (if not sent, Porcupine will listen to the port 3000): | ||
|
||
```js | ||
porcupine.init( config, 3000 ); | ||
``` | ||
|
||
The configs will also enable each one of the integrations so, if not setted, the integration is not enabled: | ||
|
||
## GitHub | ||
|
||
```js | ||
var config = { | ||
github : { | ||
oauthToken : 'your_token' | ||
} | ||
}; | ||
``` | ||
|
||
## Trello | ||
|
||
```js | ||
var config = { | ||
trello : { | ||
key : 'your_key', | ||
token : 'your_token' | ||
} | ||
}; | ||
``` | ||
|
||
## Jenkins | ||
|
||
```js | ||
var config = { | ||
jenkins : { | ||
baseUrl : 'http://your_jenkins_url.com', | ||
user : 'jenkins_user', | ||
pass : 'jenkins_pass' | ||
} | ||
}; | ||
``` | ||
|
||
# Hooks | ||
|
||
To use hooks you have to create them for Trello and GitHub. The easiest way is to create a dedicated user at those services and create the hooks with this user. A helpful tool to make the API calls is [DHCS](https://www.sprintapi.com/dhcs.html). To receive the hooks your installation have to be avaiable in the internet, an easy way to develop locally is by using [Ngrok](https://ngrok.com/). | ||
|
||
## GitHub hooks | ||
|
||
You can find more information about GitHub hooks [here](http://developer.github.com/v3/repos/hooks/). | ||
|
||
- [Create a token](https://github.com/settings/applications) | ||
- [Create a hook](http://developer.github.com/v3/repos/hooks/#create-a-hook): | ||
|
||
``` | ||
Method: POST | ||
URL: https://api.github.com/repos/:owner:/:repo:/hooks | ||
Header: "Authorization: token :token:" | ||
``` | ||
|
||
Body: | ||
|
||
```json | ||
{ | ||
"name": "web", | ||
"active": true, | ||
"events": [ | ||
"push", | ||
"issues", | ||
"issue_comment", | ||
"commit_comment", | ||
"pull_request", | ||
"pull_request_review_comment", | ||
"release" | ||
], | ||
"config": { | ||
"url": "https://:your_installation_url:/github", | ||
"content_type": "json", | ||
"insecure_ssl": "1" | ||
} | ||
} | ||
``` | ||
|
||
### List hooks | ||
|
||
``` | ||
Method: GET | ||
URL: https://api.github.com/repos/:owner:/:repo:/hooks | ||
Header: "Authorization: token :token:" | ||
``` | ||
|
||
### Delete hook | ||
|
||
``` | ||
Method: DELETE | ||
URL: https://api.github.com/repos/:owner:/:repo:/hooks/:hook_id: | ||
Header: "Authorization: token :token:" | ||
``` | ||
|
||
### Observations | ||
|
||
- Accepts self-signed certificates if you send the "insecure_ssl" config; | ||
- It's possible to use a different port than 443 for HTTPS on hooks; | ||
|
||
## Trello hooks | ||
|
||
You can find more information about Trello hooks [here](https://trello.com/docs/gettingstarted/webhooks.html). | ||
|
||
- [Generate your key](https://trello.com/1/appKey/generate) | ||
- [Generate your token](https://trello.com/docs/gettingstarted/authorize.html): | ||
|
||
``` | ||
Method: GET | ||
URL: https://trello.com/1/connect?key=:key:&name=Porcupine&response_type=token&scope=read,write&expiration=never | ||
``` | ||
|
||
- Get the board ID. The hash in the URL of the board is the short ID: | ||
|
||
``` | ||
Method: GET | ||
URL: https://trello.com/1/board/:short_id: | ||
``` | ||
|
||
- [Create a hook](https://trello.com/docs/gettingstarted/webhooks.html#creating-a-webhook): | ||
|
||
``` | ||
Method: POST | ||
URL: https://trello.com/1/tokens/:token:/webhooks/?key=:key: | ||
``` | ||
|
||
Body: | ||
|
||
```json | ||
{ | ||
"description": "Porcupine", | ||
"callbackURL": "https://:your_installation_url:/trello", | ||
"idModel": ":model_id:" | ||
} | ||
``` | ||
|
||
### List hooks | ||
|
||
``` | ||
Method: GET | ||
URL: https://trello.com/1/tokens/:token:/webhooks/?key=:key: | ||
``` | ||
|
||
### Delete hook | ||
|
||
``` | ||
Method: DELETE | ||
URL: https://trello.com/1/tokens/:token:/webhooks/:hook_id:/?key=:key: | ||
``` | ||
|
||
### Observations | ||
|
||
- Accepts self-signed certificates; | ||
- It's not possible to use a different port than 443 for HTTPS on hooks; | ||
|
||
# Example | ||
|
||
To see how we use Porcupine just check our implementation at [natuelabs/our-porcupine](https://github.com/natuelabs/our-porcupine). |
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,4 @@ | ||
var events = require( 'events' ); | ||
var eventEmitter = new events.EventEmitter(); | ||
|
||
module.exports = eventEmitter; |
Oops, something went wrong.