Skip to content

Commit

Permalink
Support reading CI results from multiple buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
beekhof committed Oct 10, 2023
1 parent 6849343 commit ee8ae16
Showing 1 changed file with 60 additions and 16 deletions.
76 changes: 60 additions & 16 deletions static/js/dashboard.v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,11 @@ function getBadges (xmlText, bucket_url, badge_set) {
return badges
}

function processBucketXML (text, options) {
function processBadges (badges, options) {
const filter_field = options.get('filter_field')
const filter_value = options.get('filter_value')
const links = options.get("links");
badges = getBadges(text, options.get('bucket'), options.get('sets'))

htmlText = ""
if (options.get("disable_buttons") != true) {
htmlText += renderSetButtons(options.get('sets'))
Expand Down Expand Up @@ -542,11 +542,20 @@ function getBucketOptions (input) {
} else {
options.set('sets', 'GA')
}
options.set('links', 'public');
options.set('links', 'public')
options.set('target', 'dataset')
options.set('bucket', 'https://storage.googleapis.com/vp-results')

buckets = []
const bucket = input['bucket']
if (bucket != null) {
buckets.push(bucket)
} else {
buckets.push('https://storage.googleapis.com/vp-results')
// buckets.push('https://storage.googleapis.com/other-results')
}
options.set('buckets', buckets)

const fields = [ 'sets', 'bucket', 'target', 'filter_field', 'filter_value', 'links', 'disable_buttons' ]
const fields = [ 'sets', 'target', 'filter_field', 'filter_value', 'links', 'disable_buttons' ]
for (i = 0; i < fields.length; i++) {
const key = fields[i]
const value = input[key]
Expand All @@ -573,16 +582,51 @@ function getBucketOptions (input) {
return options
}

function fetchBucketBadges(bucket, inputs) {
return new Promise((resolve, reject) => {
let req = new XMLHttpRequest();
const options = getBucketOptions(inputs);
req.open('GET', bucket);
req.onload = function () {
if (req.status == 200) {
const badges = getBadges(req.responseText, bucket, options.get('sets'))
resolve(badges);
} else {
console.error('Error: ' + req.status);
reject('Error: ' + req.status);
}
};
req.send();
});
}

function obtainBadges (inputs) {
let req = new XMLHttpRequest()
const options = getBucketOptions(inputs)
req.open('GET', options.get('bucket'))
req.onload = function () {
if (req.status == 200) {
processBucketXML(req.responseText, options)
} else {
console.log('Error: ' + req.status)
}
}
req.send()
const options = getBucketOptions(inputs);
const buckets = options.get('buckets')

// Create an array to store promises for each bucket's badges
const badgePromises = [];

// Iterate through each bucket URL and fetch badges asynchronously
for (const bucket of buckets) {
badgePromises.push(fetchBucketBadges(bucket, inputs));
}

// Wait for all promises to resolve
Promise.all(badgePromises)
.then((results) => {
// Process the badges from all buckets
const allBadges = [];
for (const badges of results) {
console.log("Got "+badges.length+" badges")
allBadges.push(...badges);
}

console.log('All badges:', allBadges);

processBadges(allBadges, options)
})
.catch((error) => {
console.error('Error:', error);
});
}

0 comments on commit ee8ae16

Please sign in to comment.