fix(lib): unhandled error when no gh CLI present

We did not correctly handle the case if the `gh` CLI was not present,
since `process.spawn` errors. We now wrap it in a `Result.try` and
handle that as required.
This commit is contained in:
Erica Marigold 2024-12-25 15:56:39 +00:00
parent aba182cea5
commit ed8d5594b9
Signed by: DevComp
GPG key ID: 429EF1C337871656

View file

@ -140,14 +140,16 @@ end
local function getGithubToken(): Option<string>
return Option.from(process.env.GITHUB_TOKEN):orElse(function()
local child = process.spawn("gh", { "auth", "token" })
if not child.ok then
return Option.None
end
return ResultExt.ok(Result.try(process.spawn, "gh", { "auth", "token" }))
:andThen(function(child: process.SpawnResult)
if not child.ok then
return Option.None
end
-- Remove newlines and other control characters
local token = string.gsub(child.stdout, "%s+", "")
return Option.Some(token)
-- Remove newlines and other control characters
local token = string.gsub(child.stdout, "%s+", "")
return Option.Some(token)
end)
end)
end