summaryrefslogtreecommitdiff
path: root/bitbucket-widget
diff options
context:
space:
mode:
authorstreetturtle <streetturtle@gmail.com>2020-02-26 20:58:46 -0500
committerstreetturtle <streetturtle@gmail.com>2020-02-26 20:58:46 -0500
commit257dff3b6c85444f4477db6a8ae34865b86119a5 (patch)
tree30a1ee3189a135c48789e54a4acc1840b6e774e5 /bitbucket-widget
parente482f5b7101c2eb60e8941cd1d72f6b08ee721b8 (diff)
[bitbucket] add my PRs to the list
Diffstat (limited to 'bitbucket-widget')
-rw-r--r--bitbucket-widget/bitbucket.lua42
1 files changed, 33 insertions, 9 deletions
diff --git a/bitbucket-widget/bitbucket.lua b/bitbucket-widget/bitbucket.lua
index 44960a2..186f278 100644
--- a/bitbucket-widget/bitbucket.lua
+++ b/bitbucket-widget/bitbucket.lua
@@ -20,7 +20,7 @@ local gfs = require("gears.filesystem")
local HOME_DIR = os.getenv("HOME")
-local GET_PRS_CMD= [[bash -c "curl -s -n '%s/2.0/repositories/%s/%s/pullrequests?fields=values.title,values.links.html,values.author.display_name,values.author.account_id,values.author.links.avatar&q=reviewers.account_id+%%3D+%%22%s%%22+AND+state+%%3D+%%22OPEN%%22'"]]
+local GET_PRS_CMD= [[bash -c "curl -s -n '%s/2.0/repositories/%s/%s/pullrequests?fields=values.title,values.links.html,values.author.display_name,values.author.account_id,values.author.links.avatar&q=%%28author.account_id+%%3D+%%22%s%%22+OR+reviewers.account_id+%%3D+%%22%s%%22+%%29+AND+state+%%3D+%%22OPEN%%22' | jq '.[] | unique'"]]
local DOWNLOAD_AVATAR_CMD = [[bash -c "curl -n --create-dirs -o %s/.cache/awmw/bitbucket-widget/avatars/%s %s"]]
local bitbucket_widget = {}
@@ -44,10 +44,9 @@ local function worker(args)
local current_number_of_prs
- local rows = {
- { widget = wibox.widget.textbox },
- layout = wibox.layout.fixed.vertical,
- }
+ local to_review_rows = {layout = wibox.layout.fixed.vertical}
+ local my_review_rows = {layout = wibox.layout.fixed.vertical}
+ local rows = {layout = wibox.layout.fixed.vertical}
local popup = awful.popup{
ontop = true,
@@ -88,7 +87,7 @@ local function worker(args)
local result = json.decode(stdout)
- current_number_of_prs = rawlen(result.values)
+ current_number_of_prs = rawlen(result)
if current_number_of_prs == 0 then
widget:set_visible(false)
@@ -99,7 +98,24 @@ local function worker(args)
widget:set_text(current_number_of_prs)
for i = 0, #rows do rows[i]=nil end
- for _, pr in ipairs(result.values) do
+
+ for i = 0, #to_review_rows do to_review_rows[i]=nil end
+ table.insert(to_review_rows, {
+ text = "PRs to review",
+ align = 'center',
+ forced_height = 20,
+ widget = wibox.widget.textbox
+ })
+
+ for i = 0, #my_review_rows do my_review_rows[i]=nil end
+ table.insert(my_review_rows, {
+ text = "My PRs",
+ align = 'center',
+ forced_height = 20,
+ widget = wibox.widget.textbox
+ })
+
+ for _, pr in ipairs(result) do
local path_to_avatar = os.getenv("HOME") ..'/.cache/awmw/bitbucket-widget/avatars/' .. pr.author.account_id
if not gfs.file_readable(path_to_avatar) then
@@ -156,9 +172,17 @@ local function worker(args)
)
)
- table.insert(rows, row)
+ if (pr.author.account_id == account_id) then
+ table.insert(my_review_rows, row)
+ else
+ table.insert(to_review_rows, row)
+ end
end
+ table.insert(rows, to_review_rows)
+ if (#my_review_rows > 1) then
+ table.insert(rows, my_review_rows)
+ end
popup:setup(rows)
end
@@ -174,7 +198,7 @@ local function worker(args)
)
)
- watch(string.format(GET_PRS_CMD, host, workspace, repo_slug, account_id),
+ watch(string.format(GET_PRS_CMD, host, workspace, repo_slug, account_id, account_id),
10, update_widget, bitbucket_widget)
return bitbucket_widget
end