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:
parent
494e26d7a1
commit
a4f782a5fb
6 changed files with 163 additions and 19 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue