Published
Edited
Sep 21, 2021
18 forks
34 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
repo = "sveltejs/svelte"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
isSample = repo === "sveltejs/svelte" && !hasApiKey
Insert cell
// Once authenticated:
// workflows = fetchWorkflows(repo)
workflows = isSample ? sampleWorkflows : fetchWorkflows(repo)
Insert cell
// Once authenticated:
// runs = fetchRuns(repo, workflow.id)
runs = isSample ? sampleRuns : fetchRuns(repo, workflow.id)
Insert cell
branches = new Set(runs.map(r => r.head_branch))
Insert cell
jobs = parseJobs(runs)
.filter(d => !branch || d.run.head_branch === branch)
Insert cell
Insert cell
durationByJob = data => {
const xy = {x: "minutes", y: "name"};
return Plot.plot({
marginLeft: 150,
color,
y: {
domain: d3.groupSort(data, g => d3.median(g, d => d.minutes), d => d.name)
},
marks: [
Plot.ruleX([0]),
Plot.tickX(data, {...xy, stroke: "conclusion", strokeOpacity: 0.5}),
getTooltip(data, xy)
]
})
}
Insert cell
durationOverTime = data => {
const xy = ({x: "started_at", y: "minutes"});
return Plot.plot({
marginBottom: 55,
width,
color,
x: {
tickFormat: ((i, f) => d => i(d) < d ? null : f(d))(d3.timeDay, dateFormat),
ticks: d3.timeHour.every(6)
},
marks: [
Plot.ruleY([0]),
Plot.areaY(data, Plot.binX({y1: q1, y2: q3}, {...xy, fill: "#eee", curve: "linear"})),
Plot.dot(data, {...xy, stroke: "conclusion", r: 3, strokeOpacity: 0.5}),
getTooltip(data, xy)
]
})
}
Insert cell
durationOverRun = data => {
const xy = {x: "run_number", y: "minutes"};
return Plot.plot({
marginBottom: 55,
width,
color,
x: {tickRotate: 90},
marks: [
Plot.ruleY([0]),
Plot.areaY(data, Plot.groupX({y1: q1, y2: q3}, {...xy, fill: "#eee"})),
Plot.tickY(data, {...xy, stroke: "conclusion"}),
getTooltip(data, xy)
]
})
}
Insert cell
timePlots = new Map([["Run number", durationOverRun], ["Start time", durationOverTime]])
Insert cell
Insert cell
jobMedians = d3.rollups(
jobs.filter(d => d.conclusion === "success"),
g => d3.median(g, d => d.minutes),
d => d.name
).sort((a, b) => a[1] - b[1])
Insert cell
dayMedians = d3.rollups(
jobs.filter(d => d.conclusion === "success"),
g => d3.median(g, d => d.minutes),
d => d3.timeDay.floor(d.started_at)
).sort((a, b) => a[1] - b[1])
Insert cell
q1 = data => d3.quantile(data, 0.25)
Insert cell
q3 = data => d3.quantile(data, 0.75)
Insert cell
color = ({domain: ["cancelled", "failure", "success"], range: ["gray", "#cb2431", "#2cbe4e"]})
Insert cell
dateFormat = d3.timeFormat("%a %m/%d")
Insert cell
timeFormat = d3.timeFormat("%a %m/%d %I:%M")
Insert cell
durationFormat = d => `${Math.floor(d)}m${Math.round(d % 1 * 60)}s`
Insert cell
prettyConclusion = (d) => {
if(d == "success") return "✅ success"
if(d == "failure") return "⛔️ failure"
if(d == "cancelled") return "⬜️ cancelled"
return d
}
Insert cell
getTooltip = (data, {x, y}) =>
Plot.tooltip(data, {
x,
y,
dx: 10,
dy: 10,
content: d => ({
name: d.name,
run_number: d.run_number,
duration: durationFormat(d.minutes),
started: timeFormat(d.started_at),
conclusion: d.conclusion,
branch: d.branch,
author: d.author,
message: d.message
}),
stroke: null,
onclick: (event, i) => window.open(data[i].html_url, "_blank")
})
Insert cell
Insert cell
Plot = require("@observablehq/plot@0.1").then(addTooltip)
Insert cell
import {addTooltip} from "@fil/experimental-plot-tooltip-01"
Insert cell
import {swatches as Swatches} from "@d3/color-legend"
Insert cell
import {fetchWorkflows, fetchRuns, parseJobs, sampleWorkflows, sampleRuns, rateLimitSummary, hasApiKey, apiKeyStatus} from "@observablehq/github-actions-workflows-api"
Insert cell
import {toc} from "@observablehq/templates-table-of-instructions"
Insert cell
// For a notebook to access Secrets, it must statically reference one; this cell grants Secret access to the notebook from which we import the GitHub API helpers. `undefined` stops the Secret from appearing in the Inspector.
undefined && Secret("GITHUB_ACCESS_TOKEN")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more