Feature: add gitea widget (#2968)

pull/2998/head
shamoon 9 months ago
parent 291bf422f9
commit fce694e2b9

@ -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
```

@ -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

@ -831,5 +831,10 @@
"plants": "Plants",
"photos": "Photos",
"species": "Species"
},
"gitea": {
"notifications": "Notifications",
"issues": "Issues",
"pulls": "Pull Requests"
}
}

@ -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();

@ -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")),

@ -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 <Container service={service} error={giteaNotificationsError ?? giteaIssuesError} />;
}
if (!giteaNotifications || !giteaIssues) {
return (
<Container service={service}>
<Block label="gitea.notifications" />
<Block label="gitea.issues" />
<Block label="gitea.pulls" />
</Container>
);
}
return (
<Container service={service}>
<Block label="gitea.notifications" value={giteaNotifications.length} />
<Block label="gitea.issues" value={giteaIssues.issues.length} />
<Block label="gitea.pulls" value={giteaIssues.pulls.length} />
</Container>
);
}

@ -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;

@ -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,

Loading…
Cancel
Save