Skip to content

Commit

Permalink
feat: update to es6 (#18)
Browse files Browse the repository at this point in the history
* feat: use async/await

* fix: fix github api bug

* fix: fix auto release note bug

* fix: auto release node commit message handle bug

* fix: Notable changes list display bug

* fix: Notable changes sub list display bug

* feat: add eslint

* feat: use husky to handle git hooks
  • Loading branch information
yugasun authored and xuexb committed Oct 18, 2017
1 parent d7f7b22 commit b447cbe
Show file tree
Hide file tree
Showing 13 changed files with 782 additions and 661 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ root = true
[*]
charset = utf-8
indent_style = space
indent_size = 4
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// http://eslint.org/docs/user-guide/configuring

module.exports = {
root: true,
env: {
'node': true
},
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
extends: 'standard',
// add your custom rules here
'rules': {
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
}
}
24 changes: 17 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"version": "0.0.1",
"main": "src/app.js",
"scripts": {
"start": "NODE_ENV=development node src/app"
"start": "NODE_ENV=development node src/app",
"lint": "eslint src/**/* --quiet",
"precommit": "npm run lint",
"commitmsg": "validate-commit-msg"
},
"repository": {
"type": "git",
Expand All @@ -27,12 +30,9 @@
"string-template": "^1.0.0"
},
"engines": {
"node": ">= 4"
"node": ">= 7.8.0"
},
"config": {
"ghooks": {
"commit-msg": "validate-commit-msg"
},
"validate-commit-msg": {
"types": [
"feat",
Expand All @@ -53,10 +53,20 @@
}
}
},
"os": ["darwin", "linux"],
"os": [
"darwin",
"linux"
],
"devDependencies": {
"ghooks": "^2.0.0",
"eslint": "^4.9.0",
"eslint-config-standard": "^10.2.1",
"eslint-friendly-formatter": "^3.0.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.2.0",
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-standard": "^3.0.1",
"git-pull-or-clone": "xuexb/git-pull-or-clone",
"husky": "^0.14.3",
"validate-commit-msg": "^2.14.0"
}
}
74 changes: 36 additions & 38 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,50 @@
* @author xuexb <fe.xiaowu@gmail.com>
*/

require('dotenv').config();
require('dotenv').config()

const EventEmitter = require('events');
const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const requireDir = require('require-dir');
const {verifySignature} = require('./utils');
const issueActions = requireDir('./modules/issues');
const pullRequestActions = requireDir('./modules/pull_request');
const releasesActions = requireDir('./modules/releases');
const app = new Koa();
const githubEvent = new EventEmitter();
const EventEmitter = require('events')
const Koa = require('koa')
const bodyParser = require('koa-bodyparser')
const requireDir = require('require-dir')
const { verifySignature } = require('./utils')
const issueActions = requireDir('./modules/issues')
const pullRequestActions = requireDir('./modules/pull_request')
const releasesActions = requireDir('./modules/releases')
const app = new Koa()
const githubEvent = new EventEmitter()

app.use(bodyParser());
app.use(bodyParser())

app.use(ctx => {
let eventName = ctx.request.headers['x-github-event'];
if (eventName && verifySignature(ctx.request)) {
const payload = ctx.request.body;
const action = payload.action || payload.ref_type;
let eventName = ctx.request.headers['x-github-event']
if (eventName && verifySignature(ctx.request)) {
const payload = ctx.request.body
const action = payload.action || payload.ref_type

if (action) {
eventName += `_${action}`;
}

console.log(`receive event: ${eventName}`);
if (action) {
eventName += `_${action}`
}

githubEvent.emit(eventName, {
repo: payload.repository.name,
payload
});
console.log(`receive event: ${eventName}`)

ctx.body = 'Ok.';
}
else {
ctx.body = 'Go away.';
}
});
githubEvent.emit(eventName, {
repo: payload.repository.name,
payload
})

ctx.body = 'Ok.'
} else {
ctx.body = 'Go away.'
}
})

const actions = Object.assign({}, issueActions, pullRequestActions, releasesActions);
const actions = Object.assign({}, issueActions, pullRequestActions, releasesActions)
Object.keys(actions).forEach((key) => {
actions[key](githubEvent.on.bind(githubEvent));
console.log(`bind ${key} success!`);
});
actions[key](githubEvent.on.bind(githubEvent))
console.log(`bind ${key} success!`)
})

const port = 8000;
app.listen(port);
console.log(`Listening on http://0.0.0.0:${port}`);
const port = 8000
app.listen(port)
console.log(`Listening on http://0.0.0.0:${port}`)
Loading

0 comments on commit b447cbe

Please sign in to comment.