From d1127f3e9b7e6b4da4ff01a5166ed2cc0830732a Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 7 Mar 2026 19:46:32 -0500 Subject: [PATCH] refactor: migrate credential consumers to `git_credential` Problem: `credentials.lua`, `submit.lua`, and `scraper.lua` all routed through `cache.get/set/clear_credentials`, which no longer exists. Solution: replace all `cache` credential calls with direct `git_credential.get/store/reject` calls. Remove unused `cache` imports where applicable. --- lua/cp/credentials.lua | 17 +++++++++-------- lua/cp/scraper.lua | 4 ++-- lua/cp/submit.lua | 8 ++++---- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lua/cp/credentials.lua b/lua/cp/credentials.lua index 1d7e399..1d5c759 100644 --- a/lua/cp/credentials.lua +++ b/lua/cp/credentials.lua @@ -1,7 +1,7 @@ local M = {} -local cache = require('cp.cache') local constants = require('cp.constants') +local git_credential = require('cp.git_credential') local logger = require('cp.log') local state = require('cp.state') @@ -40,14 +40,14 @@ local function prompt_and_login(platform, display) end, function(result) vim.schedule(function() if result.success then - cache.set_credentials(platform, credentials) + git_credential.store(platform, credentials) logger.log( display .. ' login successful', { level = vim.log.levels.INFO, override = true } ) else local err = result.error or 'unknown error' - cache.clear_credentials(platform) + git_credential.reject(platform, credentials) logger.log( display .. ' login failed: ' .. (constants.LOGIN_ERRORS[err] or err), { level = vim.log.levels.ERROR } @@ -73,8 +73,7 @@ function M.login(platform) local display = constants.PLATFORM_DISPLAY_NAMES[platform] or platform - cache.load() - local existing = cache.get_credentials(platform) or {} + local existing = git_credential.get(platform) or {} if existing.username and existing.password then local scraper = require('cp.scraper') @@ -91,7 +90,7 @@ function M.login(platform) { level = vim.log.levels.INFO, override = true } ) else - cache.clear_credentials(platform) + git_credential.reject(platform, existing) prompt_and_login(platform, display) end end) @@ -113,8 +112,10 @@ function M.logout(platform) return end local display = constants.PLATFORM_DISPLAY_NAMES[platform] or platform - cache.load() - cache.clear_credentials(platform) + local existing = git_credential.get(platform) + if existing then + git_credential.reject(platform, existing) + end local cookie_file = constants.COOKIE_FILE if vim.fn.filereadable(cookie_file) == 1 then local ok, data = pcall(vim.fn.json_decode, vim.fn.readfile(cookie_file, 'b')) diff --git a/lua/cp/scraper.lua b/lua/cp/scraper.lua index 4ad46bc..adb3225 100644 --- a/lua/cp/scraper.lua +++ b/lua/cp/scraper.lua @@ -347,7 +347,7 @@ function M.login(platform, credentials, on_status, callback) stdin = vim.json.encode(credentials), on_event = function(ev) if ev.credentials ~= nil and next(ev.credentials) ~= nil then - require('cp.cache').set_credentials(platform, ev.credentials) + require('cp.git_credential').store(platform, ev.credentials) end if ev.status ~= nil then if type(on_status) == 'function' then @@ -395,7 +395,7 @@ function M.submit( stdin = vim.json.encode(credentials), on_event = function(ev) if ev.credentials ~= nil and next(ev.credentials) ~= nil then - require('cp.cache').set_credentials(platform, ev.credentials) + require('cp.git_credential').store(platform, ev.credentials) end if ev.status ~= nil then if type(on_status) == 'function' then diff --git a/lua/cp/submit.lua b/lua/cp/submit.lua index 529456d..4c5eb70 100644 --- a/lua/cp/submit.lua +++ b/lua/cp/submit.lua @@ -1,8 +1,8 @@ local M = {} -local cache = require('cp.cache') local config = require('cp.config') local constants = require('cp.constants') +local git_credential = require('cp.git_credential') local logger = require('cp.log') local state = require('cp.state') @@ -14,7 +14,7 @@ local STATUS_MSGS = { } local function prompt_credentials(platform, callback) - local saved = cache.get_credentials(platform) + local saved = git_credential.get(platform) if saved and saved.username and saved.password then callback(saved) return @@ -109,12 +109,12 @@ function M.submit(opts) function(result) vim.schedule(function() if result and result.success then - cache.set_credentials(platform, creds) + git_credential.store(platform, creds) logger.log('Submitted successfully', { level = vim.log.levels.INFO, override = true }) else local err = result and result.error or 'unknown error' if err == 'bad_credentials' or err:match('^Login failed') then - cache.clear_credentials(platform) + git_credential.reject(platform, creds) logger.log( 'Submit failed: ' .. (constants.LOGIN_ERRORS[err] or err), { level = vim.log.levels.ERROR }