From 7161ef211cbd463a8174169cf17b32c719548827 Mon Sep 17 00:00:00 2001 From: Clemens Beck Date: Sun, 19 Feb 2023 02:37:13 +0100 Subject: [PATCH] [modules/gitlab] add module --- bumblebee_status/modules/contrib/gitlab.py | 78 +++++++++++++++++++++ requirements/modules/gitlab.txt | 1 + screenshots/gitlab.png | Bin 0 -> 2456 bytes tests/modules/contrib/test_gitlab.py | 42 +++++++++++ themes/icons/ascii.json | 3 + themes/icons/awesome-fonts.json | 3 + 6 files changed, 127 insertions(+) create mode 100644 bumblebee_status/modules/contrib/gitlab.py create mode 100644 requirements/modules/gitlab.txt create mode 100644 screenshots/gitlab.png create mode 100644 tests/modules/contrib/test_gitlab.py diff --git a/bumblebee_status/modules/contrib/gitlab.py b/bumblebee_status/modules/contrib/gitlab.py new file mode 100644 index 0000000..126650d --- /dev/null +++ b/bumblebee_status/modules/contrib/gitlab.py @@ -0,0 +1,78 @@ +# pylint: disable=C0111,R0903 + +""" +Displays the GitLab todo count: + + * https://docs.gitlab.com/ee/user/todos.html + * https://docs.gitlab.com/ee/api/todos.html + +Uses `xdg-open` or `x-www-browser` to open web-pages. + +Requires the following library: + * requests + +Errors: + if the GitLab todo query failed, the shown value is `n/a` + +Parameters: + * gitlab.token: GitLab personal access token, the token needs to have the "read_api" scope. + * gitlab.host: Host of the GitLab instance, default is "gitlab.com". + * gitlab.actions: Comma separated actions to be parsed (e.g.: gitlab.actions=assigned,approval_required) +""" + +import json +import requests +import shutil +import util + +import core.module +import core.widget +import core.decorators +import core.input + + +class Module(core.module.Module): + @core.decorators.every(minutes=5) + def __init__(self, config, theme): + super().__init__(config, theme, core.widget.Widget(self.gitlab)) + + self.background = True + self.__label = "" + self.__host = self.parameter("host", "gitlab.com") + + self.__actions = [] + actions = self.parameter("actions", "") + if actions: + self.__actions = util.format.aslist(actions) + + self.__requests = requests.Session() + self.__requests.headers.update({"PRIVATE-TOKEN": self.parameter("token", "")}) + + cmd = "xdg-open" + if not shutil.which(cmd): + cmd = "x-www-browser" + + core.input.register( + self, + button=core.input.LEFT_MOUSE, + cmd="{cmd} https:/{host}//dashboard/todos".format( + cmd=cmd, host=self.__host + ), + ) + + def gitlab(self, _): + return self.__label + + def update(self): + try: + url = "https://{host}/api/v4/todos".format(host=self.__host) + response = self.__requests.get(url) + todos = response.json() + if self.__actions: + todos = [t for t in todos if t["action_name"] in self.__actions] + self.__label = str(len(todos)) + except Exception as e: + self.__label = "n/a" + + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/requirements/modules/gitlab.txt b/requirements/modules/gitlab.txt new file mode 100644 index 0000000..f229360 --- /dev/null +++ b/requirements/modules/gitlab.txt @@ -0,0 +1 @@ +requests diff --git a/screenshots/gitlab.png b/screenshots/gitlab.png new file mode 100644 index 0000000000000000000000000000000000000000..d488db0dd458860553f6cf7e01cf97432458f41e GIT binary patch literal 2456 zcmZ{mX*|^H8^(XpVMx|2%@O!xU`^01=k~Am#x89I&jI?*I@A2Y^*K0MN<< z0MQ^)ldU#uz~OFgf&xzdJ5O6*X0aTuAX7&?i>#l3EAXn$i_U5|L(D9VIG5RkPD#oa z(;D1a7Qe@Bt1uRWSQ2N6hb4gRrB4C?fPBqR`ZpZ91|3!co$Q5AXp61+Redu=oxcld zS=)jWHVu~)Ff+qQ(JQY&Y{GF$kkVt#C?u#2B9#H{7rpiBR-LK0TzONeWr0@cszw;O zXS+>FWpg%if9p=2&R3b3?jv}?uaJ#*%i+{bQY6*Gt6t1dIh_J0%IOKlA^-@qU9&L> z;Nai~w49dyY)$F_;QXC=C>XTxk@47f9x$pO*pVoV=*!v;noae5sC6L0|E$`){N5is zWhDke8JRNg5jNoWkGRp?1~K%b?Y|N!2^R8m>R)@D^>^=~fcUkh@jLvhh1!%gyHQOD(3AG{=;dM0h} zLfB5Bh6}DK3a8XIn>0t>fa#Y%qJ<~c_{5KPx-q*h8al80Pm59SUv$1|nB@5}0JeM^ z>{2#rCM%x4ltncub}C`#ROvNcagrV{CgKD~d{t^pN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