|
| 1 | +/* global vegaEmbed */ |
| 2 | + |
| 3 | +function getBuilds(repo, href = `/repo/${encodeURIComponent(repo)}/builds?limit=100`, builds = []) { |
| 4 | + return fetch(`https://api.travis-ci.com${href}`, { |
| 5 | + headers: { 'Travis-API-Version': '3' }, |
| 6 | + }) |
| 7 | + .then((r) => r.json()) |
| 8 | + .then((data) => { |
| 9 | + const newBuilds = builds.concat(data.builds); |
| 10 | + if (data['@pagination'].next) { |
| 11 | + return getBuilds(repo, data['@pagination'].next['@href'], newBuilds); |
| 12 | + } |
| 13 | + return newBuilds; |
| 14 | + }); |
| 15 | +} |
| 16 | + |
| 17 | +const schema = { |
| 18 | + '$schema': 'https://vega.github.io/schema/vega-lite/v3.json', |
| 19 | + 'width': 1000, |
| 20 | + 'height': 400, |
| 21 | + 'mark': 'point', |
| 22 | + 'data': { |
| 23 | + 'name': 'table', |
| 24 | + 'values': null, |
| 25 | + }, |
| 26 | + 'selection': { |
| 27 | + 'grid': { |
| 28 | + 'type': 'interval', |
| 29 | + 'bind': 'scales', |
| 30 | + }, |
| 31 | + }, |
| 32 | + 'encoding': { |
| 33 | + 'y': { |
| 34 | + 'field': 'duration', |
| 35 | + 'type': 'quantitative', |
| 36 | + 'axis': { |
| 37 | + 'title': 'Duration (minutes)', |
| 38 | + }, |
| 39 | + }, |
| 40 | + 'x': { |
| 41 | + 'field': 'finished_at', |
| 42 | + 'timeUnit': 'yearmonthdatehoursminutes', |
| 43 | + 'type': 'temporal', |
| 44 | + 'scale': { |
| 45 | + 'nice': 'week', |
| 46 | + }, |
| 47 | + 'axis': { |
| 48 | + 'title': 'Date', |
| 49 | + }, |
| 50 | + }, |
| 51 | + 'color': { |
| 52 | + 'field': 'state', |
| 53 | + 'type': 'nominal', |
| 54 | + 'scale': { |
| 55 | + 'domain': ['failed', 'errored', 'canceled', 'passed'], |
| 56 | + 'range': ['#d62728', '#ff7f0e', '#1f77b4', '#5ab43c'], |
| 57 | + }, |
| 58 | + }, |
| 59 | + }, |
| 60 | +}; |
| 61 | + |
| 62 | +getBuilds('engine262/engine262') |
| 63 | + .then((builds) => { |
| 64 | + schema.data.values = builds.map((b) => ({ |
| 65 | + state: b.state, |
| 66 | + finished_at: b.finished_at, |
| 67 | + duration: b.duration / 60, |
| 68 | + })); |
| 69 | + vegaEmbed('#view', schema); |
| 70 | + }); |
0 commit comments