This repository has been archived by the owner on Jan 29, 2023. It is now read-only.
forked from mako-taco/pivotal-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeliver.js
111 lines (98 loc) · 2.63 KB
/
deliver.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var check = require('./internal/check'),
git = require('./internal/git'),
ask = require('./internal/ask'),
readline = require('readline'),
colors = require('colors'),
pivotal = require('pivotal')
//adding some stuff on to this shitty library, replacing broken functonality
pivotal.me = require('./internal/pivotal-shim').me,
pivotal.updateStory = require('./internal/pivotal-shim').updateStory,
pivotal.getStories = require('./internal/pivotal-shim').getStories;
module.exports = function (args) {
check(function (err, pt) {
if(err) {
throw err;
}
pivotal.useToken(pt.apikey);
git.getConfigStore(function (err, store) {
if(err) {
throw err;
}
var stores = [];
for(var key in store) {
stores.push({
branch: key,
story: store[key]
});
}
var done = 0;
var started = 0;
var notReady = 0;
stores.filter(function (store) {
return store.story.id != undefined;
}).forEach(function (item) {
started++;
var branch = item.branch;
var update = {current_state: "delivered"};
pivotal.getStory(pt.project, item.story.id, function(err, story){
if(err && err.code ==404){
console.log(item.story.id, "is invalid");
}
else if(err){
console.log(err);
throw new Error(err.desc);
}
else{
if(story.current_state=="finished"){
//deliver the story
pivotal.updateStory(pt.apikey, pt.project, story.id, update, function (err) {
if(err) {
console.log(err);
done++;
checkDone();
console.error("could not deliver ".red + story.name.grey)
}
else {
console.log("delivered ".cyan + story.name.grey);
//delete remote branch
//delete local branch
git.deleteBranch(branch, function (err) {
if(err) {
console.error("could not delete branch ".red + branch.grey);
}
console.log("cleaning up git branches".cyan)
delete store[branch];
git.setConfigStore(store, function (err, store) {
if(err) {
console.error("could not remove story branch from git config".red);
}
done++
checkDone();
});
});
}
});
}
else{
notReady++;
checkDone();
}
}
});
});
if(started == 0) {
console.log("no stories to deliver".cyan);
}
var checkDone = function() {
if(started == notReady){
console.log("no stories waiting to be delivered".cyan);
process.exit(0);
}
if(done == started-notReady) {
//do deploy here
process.exit(0);
}
}
});
});
}