feat(forge): add validate option for forge ref validation on write (#138)

Problem: Typos in forge refs like `gh:user/repo#42` silently persist —
there's no feedback when a ref points to a nonexistent issue.

Solution: Add `forge.validate` config option. When enabled, `diff.apply()`
returns new/changed `ForgeRef[]` and `forge.validate_refs()` fetches
metadata for each, logging specific warnings for not-found, auth, or
CLI-missing errors.
This commit is contained in:
Barrett Ruth 2026-03-11 12:23:20 -04:00 committed by GitHub
parent 61d84f85b8
commit f198358819
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 163 additions and 19 deletions

View file

@ -275,6 +275,68 @@ describe('diff', function()
assert.are.equal('completion', tasks[1].recur_mode)
end)
it('returns forge refs for new tasks', function()
local lines = {
'# Inbox',
'- [ ] Fix bug gh:user/repo#42',
}
local refs = diff.apply(lines, s)
assert.are.equal(1, #refs)
assert.are.equal('github', refs[1].forge)
assert.are.equal(42, refs[1].number)
end)
it('returns forge refs for changed refs on existing tasks', function()
s:add({ description = 'Fix bug gh:user/repo#1', _extra = {
_forge_ref = { forge = 'github', owner = 'user', repo = 'repo', type = 'issue', number = 1, url = '' },
} })
s:save()
local lines = {
'# Todo',
'/1/- [ ] Fix bug gh:user/repo#99',
}
local refs = diff.apply(lines, s)
assert.are.equal(1, #refs)
assert.are.equal(99, refs[1].number)
end)
it('returns empty when forge ref is unchanged', function()
s:add({ description = 'Fix bug gh:user/repo#42', _extra = {
_forge_ref = { forge = 'github', owner = 'user', repo = 'repo', type = 'issue', number = 42, url = '' },
} })
s:save()
local lines = {
'# Todo',
'/1/- [ ] Fix bug gh:user/repo#42',
}
local refs = diff.apply(lines, s)
assert.are.equal(0, #refs)
end)
it('returns empty for tasks without forge refs', function()
local lines = {
'# Inbox',
'- [ ] Plain task',
}
local refs = diff.apply(lines, s)
assert.are.equal(0, #refs)
end)
it('returns forge refs for duplicated tasks', function()
s:add({ description = 'Fix bug gh:user/repo#42', _extra = {
_forge_ref = { forge = 'github', owner = 'user', repo = 'repo', type = 'issue', number = 42, url = '' },
} })
s:save()
local lines = {
'# Todo',
'/1/- [ ] Fix bug gh:user/repo#42',
'/1/- [ ] Fix bug gh:user/repo#42',
}
local refs = diff.apply(lines, s)
assert.are.equal(1, #refs)
assert.are.equal(42, refs[1].number)
end)
it('clears priority when [N] is removed from buffer line', function()
s:add({ description = 'Task name', priority = 1 })
s:save()