-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweethook.js
29 lines (24 loc) · 920 Bytes
/
tweethook.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
var Async = require('async');
var Twit = require('twit');
var HTTPS_URL_LENGTH = 23; // As at 2015-12-08
var HASHTAG = '#tweethook';
var SPACE = ' ';
module.exports = function (ctx, cb) {
if (ctx.body.ref !== 'refs/heads/master') return cb(null, {});
var twit = new Twit({
consumer_key: ctx.data.CONSUMER_KEY,
consumer_secret: ctx.data.CONSUMER_SECRET,
access_token: ctx.data.ACCESS_TOKEN,
access_token_secret: ctx.data.ACCESS_TOKEN_SECRET,
});
Async.mapSeries(ctx.body.commits, function (commit, next) {
var truncateCommitMessage = 140
- HTTPS_URL_LENGTH
- HASHTAG.length
- SPACE.length * 2;
var status = commit.message.slice(0, truncateCommitMessage)
+ SPACE + HASHTAG
+ SPACE + commit.url;
twit.post('statuses/update', { status: status }, next);
}, cb);
};