refactor(forge): simplify auth gating and rename gitea_backend
Problem: forge auth/warning logic was scattered through `fetch_metadata` — per-API-call auth status checks, `_warned` flags, and `warn_missing_cli` conditionals on every fetch. Solution: replace `_warned` with `_auth` (cached per session), add `is_configured()` to skip unconfigured forges entirely, extract `check_auth()` for one-time auth verification, and strip `fetch_metadata` to a pure API caller returning `ForgeFetchError`. Gate `refresh` and new `validate_refs` with both checks. Rename `gitea_backend` to `gitea_forge`.
This commit is contained in:
parent
3af2e0d4c1
commit
17774b1355
4 changed files with 185 additions and 70 deletions
|
|
@ -330,7 +330,7 @@ describe('forge registry', function()
|
|||
end)
|
||||
|
||||
it('register() with custom backend resolves URLs', function()
|
||||
local custom = forge.gitea_backend({
|
||||
local custom = forge.gitea_forge({
|
||||
name = 'mygitea',
|
||||
shorthand = 'mg',
|
||||
default_host = 'gitea.example.com',
|
||||
|
|
@ -367,8 +367,8 @@ describe('forge registry', function()
|
|||
assert.same({ 'tea', 'api', '/repos/alice/proj/issues/7' }, args)
|
||||
end)
|
||||
|
||||
it('gitea_backend() creates a working backend', function()
|
||||
local b = forge.gitea_backend({
|
||||
it('gitea_forge() creates a working backend', function()
|
||||
local b = forge.gitea_forge({
|
||||
name = 'forgejo',
|
||||
shorthand = 'fj',
|
||||
default_host = 'forgejo.example.com',
|
||||
|
|
@ -396,7 +396,7 @@ describe('custom forge prefixes', function()
|
|||
local complete = require('pending.complete')
|
||||
|
||||
it('parses custom-length shorthand (3+ chars)', function()
|
||||
local custom = forge.gitea_backend({
|
||||
local custom = forge.gitea_forge({
|
||||
name = 'customforge',
|
||||
shorthand = 'cgf',
|
||||
default_host = 'custom.example.com',
|
||||
|
|
@ -458,6 +458,32 @@ describe('custom forge prefixes', function()
|
|||
end)
|
||||
end)
|
||||
|
||||
describe('is_configured', function()
|
||||
it('returns false when vim.g.pending is nil', function()
|
||||
vim.g.pending = nil
|
||||
assert.is_false(forge.is_configured('github'))
|
||||
end)
|
||||
|
||||
it('returns false when forge key is absent', function()
|
||||
vim.g.pending = { forge = { close = true } }
|
||||
assert.is_false(forge.is_configured('github'))
|
||||
vim.g.pending = nil
|
||||
end)
|
||||
|
||||
it('returns true when forge key is present', function()
|
||||
vim.g.pending = { forge = { github = {} } }
|
||||
assert.is_true(forge.is_configured('github'))
|
||||
assert.is_false(forge.is_configured('gitlab'))
|
||||
vim.g.pending = nil
|
||||
end)
|
||||
|
||||
it('returns true for non-empty forge config', function()
|
||||
vim.g.pending = { forge = { gitlab = { icon = '' } } }
|
||||
assert.is_true(forge.is_configured('gitlab'))
|
||||
vim.g.pending = nil
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('forge diff integration', function()
|
||||
local store = require('pending.store')
|
||||
local diff = require('pending.diff')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue