## Problem
Credentials were stored as plaintext JSON in
`stdpath('data')/cp-nvim.json`, with no integration with system
credential managers.
## Solution
Replace file-based credential storage with `git credential
fill/approve/reject`, delegating to whatever credential helper the user
has configured (`cache`, `store`, `libsecret`, macOS Keychain, etc.).
- New `lua/cp/git_credential.lua` module wrapping the git credential
protocol
- All credential consumers (`credentials.lua`, `submit.lua`,
`scraper.lua`) use `git_credential` directly — `cache.lua` no longer
handles credentials
- CSES API token packed into the password field (`password<TAB>token`)
so it works with helpers that ignore the `path` field
- `has_helper()` guard on `:CP login`, `:CP logout`, and `:CP submit`
with an error message if no helper is configured
- Healthcheck split into `[required]`/`[optional]` sections; git version
and credential helper status shown
- `git` checked at startup in `check_required_runtime()`
- Cache version system (`CACHE_VERSION`, v1→v2 migration) removed — the
cache file is now a plain JSON blob
- `:CP` command gets `bar = true`
108 lines
3.5 KiB
Lua
108 lines
3.5 KiB
Lua
local M = {}
|
|
|
|
local utils = require('cp.utils')
|
|
|
|
local function check()
|
|
vim.health.start('cp.nvim [required] ~')
|
|
|
|
local nvim_ver = vim.version()
|
|
local nvim_str = ('%d.%d.%d'):format(nvim_ver.major, nvim_ver.minor, nvim_ver.patch)
|
|
if vim.fn.has('nvim-0.10.0') == 1 then
|
|
vim.health.ok('Neovim >= 0.10.0: ' .. nvim_str)
|
|
else
|
|
vim.health.error('Neovim >= 0.10.0 required, found ' .. nvim_str)
|
|
end
|
|
|
|
local uname = vim.uv.os_uname()
|
|
if uname.sysname == 'Windows_NT' then
|
|
vim.health.error('Windows is not supported')
|
|
end
|
|
|
|
local time_cap = utils.time_capability()
|
|
if time_cap.ok then
|
|
vim.health.ok('GNU time found: ' .. time_cap.path)
|
|
else
|
|
vim.health.error('GNU time not found: ' .. (time_cap.reason or ''))
|
|
end
|
|
|
|
local timeout_cap = utils.timeout_capability()
|
|
if timeout_cap.ok then
|
|
vim.health.ok('GNU timeout found: ' .. timeout_cap.path)
|
|
else
|
|
vim.health.error('GNU timeout not found: ' .. (timeout_cap.reason or ''))
|
|
end
|
|
|
|
vim.health.start('cp.nvim [optional] ~')
|
|
|
|
utils.setup_python_env()
|
|
|
|
if utils.is_nix_build() then
|
|
local source = utils.is_nix_discovered() and 'runtime discovery' or 'flake install'
|
|
vim.health.ok('Nix Python environment detected (' .. source .. ')')
|
|
local py = utils.get_nix_python()
|
|
vim.health.info('Python: ' .. py)
|
|
local r = vim.system({ py, '--version' }, { text = true }):wait()
|
|
if r.code == 0 then
|
|
vim.health.info('Python version: ' .. r.stdout:gsub('\n', ''))
|
|
end
|
|
else
|
|
if vim.fn.executable('uv') == 1 then
|
|
vim.health.ok('uv executable found')
|
|
local r = vim.system({ 'uv', '--version' }, { text = true }):wait()
|
|
if r.code == 0 then
|
|
vim.health.info('uv version: ' .. r.stdout:gsub('\n', ''))
|
|
end
|
|
else
|
|
vim.health.warn('uv not found (install https://docs.astral.sh/uv/ for scraping)')
|
|
end
|
|
|
|
if vim.fn.executable('nix') == 1 then
|
|
vim.health.info('nix available but Python environment not resolved via nix')
|
|
end
|
|
|
|
local plugin_path = utils.get_plugin_path()
|
|
local venv_dir = plugin_path .. '/.venv'
|
|
if vim.fn.isdirectory(venv_dir) == 1 then
|
|
vim.health.ok('Python virtual environment found at ' .. venv_dir)
|
|
else
|
|
vim.health.info('Python virtual environment not set up (created on first scrape)')
|
|
end
|
|
end
|
|
|
|
if vim.fn.executable('git') == 1 then
|
|
local r = vim.system({ 'git', '--version' }, { text = true }):wait()
|
|
if r.code == 0 then
|
|
local major, minor, patch = r.stdout:match('(%d+)%.(%d+)%.(%d+)')
|
|
major, minor, patch = tonumber(major), tonumber(minor), tonumber(patch or 0)
|
|
local ver_str = ('%d.%d.%d'):format(major or 0, minor or 0, patch or 0)
|
|
if
|
|
major
|
|
and (major > 1 or (major == 1 and minor > 7) or (major == 1 and minor == 7 and patch >= 9))
|
|
then
|
|
vim.health.ok('git >= 1.7.9: ' .. ver_str)
|
|
else
|
|
vim.health.warn('git >= 1.7.9 required for credential storage, found ' .. ver_str)
|
|
end
|
|
end
|
|
|
|
local helper = vim.system({ 'git', 'config', 'credential.helper' }, { text = true }):wait()
|
|
if helper.code == 0 and helper.stdout and vim.trim(helper.stdout) ~= '' then
|
|
vim.health.ok('git credential helper: ' .. vim.trim(helper.stdout))
|
|
else
|
|
vim.health.warn('no git credential helper configured (required for login/submit)')
|
|
end
|
|
else
|
|
vim.health.warn('git not found (required for credential storage)')
|
|
end
|
|
end
|
|
|
|
---@return nil
|
|
function M.check()
|
|
local version = require('cp.version')
|
|
vim.health.start('cp.nvim health check ~')
|
|
vim.health.info('Version: ' .. version.version)
|
|
|
|
check()
|
|
end
|
|
|
|
return M
|