Skip to content

Commit

Permalink
feat: add healthchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
Willem Jan Noort committed Jun 22, 2024
1 parent c631083 commit f7a9a00
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions lua/adopure/health.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
local M = {}
local function check_pat_token()
local ok, response = pcall(function()
return require("adopure.config.internal"):access_token()
end)
if not ok then
vim.health.error(tostring(response))
return false
end
vim.health.ok("Pat token present;")
return true
end
local function check_context()
local context_ok, context = pcall(function()
return require("adopure.state").AdoContext:new()
end)
if not context_ok then
vim.health.error(tostring(context))
return false
end
local assert_ok, response = pcall(
assert,
context.organization_url and context.project_name and context.repository_name,
"Able to load context from git remote"
)
if not assert_ok then
vim.health.error(tostring(response))
return false
end
vim.health.ok("Ado context succesfully loaded;")
return true
end
local function check_token_in_context()
local context = require("adopure.state").AdoContext:new()
local ok, repository = pcall(require("adopure.api").get_repository, context)
if not ok or not repository then
vim.health.error(tostring(repository or "No repository found with pat_token in this context;"))
return false
end
vim.health.ok("Found repository with context and pat token;")
return true
end

local function check_dependency(dependency)
local ok, _ = pcall(require, dependency)
if not ok then
vim.health.error("Missing dependency: " .. dependency)
return
end
vim.health.ok("Installed dependency: " .. dependency)
end

function M.check()
vim.health.start("adopure.nvim")
for _, check in ipairs({ check_pat_token, check_context, check_token_in_context }) do
local pass = check()
if not pass then
return
end
end
for _, dependency in ipairs({ "telescope", "plenary" }) do
check_dependency(dependency)
end
end
return M

0 comments on commit f7a9a00

Please sign in to comment.