Skip to content

Instantly share code, notes, and snippets.

@xli
Created January 28, 2016 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xli/1430de60ba5feee7aeb6 to your computer and use it in GitHub Desktop.
Save xli/1430de60ba5feee7aeb6 to your computer and use it in GitHub Desktop.
Go server stage job count stats
var pipelines = $H({});
var stats = {
pipelineCount: 0,
stageCount: 0,
stageHasOneJobCount: 0,
stageHasMultipleJobCount: 0
}
$j.ajax({url: "/go/cctray.xml", dataType: "xml"}).done(function(data) {
$j(data).find("Project").each(function(i, e) {
var job = $j(e).attr("name").split(" :: ");
if (job.length == 3) {
var p = pipelines.get(job[0]);
console.log(p)
if (!p) {
p = $H({})
pipelines.set(job[0], p);
}
var s = p.get(job[1]);
if (!s) {
p.set(job[1], 1);
} else {
p.set(job[1], s+1);
}
}
});
stats.pipelineCount = pipelines.size();
pipelines.values().each(function(v) {
stats.stageCount = stats.stageCount + v.size();
v.values().each(function(vv) {
if (vv == 1) {
stats.stageHasOneJobCount = stats.stageHasOneJobCount + 1;
} else {
stats.stageHasMultipleJobCount = stats.stageHasMultipleJobCount + 1;
}
});
});
console.log(stats)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment