add gerrit onhover notification

This commit is contained in:
Pavel Makhov 2019-09-23 20:48:27 -04:00
parent 7403bdb0f6
commit 405e8b5d12
1 changed files with 21 additions and 27 deletions

View File

@ -15,60 +15,53 @@ local spawn = require("awful.spawn")
local naughty = require("naughty") local naughty = require("naughty")
local path_to_icons = "/usr/share/icons/Arc/status/symbolic/" local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
--local CMD = [[bash -c "curl -s --request GET --netrc https://%s/a/changes/\\?q\\=%s | tail -n +2 | jq ' . | length'"]]
local CMD = [[bash -c "curl -s --request GET --netrc https://%s/a/changes/\\?q\\=%s | tail -n +2"]] local GET_CHANGES_CMD = [[bash -c "curl -s -X GET -n https://%s/a/changes/\\?q\\=%s | tail -n +2"]]
local GET_USERNAME_CMD = [[bash -c "curl -s -X GET -n https://%s/accounts/%s/name | tail -n +2 | sed 's/\"//g'"]]
local gerrit_widget = {} local gerrit_widget = {}
local name_dict = {}
local function worker(args) local function worker(args)
local args = args or {} local args = args or {}
local host = args.host or naughty.notify{preset = naughty.config.presets.critical, text = 'Gerrit host is unknown'} local host = args.host or naughty.notify{preset = naughty.config.presets.critical, text = 'Gerrit host is unknown'}
local query = args.query or 'status:open+AND+NOT+is:wip+AND+is:reviewer' local query = args.query or 'is:reviewer AND status:open AND NOT is:wip'
local reviews local reviews
local notification_text = '' local notification_text
gerrit_widget = wibox.widget{ gerrit_widget = wibox.widget{
--font = 'Play 12',
widget = wibox.widget.textbox widget = wibox.widget.textbox
} }
local get_size = function (T) local function get_name_by_id(id)
local count = 0 res = name_dict[id]
for _ in pairs(T) do count = count + 1 end if res == nil then
return count res = ''
spawn.easy_async(string.format(GET_USERNAME_CMD, host, id), function(stdout, stderr, reason, exit_code)
name_dict[tonumber(id)] = stdout
end)
end
return res
end end
local update_graphic = function(widget, stdout, _, _, _) local update_graphic = function(widget, stdout, _, _, _)
reviews = json.decode(stdout) reviews = json.decode(stdout)
widget.text = get_size(reviews) widget.text = rawlen(reviews)
notification_text = ''
for i in pairs(reviews)do for _, review in ipairs(reviews) do
notification_text = notification_text .. '\n' .. reviews[i].subject notification_text = notification_text .. "<b>" .. review.project ..'</b> / ' .. get_name_by_id(review.owner._account_id) .. review.subject ..'\n'
i = i + 1
end end
end end
local function urlencode(url)
if url == nil then
return
end
url = url:gsub(" ", "+")
return url
end
query_escaped = urlencode(query)
watch(string.format(CMD, host, query_escaped), 10, update_graphic, gerrit_widget)
local notification local notification
gerrit_widget:connect_signal("mouse::enter", function() gerrit_widget:connect_signal("mouse::enter", function()
notification = naughty.notify{ notification = naughty.notify{
text = notification_text, text = notification_text,
timeout = 5, hover_timeout = 10, timeout = 20,
position = position, position = position,
width = (500) width = (500)
} }
@ -78,6 +71,7 @@ local function worker(args)
naughty.destroy(notification) naughty.destroy(notification)
end) end)
watch(string.format(GET_CHANGES_CMD, host, query:gsub(" ", "+")), 1, update_graphic, gerrit_widget)
return gerrit_widget return gerrit_widget
end end