Skip to content

Feature: gitlab service widget #4317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/widgets/services/gitlab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: Gitlab
description: Gitlab Widget Configuration
---

Learn more about [Gitlab](https://gitlab.com).

API requires a personal access token with either `read_api` or `api` permission. See the [gitlab documentation](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#create-a-personal-access-token) for details on generating one.

Allowed fields: `["events", "openIssues", "openMergeRequests"]`.

```yaml
widget:
type: gitlab
url: http://gitlab.host.or.ip:port
key: personal-access-token
```
1 change: 1 addition & 0 deletions docs/widgets/services/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ You can also find a list of all available service widgets in the sidebar navigat
- [Gatus](gatus.md)
- [Ghostfolio](ghostfolio.md)
- [Gitea](gitea.md)
- [Gitlab](gitlab.md)
- [Glances](glances.md)
- [Gluetun](gluetun.md)
- [Gotify](gotify.md)
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ nav:
- widgets/services/gatus.md
- widgets/services/ghostfolio.md
- widgets/services/gitea.md
- widgets/services/gitlab.md
- widgets/services/glances.md
- widgets/services/gluetun.md
- widgets/services/gotify.md
Expand Down
5 changes: 5 additions & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -1001,5 +1001,10 @@
},
"spoolman": {
"loading": "Loading"
},
"gitlab": {
"events": "Events",
"issues": "Issues",
"merges": "Merge Requests"
}
}
2 changes: 2 additions & 0 deletions src/utils/proxy/handlers/credentialed.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export default async function credentialedProxyHandler(req, res, map) {
}
} else if (widget.type === "wgeasy") {
headers.Authorization = widget.password;
} else if (widget.type === "gitlab") {
headers["PRIVATE-TOKEN"] = widget.key;
} else {
headers["X-API-Key"] = `${widget.key}`;
}
Expand Down
1 change: 1 addition & 0 deletions src/widgets/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const components = {
gatus: dynamic(() => import("./gatus/component")),
ghostfolio: dynamic(() => import("./ghostfolio/component")),
gitea: dynamic(() => import("./gitea/component")),
gitlab: dynamic(() => import("./gitlab/component")),
glances: dynamic(() => import("./glances/component")),
gluetun: dynamic(() => import("./gluetun/component")),
gotify: dynamic(() => import("./gotify/component")),
Expand Down
36 changes: 36 additions & 0 deletions src/widgets/gitlab/component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useTranslation } from "next-i18next";

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 { t } = useTranslation();
const { widget } = service;

const { data: gitlabEvents, error: gitlabEventsError } = useWidgetAPI(widget, "events");
const { data: gitlabIssues, error: gitlabIssuesError } = useWidgetAPI(widget, "issues");
const { data: gitlabMerges, error: gitlabMergesError } = useWidgetAPI(widget, "merges");

if (gitlabEventsError || gitlabIssuesError || gitlabMergesError) {
return <Container service={service} error={gitlabEventsError ?? gitlabIssuesError ?? gitlabMergesError} />;
}

if (!gitlabEvents || !gitlabIssues || !gitlabMerges) {
return (
<Container service={service}>
<Block label="gitlab.events" />
<Block label="gitlab.issues" />
<Block label="gitlab.merges" />
</Container>
);
}

return (
<Container service={service}>
<Block label="gitlab.events" value={t("common.number", { value: gitlabEvents.count })} />
<Block label="gitlab.issues" value={t("common.number", { value: gitlabIssues.count })} />
<Block label="gitlab.merges" value={t("common.number", { value: gitlabMerges.count })} />
</Container>
);
}
29 changes: 29 additions & 0 deletions src/widgets/gitlab/widget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { asJson } from "utils/proxy/api-helpers";
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";

const widget = {
api: "{url}/api/v4/{endpoint}",
proxyHandler: credentialedProxyHandler,
mappings: {
events: {
endpoint: "events",
map: (data) => ({
count: asJson(data).length,
}),
},
issues: {
endpoint: "issues?state=opened",
map: (data) => ({
count: asJson(data).length,
}),
},
merges: {
endpoint: "merge_requests?state=opened",
map: (data) => ({
count: asJson(data).length,
}),
},
},
};

export default widget;
2 changes: 2 additions & 0 deletions src/widgets/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import gamedig from "./gamedig/widget";
import gatus from "./gatus/widget";
import ghostfolio from "./ghostfolio/widget";
import gitea from "./gitea/widget";
import gitlab from "./gitlab/widget";
import glances from "./glances/widget";
import gluetun from "./gluetun/widget";
import gotify from "./gotify/widget";
Expand Down Expand Up @@ -164,6 +165,7 @@ const widgets = {
gatus,
ghostfolio,
gitea,
gitlab,
glances,
gluetun,
gotify,
Expand Down