Skip to content

Commit

Permalink
feat: 🎸 copy commit to clipboard if commit exist
Browse files Browse the repository at this point in the history
  • Loading branch information
IWANABETHATGUY committed Jun 25, 2024
1 parent 006f115 commit 8a29d83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 16 additions & 10 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function main() {

for (let [
series,
{ unit, data, commit, timestamp, metric },
{ unit, data, commit, timestamp, metric, repoUrl },
] of Object.entries(normalizedEntryDict)) {
let plotName = series;
let seriesName: string;
Expand Down Expand Up @@ -80,13 +80,14 @@ async function main() {
plot?.data.push({
name: key,
line: {
// width:1.5,
// @ts-ignore
shape: 'hv'
},
x: timestamp.map((n) => new Date(n)),
y: value,
hovertext: commit,
hovertemplate: `%{y} ${unit}<br>(%{hovertext})`,
repoUrl: commit,
});
});
}
Expand All @@ -110,15 +111,19 @@ async function main() {

// @ts-ignore
Plotly.newPlot(plotDiv, definition.data, definition.layout);
// plotDiv.on("plotly_click", (data) => {
// const commit_hash: string = (data.points[0] as any).hovertext;
// const url = `https://github.com/rolldown-rs/rolldown/commit/${commit_hash}`;
// const notification_text = `Commit <b>${commit_hash}</b> URL copied to clipboard`;
// navigator.clipboard.writeText(url);
// show_notification(notification_text);
// });
plotDiv.on("plotly_click", (data) => {
const commit_hash: string = (data.points[0] as any).hovertext;
if (!commit_hash) {
return;
}
let repoUrl = (data.points[0] as any).repoUrl ?? "https://github.com/rolldown/rolldown";
const url = `${repoUrl.trimEnd("/")}/commit/${commit_hash}`;
console.log(`url: `, url)
const notification_text = `Commit <b>${commit_hash}</b> URL copied to clipboard`;
navigator.clipboard.writeText(url);
show_notification(notification_text);
});
metricContainerMap.get(metric)?.appendChild(plotDiv);
// bodyElement.appendChild(plotDiv);
}
}

Expand Down Expand Up @@ -174,6 +179,7 @@ function normalizeEntryDict(
timestamp,
unit: value[0].unit,
metric: value[0].metric,
repoUrl: value[0].repoUrl,
};
});
return [map, metricSet];
Expand Down
2 changes: 2 additions & 0 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Entry {
commit: string;
unit: string;
records: Record<string, number>;
repoUrl?: String;
}

export interface Metric {
Expand All @@ -13,6 +14,7 @@ export interface Metric {
data: Record<string, number[]>;
commit: string[];
timestamp: number[];
repoUrl?: string;
}

export interface Plots {
Expand Down

0 comments on commit 8a29d83

Please sign in to comment.