forked from groovecoder/discord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommenter.js
42 lines (36 loc) · 1.18 KB
/
commenter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
/**
* NOTE: This module won't be necessary once octonode implements
* create_pull_request_comment.
*/
var request = require('request');
var config = require('./config');
/**
* Post a line comment on a particular pull request. commentURL should be an
* instance of review_comments_url.
* https://developer.github.com/v3/activity/events/types/#pullrequestevent
*/
function postPullRequestComment(commentURL, comment, filename, commitSHA, line, done) {
request.post({
url: commentURL,
headers: {
'User-Agent': config.brand,
'Authorization': 'token ' + config.token
},
form: {
body: comment,
path: filename,
commit_id: commitSHA,
position: line
}
}, function(error, response) {
// If the comment could not be submitted, notify Redis so that the job
// can be re-attempted later. Otherwise, mark the job as done.
if (error || response.statusCode === 403) {
return done(new Error('Comment could not be submitted'));
} else {
done();
}
});
}
exports.postPullRequestComment = postPullRequestComment;