summaryrefslogtreecommitdiff
path: root/bitbucket-widget
diff options
context:
space:
mode:
Diffstat (limited to 'bitbucket-widget')
-rw-r--r--bitbucket-widget/README.md16
-rw-r--r--bitbucket-widget/bitbucket.lua44
2 files changed, 34 insertions, 26 deletions
diff --git a/bitbucket-widget/README.md b/bitbucket-widget/README.md
index a0cae0a..7f82e73 100644
--- a/bitbucket-widget/README.md
+++ b/bitbucket-widget/README.md
@@ -4,9 +4,9 @@ The widget shows the number of pull requests assigned to the user and when click
## How it works
-Widget uses cURL to query Bitbucket's [REST API](https://developer.atlassian.com/bitbucket/api/2/reference/). In order to be authenticated, widget uses a [netrc](https://ec.haxx.se/usingcurl/usingcurl-netrc) feature of the cURL, which is basically to store basic auth credentials in a .netrc file in home folder.
+Widget uses cURL to query Bitbucket's [REST API](https://developer.atlassian.com/bitbucket/api/2/reference/). In order to be authenticated, widget uses a [netrc](https://ec.haxx.se/usingcurl/usingcurl-netrc) feature of the cURL, which is basically allows storing basic auth credentials in a **.netrc** file in home folder.
-Bitbucket allows using [App Passwords](https://confluence.atlassian.com/bitbucket/app-passwords-828781300.html) (available in the account settings) - simply generate one for the widget and use it as password in .netrc file.
+Bitbucket allows using [App Passwords](https://confluence.atlassian.com/bitbucket/app-passwords-828781300.html) (available in the account settings) - simply generate one for the widget and use it as password in **.netrc** file.
## Customization
@@ -15,15 +15,19 @@ It is possible to customize widget by providing a table with all or some of the
| Name | Default | Description |
|---|---|---|
| `icon` | `~/.config/awesome/awesome-wm-widgets/bitbucket-widget/bitbucket-icon-gradient-blue.svg` | Path to the icon |
-| `host` | Required | Ex: _http://api.bitbucket.org_ |
-| `uuid` | Required | UUID |
+| `host` | Required | e.g _http://api.bitbucket.org_ |
+| `uuid` | Required | e.g _{123e4567-e89b-12d3-a456-426614174000}_ |
| `workspace` | Required | Workspace ID|
| `repo_slug` | Required | Repository slug |
| `timeout` | 60 | How often in seconds the widget refreshes |
+Note:
+ - host most likely should start with _api._
+ - to get your UUID you may call `curl -s -n 'https://api.bitbucket.org/2.0/user'`
+
## Installation
-Create a .netrc file in you home directory with following content:
+Create a **.netrc** file in you home directory with following content:
```bash
machine api.bitbucket.org
@@ -56,7 +60,7 @@ s.mytasklist, -- Middle widget
-- default
bitbucket_widget({
host = 'https://api.bitbucket.org',
- uuid = 'your-uuid',
+ uuid = '{123e4567-e89b-12d3-a456-426614174000}',
workspace = 'workspace',
repo_slug = 'slug'
diff --git a/bitbucket-widget/bitbucket.lua b/bitbucket-widget/bitbucket.lua
index 8d47f2f..b85e653 100644
--- a/bitbucket-widget/bitbucket.lua
+++ b/bitbucket-widget/bitbucket.lua
@@ -21,7 +21,12 @@ local gfs = require("gears.filesystem")
local HOME_DIR = os.getenv("HOME")
local WIDGET_DIR = HOME_DIR .. '/.config/awesome/awesome-wm-widgets/bitbucket-widget/'
-local GET_PRS_CMD= [[bash -c "curl -s --show-error -n '%s/2.0/repositories/%s/%s/pullrequests?fields=values.participants.approved,values.title,values.links.html,values.author.display_name,values.author.uuid,values.author.links.avatar,values.source.branch,values.destination.branch,values.comment_count,values.created_on&q=reviewers.uuid+%%3D+%%22%s%%22+AND+state+%%3D+%%22OPEN%%22' | jq '.[] '"]]
+local GET_PRS_CMD= [[bash -c "curl -s --show-error -n ]]
+ .. [['%s/2.0/repositories/%s/%s/pullrequests]]
+ .. [[?fields=values.participants.approved,values.title,values.links.html,values.author.display_name,]]
+ .. [[values.author.uuid,values.author.links.avatar,values.source.branch,values.destination.branch,]]
+ .. [[values.comment_count,values.created_on&q=reviewers.uuid+%%3D+%%22%s%%22+AND+state+%%3D+%%22OPEN%%22']]
+ .. [[ | jq '.[] '"]]
local DOWNLOAD_AVATAR_CMD = [[bash -c "curl -L -n --create-dirs -o %s/.cache/awmw/bitbucket-widget/avatars/%s %s"]]
local bitbucket_widget = wibox.widget {
@@ -71,7 +76,7 @@ local popup = awful.popup{
--- Converts string representation of date (2020-06-02T11:25:27Z) to date
local function parse_date(date_str)
local pattern = "(%d+)%-(%d+)%-(%d+)T(%d+):(%d+):(%d+)%Z"
- local y, m, d, h, min, sec, mil = date_str:match(pattern)
+ local y, m, d, h, min, sec, _ = date_str:match(pattern)
return os.time{year = y, month = m, day = d, hour = h, min = min, sec = sec}
end
@@ -111,9 +116,9 @@ local function count_approves(participants)
return res
end
-local function worker(args)
+local function worker(user_args)
- local args = args or {}
+ local args = user_args or {}
local icon = args.icon or WIDGET_DIR .. '/bitbucket-icon-gradient-blue.svg'
local host = args.host or show_warning('Bitbucket host is not set')
@@ -279,11 +284,8 @@ local function worker(args)
}
if not gfs.file_readable(path_to_avatar) then
- spawn.easy_async(string.format(
- DOWNLOAD_AVATAR_CMD,
- HOME_DIR,
- pr.author.uuid,
- pr.author.links.avatar.href), function() row:get_children_by_id('avatar')[1]:set_image(path_to_avatar) end)
+ local cmd = string.format(DOWNLOAD_AVATAR_CMD, HOME_DIR, pr.author.uuid, pr.author.links.avatar.href)
+ spawn.easy_async(cmd, function() row:get_children_by_id('avatar')[1]:set_image(path_to_avatar) end)
end
@@ -299,34 +301,36 @@ local function worker(args)
)
)
row:get_children_by_id('avatar')[1]:buttons(
- awful.util.table.join(
- awful.button({}, 1, function()
- spawn.with_shell(string.format('xdg-open "https://bitbucket.org/%s/%s/pull-requests?state=OPEN&author=%s"', workspace, repo_slug, pr.author.uuid))
- popup.visible = false
- end)
- )
+ awful.util.table.join(
+ awful.button({}, 1, function()
+ spawn.with_shell(
+ string.format('xdg-open "https://bitbucket.org/%s/%s/pull-requests?state=OPEN&author=%s"',
+ workspace, repo_slug, pr.author.uuid)
+ )
+ popup.visible = false
+ end)
+ )
)
local old_cursor, old_wibox
- row:get_children_by_id('title')[1]:connect_signal("mouse::enter", function(c)
+ row:get_children_by_id('title')[1]:connect_signal("mouse::enter", function()
local wb = mouse.current_wibox
old_cursor, old_wibox = wb.cursor, wb
wb.cursor = "hand1"
end)
- row:get_children_by_id('title')[1]:connect_signal("mouse::leave", function(c)
+ row:get_children_by_id('title')[1]:connect_signal("mouse::leave", function()
if old_wibox then
old_wibox.cursor = old_cursor
old_wibox = nil
end
end)
- local old_cursor, old_wibox
- row:get_children_by_id('avatar')[1]:connect_signal("mouse::enter", function(c)
+ row:get_children_by_id('avatar')[1]:connect_signal("mouse::enter", function()
local wb = mouse.current_wibox
old_cursor, old_wibox = wb.cursor, wb
wb.cursor = "hand1"
end)
- row:get_children_by_id('avatar')[1]:connect_signal("mouse::leave", function(c)
+ row:get_children_by_id('avatar')[1]:connect_signal("mouse::leave", function()
if old_wibox then
old_wibox.cursor = old_cursor
old_wibox = nil