This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const xml2js = require('xml2js'); | |
const fs = require('fs'); | |
const xmlFileName = 'deployments.xml'; | |
const environment = 'PROD'; | |
const year = '2019'; | |
xml2js.parseString(fs.readFileSync(xmlFileName), function (err, result) { | |
if (err) throw err; | |
var filteredDeployments = result.Deployments.Deployment.filter(filterConditions); | |
var projectAndDeployCount = filteredDeployments.reduce(countByProjectName, {}); | |
console.log('Total successful deploys to ' + environment + ' in ' + year + ': ' + filteredDeployments.length); | |
console.table(sortByMostDeploys(projectAndDeployCount)); | |
}); | |
function filterConditions(deployment) { | |
return deployment.TaskState[0] === 'Success' | |
&& deployment.CompletedTime[0].startsWith(year + '-') | |
&& deployment.EnvironmentName[0] === environment; | |
} | |
function countByProjectName(state, value) { | |
var projectName = value.ProjectName[0]; | |
if (typeof state[projectName] === 'undefined') | |
state[projectName] = 1; | |
else | |
state[projectName]++; | |
return state; | |
} | |
function sortByMostDeploys(projectAndDeployCount) { | |
return Object.entries(projectAndDeployCount).sort((a, b) => b[1] - a[1]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment