Feature: add gitea widget (#2968)
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
|
||||
```
|
@ -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;
|
Loading…
Reference in new issue