refactor(forge): replace curl/token auth with CLI-native API calls

Problem: Forge metadata fetching required manual token management —
config fields, CLI token extraction, and curl with auth headers. Each
forge had a different auth path, and Codeberg had no CLI support at all.

Solution: Delete `get_token()` and `_api_url()`, replace with
`_api_args()` that builds `gh api`, `glab api`, or `tea api` arg
arrays. The CLIs handle auth internally. Add `warn_missing_cli` config
(default true) that warns once per forge per session on failure. Add
forge CLI checks to `:checkhealth`. Remove `token` from config/docs.
This commit is contained in:
Barrett Ruth 2026-03-10 21:42:55 -04:00
parent 54f2eb50d9
commit ecacb62674
5 changed files with 81 additions and 94 deletions

View file

@ -186,9 +186,9 @@ describe('forge', function()
end)
end)
describe('_api_url', function()
it('builds GitHub API URL', function()
local url = forge._api_url({
describe('_api_args', function()
it('builds GitHub CLI args', function()
local args = forge._api_args({
forge = 'github',
owner = 'user',
repo = 'repo',
@ -196,11 +196,11 @@ describe('forge', function()
number = 42,
url = '',
})
assert.equals('https://api.github.com/repos/user/repo/issues/42', url)
assert.same({ 'gh', 'api', '/repos/user/repo/issues/42' }, args)
end)
it('builds GitLab API URL for issue', function()
local url = forge._api_url({
it('builds GitLab CLI args for issue', function()
local args = forge._api_args({
forge = 'gitlab',
owner = 'group',
repo = 'project',
@ -208,11 +208,11 @@ describe('forge', function()
number = 15,
url = '',
})
assert.equals('https://gitlab.com/api/v4/projects/group%2Fproject/issues/15', url)
assert.same({ 'glab', 'api', '/projects/group%2Fproject/issues/15' }, args)
end)
it('builds GitLab API URL for merge request', function()
local url = forge._api_url({
it('builds GitLab CLI args for merge request', function()
local args = forge._api_args({
forge = 'gitlab',
owner = 'group',
repo = 'project',
@ -220,11 +220,11 @@ describe('forge', function()
number = 5,
url = '',
})
assert.equals('https://gitlab.com/api/v4/projects/group%2Fproject/merge_requests/5', url)
assert.same({ 'glab', 'api', '/projects/group%2Fproject/merge_requests/5' }, args)
end)
it('builds Codeberg API URL', function()
local url = forge._api_url({
it('builds Codeberg CLI args', function()
local args = forge._api_args({
forge = 'codeberg',
owner = 'user',
repo = 'repo',
@ -232,7 +232,7 @@ describe('forge', function()
number = 3,
url = '',
})
assert.equals('https://codeberg.org/api/v1/repos/user/repo/issues/3', url)
assert.same({ 'tea', 'api', '/repos/user/repo/issues/3' }, args)
end)
end)