refactor(sync): extract backend interface, adapt gcal module
Problem: :Pending sync hardcodes Google Calendar — M.sync() does
pcall(require, 'pending.sync.gcal') and calls gcal.sync() directly.
The config has a flat gcal field. This prevents adding new sync backends
without modifying init.lua.
Solution: Define a backend interface contract (name, auth, sync, health
fields), refactor :Pending sync to dispatch via require('pending.sync.'
.. backend_name), add sync table to config with legacy gcal migration,
rename gcal.authorize to gcal.auth, add gcal.health for checkhealth,
and add tab completion for backend names and actions.
This commit is contained in:
parent
8d3d21b330
commit
7de9c23ec1
5 changed files with 85 additions and 18 deletions
|
|
@ -3,6 +3,8 @@ local store = require('pending.store')
|
|||
|
||||
local M = {}
|
||||
|
||||
M.name = 'gcal'
|
||||
|
||||
local BASE_URL = 'https://www.googleapis.com/calendar/v3'
|
||||
local TOKEN_URL = 'https://oauth2.googleapis.com/token'
|
||||
local AUTH_URL = 'https://accounts.google.com/o/oauth2/v2/auth'
|
||||
|
|
@ -22,7 +24,7 @@ local SCOPE = 'https://www.googleapis.com/auth/calendar'
|
|||
---@return table<string, any>
|
||||
local function gcal_config()
|
||||
local cfg = config.get()
|
||||
return cfg.gcal or {}
|
||||
return (cfg.sync and cfg.sync.gcal) or cfg.gcal or {}
|
||||
end
|
||||
|
||||
---@return string
|
||||
|
|
@ -199,7 +201,7 @@ local function get_access_token()
|
|||
end
|
||||
local tokens = load_tokens()
|
||||
if not tokens or not tokens.refresh_token then
|
||||
M.authorize()
|
||||
M.auth()
|
||||
tokens = load_tokens()
|
||||
if not tokens then
|
||||
return nil
|
||||
|
|
@ -218,7 +220,7 @@ local function get_access_token()
|
|||
return tokens.access_token
|
||||
end
|
||||
|
||||
function M.authorize()
|
||||
function M.auth()
|
||||
local creds = load_credentials()
|
||||
if not creds then
|
||||
vim.notify(
|
||||
|
|
@ -514,4 +516,18 @@ function M.sync()
|
|||
)
|
||||
end
|
||||
|
||||
---@return nil
|
||||
function M.health()
|
||||
if vim.fn.executable('curl') == 1 then
|
||||
vim.health.ok('curl found (required for gcal sync)')
|
||||
else
|
||||
vim.health.warn('curl not found (needed for gcal sync)')
|
||||
end
|
||||
if vim.fn.executable('openssl') == 1 then
|
||||
vim.health.ok('openssl found (required for gcal OAuth PKCE)')
|
||||
else
|
||||
vim.health.warn('openssl not found (needed for gcal OAuth)')
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue