mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
fix(gh.item): better method to extract repo from gh url. Closes #2418
This commit is contained in:
parent
f75f307af3
commit
52d544cc64
1 changed files with 7 additions and 1 deletions
|
|
@ -89,7 +89,7 @@ function M:update(data, fields)
|
|||
self.fields[field] = true
|
||||
end
|
||||
if not self.repo and item.url then
|
||||
local repo = item.url:match("github%.com/([^/]+/[^/]+)/")
|
||||
local repo = M.get_repo(item.url)
|
||||
if repo then
|
||||
self.repo = repo
|
||||
end
|
||||
|
|
@ -150,4 +150,10 @@ function M.to_uri(item)
|
|||
return ("gh://%s/%s/%s"):format(item.repo or "", assert(item.type), tostring(assert(item.number)))
|
||||
end
|
||||
|
||||
---@param url string
|
||||
function M.get_repo(url)
|
||||
local path = url:find("^http") and url:gsub("^https?://[^/]+/", "") or url:gsub("^[^/]+/", "")
|
||||
return path:match("([^/]+/[^/]+)") --[[@as string?]]
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue