Platform
Resources
Pricing
Sign in
Contact us
Simon Willison
Workspace
Fork
Public
By
Simon Willison
Edited
Jan 31, 2024
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
latest_commit_hash
=
{
if
(
!
fetchLatestCommit
)
{
return
;
}
if
(
!
resolved
)
{
return
;
}
const
url
=
`https://api.github.com/repos/${
resolved
}/commits`
;
const
data
=
await
(
await
fetch
(
url
)
)
.
json
(
)
;
return
data
[
0
]
.
sha
;
}
Insert cell
url
=
{
if
(
!
branch
||
!
resolved
)
{
return
null
;
}
if
(
branch
==
"main"
||
branch
==
"master"
)
{
return
`https://codeload.github.com/${
resolved
}/zip/refs/heads/${
branch
}`
;
}
return
`https://codeload.github.com/${
resolved
}/zip/${
branch
}`
;
}
Insert cell
resolved
=
{
const
simpleRepoRegex
=
/^[^\/]+\/[^\/]+$/
;
if
(
simpleRepoRegex
.
test
(
repo
)
)
{
return
repo
;
}
// Extract 'owner/repo' from a GitHub URL
const
urlRegex
=
/https:\/\/github\.com\/([^\/]+\/[^\/]+)/
;
const
match
=
repo
.
match
(
urlRegex
)
;
return
match
?
match
[
1
]
:
null
;
}
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
repo
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
branch
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
fetchLatestCommit
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
latest_commit_hash
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
url
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
resolved
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML