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
|
|
|
|
|
|
|
|
function M.fast_check()
|
|
|
|
for _, plugin in pairs(Config.plugins) do
|
2022-12-20 10:58:54 +00:00
|
|
|
if plugin._.installed then
|
|
|
|
plugin._.has_updates = nil
|
|
|
|
local info = Git.info(plugin.dir)
|
|
|
|
local target = Git.get_target(plugin)
|
|
|
|
if info and target and info.commit ~= target.commit then
|
|
|
|
plugin._.has_updates = true
|
|
|
|
end
|
2022-12-05 19:49:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
M.report()
|
|
|
|
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
|
|
|
|
|
|
|
|
function M.report()
|
|
|
|
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-13 09:07:36 +00:00
|
|
|
if plugin._.has_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
|
|
|
|
if #lines > 0 and Config.options.checker.notify then
|
|
|
|
table.insert(lines, 1, "# Plugin Updates")
|
|
|
|
Util.info(lines)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|