fix(gh.item): better method to extract repo from gh url. Closes #2418

This commit is contained in:
Folke Lemaitre 2025-11-03 08:16:22 +01:00
parent f75f307af3
commit 52d544cc64
No known key found for this signature in database
GPG key ID: 9B52594D560070AB

View file

@ -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