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

@ -82,14 +82,26 @@ function M.parse_buffer(lines)
return result
end
---@param a? pending.ForgeRef
---@param b? pending.ForgeRef
---@return boolean
local function refs_equal(a, b)
if not a or not b then
return false
end
return a.forge == b.forge and a.owner == b.owner
and a.repo == b.repo and a.number == b.number
end
---@param lines string[]
---@param s pending.Store
---@param hidden_ids? table<integer, true>
---@return nil
---@return pending.ForgeRef[]
function M.apply(lines, s, hidden_ids)
local parsed = M.parse_buffer(lines)
local now = timestamp()
local data = s:data()
local new_refs = {} ---@type pending.ForgeRef[]
local old_by_id = {}
for _, task in ipairs(data.tasks) do
@ -120,6 +132,9 @@ function M.apply(lines, s, hidden_ids)
order = order_counter,
_extra = entry.forge_ref and { _forge_ref = entry.forge_ref } or nil,
})
if entry.forge_ref then
table.insert(new_refs, entry.forge_ref)
end
else
seen_ids[entry.id] = true
local task = old_by_id[entry.id]
@ -154,6 +169,10 @@ function M.apply(lines, s, hidden_ids)
end
end
if entry.forge_ref ~= nil then
local old_ref = task._extra and task._extra._forge_ref or nil
if not refs_equal(old_ref, entry.forge_ref) then
table.insert(new_refs, entry.forge_ref)
end
if not task._extra then
task._extra = {}
end
@ -188,6 +207,9 @@ function M.apply(lines, s, hidden_ids)
order = order_counter,
_extra = entry.forge_ref and { _forge_ref = entry.forge_ref } or nil,
})
if entry.forge_ref then
table.insert(new_refs, entry.forge_ref)
end
end
::continue::
@ -202,6 +224,7 @@ function M.apply(lines, s, hidden_ids)
end
s:save()
return new_refs
end
return M