Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Now deletes delete failed stacks #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function cleanupStacks(dryRun) {
var withStatuses = filterStacksByStatus(oldNonMasterStacks);
var notBatmanTag = ignoreStacksWithBatmanTag(withStatuses);
batmanTaggedStacks = getBatmanStacks(withStatuses);
return notBatmanTag;
return notBatmanTag.concat(getDeleteFailedStacks(allStacks));
})
.then(filteredStacks => {
console.log('filteredStacks', filteredStacks);
Expand Down Expand Up @@ -106,6 +106,13 @@ function filterStacksByStatus(stacksArray) {
});
}

function getDeleteFailedStacks(stacksArray) {
return _.filter(stacksArray, stack => {
var statuses = ["DELETE_FAILED"];
return statuses.indexOf(stack.StackStatus) >= 0;
});
}

function findNonMasterStacks(stacksArray) {
var nonMasterStacks = _.filter(stacksArray, stack => {
var branchTag = _.filter(stack.Tags, (tag) => {return tag.Key.toLowerCase() == process.env.BRANCH_KEY.toLowerCase()});
Expand Down
14 changes: 12 additions & 2 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function assertDeletedStacksResponse(deletableStackNames) {
assert(deletableStackNames.mercyShown.indexOf('Tagged Batman Not Deleted') > -1);
assert(deletedStacks.indexOf('Delete Me') > -1);
assert(deletedStacks.indexOf('Try deleting failed again') > -1);
assert.equal(deletedStacks.length, 3);
assert(deletedStacks.indexOf('Try deleting young failed') > -1);
assert.equal(deletedStacks.length, 5);
}


Expand All @@ -31,7 +32,7 @@ describe('Cleanup', function() {
console.log('Shown Mercy: ', deletableStackNames.mercyShown);
assertDeletedStacksResponse(deletableStackNames);
assert(deleteStacksStub.called);
assert(deleteStacksStub.calledWith(sinon.match({ StackName: 'Delete Me'}, { StackName: 'Try deleting failed again'}, { StackName: 'elastic-beanstalk-another-branch'})));
assert(deleteStacksStub.calledWith(sinon.match({ StackName: 'Delete Me'}, { StackName: 'Try deleting failed again'}, { StackName: 'elastic-beanstalk-another-branch'}, { StackName: 'Try deleting young failed'})));
done();
}).catch(err => {
console.log('errors');
Expand Down Expand Up @@ -144,6 +145,15 @@ var mocks = {
}],
Outputs: [],
LastUpdatedTime: moment().add(-8, 'days')
},{
StackName: 'Try deleting young failed',
StackStatus: 'DELETE_FAILED',
Tags: [{
Key: 'Slice',
Value: 'non master'
}],
Outputs: [],
LastUpdatedTime: moment().add(-2, 'days')
},{
StackName: 'Do not delete me',
StackStatus: 'UPDATE_IN_PROGRESS',
Expand Down