Skip to content

Commit

Permalink
improve URL parsing in tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
joneugster committed Aug 25, 2024
1 parent 4a226a5 commit ec36e1a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions client/src/Popups/Tools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,17 @@ const ToolTip: FC<{
if (loaded) { return }
setLoaded(true)

// Hack: construct github api URL from repo URL
let githubUrl = pkg.url.replace('github.com/', 'api.github.com/repos/') + `/commits/${pkg.rev}`
// construct github api URL from repo URL
let m = pkg.url.match(/github.com\/([^\/]+)\/([^\/\.]+)/i) // exclude '\.' to strip potential '.git' at the end
if (!m || m.length < 2) {
console.warn(`[LeanWeb]: cannot parse package url`, pkg.url)
setError('Not Found')
return
}

let githubUrl = `https://api.github.com/repos/${m![1]}/${m![2]}/commits/${pkg.rev}`

pkg.url.replace('github.com/', 'api.github.com/repos/') + `/commits/${pkg.rev}`
console.debug(`[LeanWeb]: fetch from ${githubUrl}`)

fetch(githubUrl).then(response => {
Expand Down

0 comments on commit ec36e1a

Please sign in to comment.