From fce694e2b966b0cd9b0275fc8ec11190e2fe3ed8 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed, 21 Feb 2024 00:41:21 -0800 Subject: [PATCH] Feature: add gitea widget (#2968) --- docs/widgets/services/gitea.md | 17 +++++++++++++++++ mkdocs.yml | 1 + public/locales/en/common.json | 5 +++++ src/utils/proxy/api-helpers.js | 2 +- src/widgets/components.js | 1 + src/widgets/gitea/component.jsx | 32 ++++++++++++++++++++++++++++++++ src/widgets/gitea/widget.js | 22 ++++++++++++++++++++++ src/widgets/widgets.js | 2 ++ 8 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 docs/widgets/services/gitea.md create mode 100644 src/widgets/gitea/component.jsx create mode 100644 src/widgets/gitea/widget.js diff --git a/docs/widgets/services/gitea.md b/docs/widgets/services/gitea.md new file mode 100644 index 000000000..bf75aa69b --- /dev/null +++ b/docs/widgets/services/gitea.md @@ -0,0 +1,17 @@ +--- +title: Gitea +description: Gitea Widget Configuration +--- + +Learn more about [Gitea](https://gitea.com). + +API token requires `notifications` and `repository` permissions. See the [gitea documentation](https://docs.gitea.com/development/api-usage#generating-and-listing-api-tokens) for details on generating tokens. + +Allowed fields: ["notifications", "issues", "pulls"] + +```yaml +widget: + type: gitea + url: http://gitea.host.or.ip:port + key: giteaapitoken +``` diff --git a/mkdocs.yml b/mkdocs.yml index e9d531ba0..c6ecfda95 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -57,6 +57,7 @@ nav: - widgets/services/gamedig.md - widgets/services/gatus.md - widgets/services/ghostfolio.md + - widgets/services/gitea.md - widgets/services/glances.md - widgets/services/gluetun.md - widgets/services/gotify.md diff --git a/public/locales/en/common.json b/public/locales/en/common.json index cc6846a00..7d5097fb2 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -831,5 +831,10 @@ "plants": "Plants", "photos": "Photos", "species": "Species" + }, + "gitea": { + "notifications": "Notifications", + "issues": "Issues", + "pulls": "Pull Requests" } } diff --git a/src/utils/proxy/api-helpers.js b/src/utils/proxy/api-helpers.js index cfb4307e6..5fc22e1e5 100644 --- a/src/utils/proxy/api-helpers.js +++ b/src/utils/proxy/api-helpers.js @@ -57,7 +57,7 @@ export function jsonArrayFilter(data, filter) { export function sanitizeErrorURL(errorURL) { // Dont display sensitive params on frontend const url = new URL(errorURL); - ["apikey", "api_key", "token", "t"].forEach((key) => { + ["apikey", "api_key", "token", "t", "access_token"].forEach((key) => { if (url.searchParams.has(key)) url.searchParams.set(key, "***"); }); return url.toString(); diff --git a/src/widgets/components.js b/src/widgets/components.js index 784f05b20..9054c4d2f 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -31,6 +31,7 @@ const components = { gamedig: dynamic(() => import("./gamedig/component")), gatus: dynamic(() => import("./gatus/component")), ghostfolio: dynamic(() => import("./ghostfolio/component")), + gitea: dynamic(() => import("./gitea/component")), glances: dynamic(() => import("./glances/component")), gluetun: dynamic(() => import("./gluetun/component")), gotify: dynamic(() => import("./gotify/component")), diff --git a/src/widgets/gitea/component.jsx b/src/widgets/gitea/component.jsx new file mode 100644 index 000000000..b193efd2e --- /dev/null +++ b/src/widgets/gitea/component.jsx @@ -0,0 +1,32 @@ +import Container from "components/services/widget/container"; +import Block from "components/services/widget/block"; +import useWidgetAPI from "utils/proxy/use-widget-api"; + +export default function Component({ service }) { + const { widget } = service; + + const { data: giteaNotifications, error: giteaNotificationsError } = useWidgetAPI(widget, "notifications"); + const { data: giteaIssues, error: giteaIssuesError } = useWidgetAPI(widget, "issues"); + + if (giteaNotificationsError || giteaIssuesError) { + return ; + } + + if (!giteaNotifications || !giteaIssues) { + return ( + + + + + + ); + } + + return ( + + + + + + ); +} diff --git a/src/widgets/gitea/widget.js b/src/widgets/gitea/widget.js new file mode 100644 index 000000000..32871b006 --- /dev/null +++ b/src/widgets/gitea/widget.js @@ -0,0 +1,22 @@ +import { asJson } from "utils/proxy/api-helpers"; +import genericProxyHandler from "utils/proxy/handlers/generic"; + +const widget = { + api: "{url}/api/v1/{endpoint}?access_token={key}", + proxyHandler: genericProxyHandler, + + mappings: { + notifications: { + endpoint: "notifications", + }, + issues: { + endpoint: "repos/issues/search", + map: (data) => ({ + pulls: asJson(data).filter((issue) => issue.pull_request), + issues: asJson(data).filter((issue) => !issue.pull_request), + }), + }, + }, +}; + +export default widget; diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 6f50d9ef5..5804253d6 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -25,6 +25,7 @@ import fritzbox from "./fritzbox/widget"; import gamedig from "./gamedig/widget"; import gatus from "./gatus/widget"; import ghostfolio from "./ghostfolio/widget"; +import gitea from "./gitea/widget"; import glances from "./glances/widget"; import gluetun from "./gluetun/widget"; import gotify from "./gotify/widget"; @@ -133,6 +134,7 @@ const widgets = { gamedig, gatus, ghostfolio, + gitea, glances, gluetun, gotify,