-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtrello_commit.js
More file actions
52 lines (39 loc) · 1.51 KB
/
trello_commit.js
File metadata and controls
52 lines (39 loc) · 1.51 KB
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
var Trello = require("node-trello");
var t = new Trello("<key>", "<token>"); // Change these to your key and token from Trello
var exec = require('child_process').exec;
exec('(cd ' + process.argv[2] + ' && git log -1 --oneline HEAD)', function callback(error, stdout, stderr){
if (error) throw error;
if(stdout.indexOf('|') < 0) { return; }
var splitCommit = stdout.split('|'),
cardIdentifier = splitCommit[1].trim(),
commitContent = 'Commit: ' + splitCommit[0],
postUrl = "/1/cards/{0}/actions/comments/",
getUrl,
splitString,
cardId,
boardId;
if(cardIdentifier && cardIdentifier.indexOf('trello.com') >= 0) {
splitString = cardIdentifier.split('/');
cardId = splitString[splitString.length - 1].replace('\n','');
postUrl = postUrl.replace('{0}', cardId);
t.post(postUrl, { text: commitContent }, function (error, data) {
if (error) throw error;
console.log('Sent commit message to Trello');
});
}
else {
getUrl = "/1/boards/{0}/cards/{1}";
splitString = cardIdentifier.split('/');
boardId = splitString[0];
cardId = splitString[1].replace('\n', '');
getUrl = getUrl.replace('{0}', boardId).replace('{1}', cardId);
t.get(getUrl, function (error, data) {
if (error) throw error;
postUrl = postUrl.replace('{0}', data.id);
t.post(postUrl, { text: commitContent }, function (error, data) {
if (error) throw error;
console.log('Sent commit message to Trello');
});
});
}
});