Sample Snippets
Â
Â
Â
Execute a command if a specific file is being changed
var commits = stash.fetchCommits( project.key, repository.slug, changeSet[0].fromHash, changeSet[0].toHash); var executeCommand = false; for(var i=0;i<commits.length;i++) { for(var x=0;x<commits[i].filesAdded.length;x++) { if( commits[i].filesAdded[x].path=='my-special-file') { executeCommand = true; } } for(var x=0;x<commits[i].filesModified.length;x++) { if( commits[i].filesModified[x].path=='my-special-file') { executeCommand = true; } } } Â if( executeCommand ) { stash.executeCommand('command-to-execute.sh arg'); } Â
Â
Block certain files from being pushed
function verifyFiles( files) { for(var i=0;i<files.length;i++) { if(files[i].path().endsWith('.doc')) { stash.sendFeedback('Invalid file extension', files[i].path+' was in the commit. Please remove', true); } } } for(var c=0;c<changeSet.length;c++) { var commits = stash.fetchCommits( project.key, repository.slug, changeSet[c].fromHash , changeSet[c].toHash); for(var commitCounter=0;commitCounter<commits.length;commitCounter++) { verifyFiles( commits[commitCounter].filesAdded); verifyFiles( commits[commitCounter].filesModified); verifyFiles( commits[commitCounter].filesMoved); verifyFiles( commits[commitCounter].filesCopied); verifyFiles( commits[commitCounter].filesUnknown); } }