Skip to content

Commit a9aac45

Browse files
committed
Audit: Notify user about missing signature with issue comment
Fixes jquery#12
1 parent 8179cee commit a9aac45

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

bin/server.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function prHook( event, done ) {
3737
getSignatures().then(
3838
function( signatures ) {
3939
auditPr( {
40+
action: event.payload.action,
4041
repo: event.repo,
4142
pr: event.pr,
4243
baseRemote: event.payload.pull_request.base.git_url,
@@ -113,7 +114,12 @@ getSignatures = ( function() {
113114
promise = updatedPromise;
114115
if ( Object.keys( signatures ).length !== Object.keys( newSignatures ).length ) {
115116
signatures = newSignatures;
116-
async.eachSeries( failedEvents.splice( 0 ), prHook );
117+
async.eachSeries( failedEvents.splice( 0 ), function( event, done ) {
118+
119+
// Overide action to avoid posting comments twice
120+
event.payload.action = "synchronize";
121+
prHook( event, done );
122+
} );
117123
}
118124
} )
119125
.catch( function( error ) {

lib/comment.hbs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Thank you for your pull request. It looks like this may be your first contribution to a jQuery Foundation project, if so we need you to sign our Contributor License Agreement (CLA).
2+
3+
__:memo: Please visit http://contribute.jquery.org/CLA/ to sign.__
4+
5+
After you signed, the PR is checked again automatically after a minute. If there's still an issue, please reply here to let us know.
6+
7+
---
8+
9+
If you've already signed our CLA, it's possible your git author information doesn't match your CLA signature (both your name and email have to match), for more information, [check the status of your CLA check](http://contribute.jquery.org/CLA/status/?repo={{repo}}&sha={{head}}).

lib/pr.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
var fs = require( "fs" ),
2-
querystring = require( "querystring" ),
3-
Promise = require( "es6-promise" ).Promise,
4-
mkdirp = require( "mkdirp" ),
5-
createDebugger = require( "debug" ),
6-
config = require( "./config" ),
7-
Repo = require( "./repo" );
1+
var fs = require( "fs" );
2+
var querystring = require( "querystring" );
3+
var Promise = require( "es6-promise" ).Promise;
4+
var mkdirp = require( "mkdirp" );
5+
var createDebugger = require( "debug" );
6+
var config = require( "./config" );
7+
var Repo = require( "./repo" );
8+
var handlebars = require( "handlebars" );
9+
var commentTemplate = handlebars.compile( fs.readFileSync( __dirname + "/comment.hbs", "utf-8" ) );
810

911
function Audit( options ) {
1012
if ( !options.repo ) {
@@ -196,6 +198,19 @@ Audit.prototype.logResult = function( result ) {
196198
} );
197199
};
198200

201+
Audit.prototype.postComment = function() {
202+
203+
// Only post comment on new PRs
204+
if ( this.options.action !== "opened" ) {
205+
return;
206+
}
207+
208+
return this.repo.addComment( {
209+
pr: this.options.pr,
210+
body: commentTemplate( this.options )
211+
} );
212+
};
213+
199214
Audit.prototype.finishAudit = function( values ) {
200215
var result = values[ 0 ],
201216
labels = values[ 1 ],
@@ -212,7 +227,8 @@ Audit.prototype.finishAudit = function( values ) {
212227
return Promise.all( [
213228
this.logResult( result ),
214229
this.repo.setStatus( status ),
215-
this.applyLabels( labels, result.state )
230+
this.applyLabels( labels, result.state ),
231+
this.postComment()
216232
] )
217233
.then( function() {
218234

lib/repo/github.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,13 @@ Repo.prototype.removeLabel = function( options ) {
108108
} );
109109
};
110110

111+
Repo.prototype.addComment = function( options ) {
112+
return this.request( {
113+
path: "/issues/" + ( options.issue || options.pr ) + "/comments",
114+
method: "POST"
115+
}, {
116+
body: options.body
117+
} );
118+
};
119+
111120
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"es6-promise": "2.0.1",
3030
"git-notifier": "2.1.0",
3131
"github-request": "1.2.1",
32+
"handlebars": "^4.0.1",
3233
"mkdirp": "0.5.0",
3334
"mout": "0.11.0",
3435
"sane-email-validation": "1.0.0",

0 commit comments

Comments
 (0)