-
Notifications
You must be signed in to change notification settings - Fork 0
/
pivotal_poster.js
54 lines (48 loc) · 1.42 KB
/
pivotal_poster.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
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Formats git informations and posts them to PivotalTracker.
*/
var API_TOCKEN = require('./tracker_token');
//optional injection of http for mocking
module.exports = function(https) {
if(!https) https = require('https');
function prepareMessageForPivotal(story_id, message, refname, author, hash, callback) {
var post_msg =
'<source_commit>'
+ '<message>Branch:' + refname + '\n' + message + '</message>'
+ '<author>' + author + '</author>'
+ '<commit_id>' + hash + '</commit_id>'
+ '</source_commit>';
callback(null, post_msg, story_id);
}
/**
* Posts the informations to PivotalTracker
*/
function postToPivotal (post_msg, story_id, callback) {
var options = {
host: 'www.pivotaltracker.com',
path: '/services/v3/source_commits',
method: 'POST',
headers: {'X-TrackerToken' : API_TOCKEN
, 'Content-type': 'application/xml'
, 'Content-length': post_msg.length}
};
console.log('Start posting for story ' + story_id);
var req = https.request(options, function(res) {
var data = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function (chunk) {
var success = (res.statusCode === 200) ? 'success for ' : 'failed for ';
callback(null, 'Post ' + success + story_id);
});
});
req.write(post_msg);
req.end();
}
return {
prepareMessageForPivotal: prepareMessageForPivotal
, postToPivotal: postToPivotal
};
}