diff --git a/.gitignore b/.gitignore index 3cdc0ad..e5f98f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules coverage artifacts +.idea/ diff --git a/.travis.yml b/.travis.yml index 4fc06d2..de1246f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - '0.11' + - '4' script: - npm test sudo: false diff --git a/README.md b/README.md index b3908bd..c940fb9 100644 --- a/README.md +++ b/README.md @@ -36,14 +36,14 @@ var gulp = require('gulp'), eslint = require('gulp-eslint'), github = require('gulp-github'); -gulp.task('link_report_github', function () { +gulp.task('lint_report_github', function () { return gulp.src('lib/*.js') .pipe(jshint()) .pipe(jscs()).on('error', function (E) { console.log(E.message); // This handled jscs stream error. }) .pipe(eslint()) - .pipe(github(options)); // Comment issues in github PR! + .pipe(github(options)) // Comment issues in github PR! .pipe(github.failThisTask()); // Fail this task when jscs/jshint/eslint issues found. }); @@ -54,8 +54,14 @@ github.commentToPR('Yes! it works!!', options); github.createStatusToCommit({ description: 'No! 2 failures...', context: 'my gulp task', - state: 'failure' + state: 'failure', + target_url: 'http://www.homerswebpage.com/' }, options); + +// Or, create a task to reject PR with merged commits +gulp.task('git_rules', function (cb) { + git.failMergedPR(options, cb); +}); ``` Options @@ -79,8 +85,10 @@ Options // when using github enterprise, optional git_option: { - // refer to https://www.npmjs.com/package/github - host: 'github.mycorp.com' + // refer to https://www.npmjs.com/package/github for more options + host: 'github.mycorp.com', + // You may require this when you using Enterprise Github + pathPrefix: '/api/v3' }, // Provide your own jshint reporter, optional diff --git a/gulpfile.js b/gulpfile.js index 6ebf5ee..157f504 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,7 +5,7 @@ var gulp = require('gulp'), github = require('./index'); gulp.task('default', function () { - return gulp.src('*.js') + return gulp.src(['*.js']) // , 'lint_test/*.js']) .pipe(eslint()) .pipe(jshint()) .pipe(jscs()) @@ -21,8 +21,9 @@ gulp.task('default', function () { git_prid: process.env.TRAVIS_PULL_REQUEST, git_sha: process.env.TRAVIS_COMMIT, - jshint_status: 'error', // Set status to error when jshint errors - jscs_status: 'failure' // Set status to failure when jscs errors + jshint_status: 'error', // Set status to error when jshint errors + jscs_status: 'failure', // Set status to failure when jscs errors + eslint_status: 'failure' // Set status to failure when eslint errors })) .pipe(github.failThisTask()); }); diff --git a/index.js b/index.js index 7ed65cd..e8124e1 100644 --- a/index.js +++ b/index.js @@ -38,6 +38,17 @@ var closePR = function (opt, cb) { }, cb); }; +var createPR = function (title, head, base, body, opt, cb) { + getGIT(opt).pullRequests.create({ + user: opt.git_repo.split('/')[0], + repo: opt.git_repo.split('/')[1], + title: title, + head: head, + base: base, + body: body + }, cb); +}; + var commentToPR = function (body, opt, cb) { getGIT(opt).issues.createComment({ user: opt.git_repo.split('/')[0], @@ -48,14 +59,16 @@ var commentToPR = function (body, opt, cb) { }; var createStatusToCommit = function (state, opt, cb) { - getGIT(opt).statuses.create({ + var statusOptions = { user: opt.git_repo.split('/')[0], repo: opt.git_repo.split('/')[1], sha: opt.git_sha, state: state.state, description: state.description, context: state.context - }, cb); + }; + if(state.target_url){statusOptions.target_url = state.target_url;} + getGIT(opt).repos.createStatus(statusOptions, cb); }; var isPullRequest = function (opt) { @@ -64,7 +77,7 @@ var isPullRequest = function (opt) { var isMerge = function (opt, callback) { if (!isPullRequest(opt)) { - return; + return callback(); } getGIT(opt).pullRequests.getCommits({ @@ -110,6 +123,8 @@ var failMergedPR = function (opt, cb) { return; } + err.push(M); + commentToPR('**Do not accept PR with merge, please use rebase always!**\n' + M, opt, done); createStatusToCommit({ @@ -176,7 +191,9 @@ module.exports = function (options) { eslint_output = ['**Please fix these eslint issues first:**'], opt = options || {}, jshint_reporter = opt.jshint_reporter || jshint_simple_reporter, - jscs_reporter = opt.jscs_reporter || jscs_simple_reporter; + jscs_reporter = opt.jscs_reporter || jscs_simple_reporter, + eslint_reporter = opt.eslint_reporter || eslint_simple_reporter; + return through.obj(function (file, enc, callback) { if (file.jshint && !file.jshint.success && !file.jshint.ignored) { @@ -186,14 +203,14 @@ module.exports = function (options) { } if (file.jscs && !file.jscs.success) { - file.jscs.errors.forEach(function (E) { + (file.jscs.errors.getErrorList ? file.jscs.errors.getErrorList() : file.jscs.errors).forEach(function (E) { jscs_output.push(jscs_reporter(E, file)); }); } if (file.eslint) { file.eslint.messages.forEach(function (E) { - eslint_output.push(eslint_simple_reporter(E, file)); + eslint_output.push(eslint_reporter(E, file)); }); } @@ -289,6 +306,7 @@ module.exports = function (options) { }; module.exports.commentToPR = commentToPR; +module.exports.createPR = createPR; module.exports.createStatusToCommit = createStatusToCommit; module.exports.failThisTask = failThisTask; module.exports.failMergedPR = failMergedPR; diff --git a/lint_test/test1.js b/lint_test/test1.js new file mode 100644 index 0000000..c09af3e --- /dev/null +++ b/lint_test/test1.js @@ -0,0 +1,7 @@ +var bad = {}; +var foo = 123; + +if (123) { + foo ++; + foo--; +} diff --git a/package.json b/package.json index 49fccef..686354d 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "gulp-github", - "version": "0.3.3", + "version": "0.3.6", "description": "A gulp plugin to pipe contents to github pull request comments.", - "author": "Zordius ", + "author": "Zordius ", "contributors": [ { "name": "Zordius Chen", @@ -26,15 +26,15 @@ }, "main": "index.js", "dependencies": { - "github": "0.2.4", - "gulp-util": "3.0.6", + "github": "2.2.0", + "gulp-util": "3.0.7", "through2": "*" }, "devDependencies": { - "gulp": "3.9.0", - "gulp-jshint": "1.11.2", - "gulp-jscs": "2.0.0", - "gulp-eslint": "1.0.0" + "gulp": "3.9.1", + "gulp-jshint": "2.0.1", + "gulp-jscs": "4.0.0", + "gulp-eslint": "3.0.1" }, "engines": { "node": ">=0.8"