Compare commits
No commits in common. "4ad1d52e2d56c160145abd675cc7798096d7f7d8" and "991ac5b4673d370a2d06dabf47843e21957fbd67" have entirely different histories.
4ad1d52e2d
...
991ac5b467
2 changed files with 27 additions and 64 deletions
|
|
@ -154,21 +154,6 @@ local function unlink_remote(task, extra, now_ts)
|
||||||
task.modified = now_ts
|
task.modified = now_ts
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param parts {[1]: integer, [2]: string}[]
|
|
||||||
---@return string
|
|
||||||
local function fmt_counts(parts)
|
|
||||||
local items = {}
|
|
||||||
for _, p in ipairs(parts) do
|
|
||||||
if p[1] > 0 then
|
|
||||||
table.insert(items, p[1] .. ' ' .. p[2])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if #items == 0 then
|
|
||||||
return 'nothing to do'
|
|
||||||
end
|
|
||||||
return table.concat(items, ' | ')
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param callback fun(access_token: string): nil
|
---@param callback fun(access_token: string): nil
|
||||||
local function with_token(callback)
|
local function with_token(callback)
|
||||||
oauth.async(function()
|
oauth.async(function()
|
||||||
|
|
@ -191,7 +176,7 @@ function M.push()
|
||||||
|
|
||||||
local s = require('pending').store()
|
local s = require('pending').store()
|
||||||
local now_ts = os.date('!%Y-%m-%dT%H:%M:%SZ') --[[@as string]]
|
local now_ts = os.date('!%Y-%m-%dT%H:%M:%SZ') --[[@as string]]
|
||||||
local created, updated, deleted, failed = 0, 0, 0, 0
|
local created, updated, deleted = 0, 0, 0
|
||||||
|
|
||||||
for _, task in ipairs(s:tasks()) do
|
for _, task in ipairs(s:tasks()) do
|
||||||
local extra = task._extra or {}
|
local extra = task._extra or {}
|
||||||
|
|
@ -212,7 +197,6 @@ function M.push()
|
||||||
delete_event(access_token, cal_id --[[@as string]], event_id --[[@as string]])
|
delete_event(access_token, cal_id --[[@as string]], event_id --[[@as string]])
|
||||||
if del_err then
|
if del_err then
|
||||||
log.warn('gcal delete failed: ' .. del_err)
|
log.warn('gcal delete failed: ' .. del_err)
|
||||||
failed = failed + 1
|
|
||||||
else
|
else
|
||||||
unlink_remote(task, extra, now_ts)
|
unlink_remote(task, extra, now_ts)
|
||||||
deleted = deleted + 1
|
deleted = deleted + 1
|
||||||
|
|
@ -230,7 +214,6 @@ function M.push()
|
||||||
local upd_err = update_event(access_token, cal_id, event_id, task)
|
local upd_err = update_event(access_token, cal_id, event_id, task)
|
||||||
if upd_err then
|
if upd_err then
|
||||||
log.warn('gcal update failed: ' .. upd_err)
|
log.warn('gcal update failed: ' .. upd_err)
|
||||||
failed = failed + 1
|
|
||||||
else
|
else
|
||||||
updated = updated + 1
|
updated = updated + 1
|
||||||
end
|
end
|
||||||
|
|
@ -238,12 +221,10 @@ function M.push()
|
||||||
local lid, lid_err = find_or_create_calendar(access_token, cat, calendars)
|
local lid, lid_err = find_or_create_calendar(access_token, cat, calendars)
|
||||||
if lid_err or not lid then
|
if lid_err or not lid then
|
||||||
log.warn('gcal calendar failed: ' .. (lid_err or 'unknown'))
|
log.warn('gcal calendar failed: ' .. (lid_err or 'unknown'))
|
||||||
failed = failed + 1
|
|
||||||
else
|
else
|
||||||
local new_id, create_err = create_event(access_token, lid, task)
|
local new_id, create_err = create_event(access_token, lid, task)
|
||||||
if create_err then
|
if create_err then
|
||||||
log.warn('gcal create failed: ' .. create_err)
|
log.warn('gcal create failed: ' .. create_err)
|
||||||
failed = failed + 1
|
|
||||||
elseif new_id then
|
elseif new_id then
|
||||||
if not task._extra then
|
if not task._extra then
|
||||||
task._extra = {}
|
task._extra = {}
|
||||||
|
|
@ -264,12 +245,7 @@ function M.push()
|
||||||
if buffer.bufnr() and vim.api.nvim_buf_is_valid(buffer.bufnr()) then
|
if buffer.bufnr() and vim.api.nvim_buf_is_valid(buffer.bufnr()) then
|
||||||
buffer.render(buffer.bufnr())
|
buffer.render(buffer.bufnr())
|
||||||
end
|
end
|
||||||
log.info('gcal push: ' .. fmt_counts({
|
log.info(string.format('Google Calendar pushed — +%d ~%d -%d', created, updated, deleted))
|
||||||
{ created, 'added' },
|
|
||||||
{ updated, 'updated' },
|
|
||||||
{ deleted, 'removed' },
|
|
||||||
{ failed, 'failed' },
|
|
||||||
}))
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -195,21 +195,6 @@ local function unlink_remote(task, now_ts)
|
||||||
task.modified = now_ts
|
task.modified = now_ts
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param parts {[1]: integer, [2]: string}[]
|
|
||||||
---@return string
|
|
||||||
local function fmt_counts(parts)
|
|
||||||
local items = {}
|
|
||||||
for _, p in ipairs(parts) do
|
|
||||||
if p[1] > 0 then
|
|
||||||
table.insert(items, p[1] .. ' ' .. p[2])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if #items == 0 then
|
|
||||||
return 'nothing to do'
|
|
||||||
end
|
|
||||||
return table.concat(items, ' | ')
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param task pending.Task
|
---@param task pending.Task
|
||||||
---@return table
|
---@return table
|
||||||
local function task_to_gtask(task)
|
local function task_to_gtask(task)
|
||||||
|
|
@ -465,12 +450,9 @@ function M.push()
|
||||||
if buffer.bufnr() and vim.api.nvim_buf_is_valid(buffer.bufnr()) then
|
if buffer.bufnr() and vim.api.nvim_buf_is_valid(buffer.bufnr()) then
|
||||||
buffer.render(buffer.bufnr())
|
buffer.render(buffer.bufnr())
|
||||||
end
|
end
|
||||||
log.info('gtasks push: ' .. fmt_counts({
|
log.info(
|
||||||
{ created, 'added' },
|
string.format('Google Tasks pushed — +%d ~%d -%d !%d', created, updated, deleted, failed)
|
||||||
{ updated, 'updated' },
|
)
|
||||||
{ deleted, 'deleted' },
|
|
||||||
{ failed, 'failed' },
|
|
||||||
}))
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -492,12 +474,15 @@ function M.pull()
|
||||||
if buffer.bufnr() and vim.api.nvim_buf_is_valid(buffer.bufnr()) then
|
if buffer.bufnr() and vim.api.nvim_buf_is_valid(buffer.bufnr()) then
|
||||||
buffer.render(buffer.bufnr())
|
buffer.render(buffer.bufnr())
|
||||||
end
|
end
|
||||||
log.info('gtasks pull: ' .. fmt_counts({
|
log.info(
|
||||||
{ created, 'added' },
|
string.format(
|
||||||
{ updated, 'updated' },
|
'Google Tasks pulled — +%d ~%d !%d, unlinked: %d',
|
||||||
{ unlinked, 'unlinked' },
|
created,
|
||||||
{ failed, 'failed' },
|
updated,
|
||||||
}))
|
failed,
|
||||||
|
unlinked
|
||||||
|
)
|
||||||
|
)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -521,17 +506,19 @@ function M.sync()
|
||||||
if buffer.bufnr() and vim.api.nvim_buf_is_valid(buffer.bufnr()) then
|
if buffer.bufnr() and vim.api.nvim_buf_is_valid(buffer.bufnr()) then
|
||||||
buffer.render(buffer.bufnr())
|
buffer.render(buffer.bufnr())
|
||||||
end
|
end
|
||||||
log.info('gtasks sync — push: ' .. fmt_counts({
|
log.info(
|
||||||
{ pushed_create, 'added' },
|
string.format(
|
||||||
{ pushed_update, 'updated' },
|
'Google Tasks synced — push: +%d ~%d -%d !%d, pull: +%d ~%d !%d, unlinked: %d',
|
||||||
{ pushed_delete, 'deleted' },
|
pushed_create,
|
||||||
{ pushed_failed, 'failed' },
|
pushed_update,
|
||||||
}) .. ' pull: ' .. fmt_counts({
|
pushed_delete,
|
||||||
{ pulled_create, 'added' },
|
pushed_failed,
|
||||||
{ pulled_update, 'updated' },
|
pulled_create,
|
||||||
{ unlinked, 'unlinked' },
|
pulled_update,
|
||||||
{ pulled_failed, 'failed' },
|
pulled_failed,
|
||||||
}))
|
unlinked
|
||||||
|
)
|
||||||
|
)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue