refactor(forge): extract ForgeBackend class and registry
Problem: adding a new forge required touching 5 lookup tables (`FORGE_HOSTS`, `FORGE_CLI`, `FORGE_AUTH_CMD`, `SHORTHAND_PREFIX`, `_warned_forges`) and every branching site in `_api_args`, `fetch_metadata`, and `parse_ref`. Solution: introduce a `ForgeBackend` class with `parse_url`, `api_args`, and `parse_state` methods, plus a `register()` / `backends()` registry. New forges (Gitea, Forgejo) are a single `register()` call via the `gitea_backend()` convenience constructor.
This commit is contained in:
parent
ecacb62674
commit
0033b26e38
4 changed files with 380 additions and 186 deletions
|
|
@ -47,16 +47,12 @@ function M.check()
|
|||
end
|
||||
|
||||
vim.health.start('pending.nvim: forge')
|
||||
local forge_clis = {
|
||||
{ cmd = 'gh', name = 'GitHub', hint = 'gh auth login' },
|
||||
{ cmd = 'glab', name = 'GitLab', hint = 'glab auth login' },
|
||||
{ cmd = 'tea', name = 'Codeberg', hint = 'tea login add' },
|
||||
}
|
||||
for _, cli in ipairs(forge_clis) do
|
||||
if vim.fn.executable(cli.cmd) == 1 then
|
||||
vim.health.ok(('%s found'):format(cli.cmd))
|
||||
local forge = require('pending.forge')
|
||||
for _, backend in ipairs(forge.backends()) do
|
||||
if vim.fn.executable(backend.cli) == 1 then
|
||||
vim.health.ok(('%s found'):format(backend.cli))
|
||||
else
|
||||
vim.health.warn(('%s not found — run `%s`'):format(cli.cmd, cli.hint))
|
||||
vim.health.warn(('%s not found — run `%s`'):format(backend.cli, backend.auth_cmd))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue