2022-12-05 19:49:23 +00:00
|
|
|
local Config = require("lazy.core.config")
|
|
|
|
local Manage = require("lazy.manage")
|
|
|
|
local Util = require("lazy.util")
|
|
|
|
local Git = require("lazy.manage.git")
|
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
M.running = false
|
|
|
|
M.updated = {}
|
2022-12-13 09:07:36 +00:00
|
|
|
M.reported = {}
|
2022-12-05 19:49:23 +00:00
|
|
|
|
|
|
|
function M.start()
|
|
|
|
M.fast_check()
|
|
|
|
M.check()
|
|
|
|
end
|
|
|
|
|
2022-12-23 06:43:58 +00:00
|
|
|
---@param opts? {report:boolean} report defaults to true
|
|
|
|
function M.fast_check(opts)
|
|
|
|
opts = opts or {}
|
2022-12-05 19:49:23 +00:00
|
|
|
for _, plugin in pairs(Config.plugins) do
|
2022-12-21 13:39:08 +00:00
|
|
|
if not plugin.pin and plugin._.installed then
|
2022-12-31 15:01:59 +00:00
|
|
|
plugin._.updates = nil
|
2022-12-20 10:58:54 +00:00
|
|
|
local info = Git.info(plugin.dir)
|
2022-12-20 12:44:21 +00:00
|
|
|
local ok, target = pcall(Git.get_target, plugin)
|
2023-01-03 08:36:35 +00:00
|
|
|
if ok and info and target and not Git.eq(info, target) then
|
2022-12-31 15:01:59 +00:00
|
|
|
plugin._.updates = { from = info, to = target }
|
2022-12-20 10:58:54 +00:00
|
|
|
end
|
2022-12-05 19:49:23 +00:00
|
|
|
end
|
|
|
|
end
|
2022-12-24 08:22:46 +00:00
|
|
|
M.report(opts.report ~= false)
|
2022-12-05 19:49:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.check()
|
|
|
|
Manage.check({
|
|
|
|
show = false,
|
|
|
|
concurrency = Config.options.checker.concurrency,
|
|
|
|
}):wait(function()
|
|
|
|
M.report()
|
|
|
|
vim.defer_fn(M.check, Config.options.checker.frequency * 1000)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2022-12-24 08:22:46 +00:00
|
|
|
---@param notify? boolean
|
|
|
|
function M.report(notify)
|
2022-12-05 19:49:23 +00:00
|
|
|
local lines = {}
|
2022-12-13 09:07:36 +00:00
|
|
|
M.updated = {}
|
2022-12-05 19:49:23 +00:00
|
|
|
for _, plugin in pairs(Config.plugins) do
|
2022-12-31 15:01:59 +00:00
|
|
|
if plugin._.updates then
|
2022-12-05 19:49:23 +00:00
|
|
|
table.insert(M.updated, plugin.name)
|
2022-12-13 09:07:36 +00:00
|
|
|
if not vim.tbl_contains(M.reported, plugin.name) then
|
|
|
|
table.insert(lines, "- **" .. plugin.name .. "**")
|
|
|
|
table.insert(M.reported, plugin.name)
|
|
|
|
end
|
2022-12-05 19:49:23 +00:00
|
|
|
end
|
|
|
|
end
|
2022-12-24 08:22:46 +00:00
|
|
|
if #lines > 0 and notify and Config.options.checker.notify then
|
2022-12-05 19:49:23 +00:00
|
|
|
table.insert(lines, 1, "# Plugin Updates")
|
|
|
|
Util.info(lines)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|