Skip to content

Commit 2b8647b

Browse files
UrsKroellshamoon
andauthored
Feature: gitlab service widget (#4317)
Co-authored-by: shamoon <[email protected]>
1 parent 94bbcbe commit 2b8647b

File tree

9 files changed

+82
-0
lines changed

9 files changed

+82
-0
lines changed

docs/widgets/services/gitlab.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Gitlab
3+
description: Gitlab Widget Configuration
4+
---
5+
6+
Learn more about [Gitlab](https://gitlab.com).
7+
8+
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.
9+
10+
Your Gitlab user ID can be found on [your profile page](https://support.circleci.com/hc/en-us/articles/20761157174043-How-to-find-your-GitLab-User-ID).
11+
12+
Allowed fields: `["events", "issues", "merges", "projects"]`.
13+
14+
```yaml
15+
widget:
16+
type: gitlab
17+
url: http://gitlab.host.or.ip:port
18+
key: personal-access-token
19+
user_id: 123456
20+
```

docs/widgets/services/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ You can also find a list of all available service widgets in the sidebar navigat
4141
- [Gatus](gatus.md)
4242
- [Ghostfolio](ghostfolio.md)
4343
- [Gitea](gitea.md)
44+
- [Gitlab](gitlab.md)
4445
- [Glances](glances.md)
4546
- [Gluetun](gluetun.md)
4647
- [Gotify](gotify.md)

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ nav:
6464
- widgets/services/gatus.md
6565
- widgets/services/ghostfolio.md
6666
- widgets/services/gitea.md
67+
- widgets/services/gitlab.md
6768
- widgets/services/glances.md
6869
- widgets/services/gluetun.md
6970
- widgets/services/gotify.md

public/locales/en/common.json

+6
Original file line numberDiff line numberDiff line change
@@ -1001,5 +1001,11 @@
10011001
},
10021002
"spoolman": {
10031003
"loading": "Loading"
1004+
},
1005+
"gitlab": {
1006+
"groups": "Groups",
1007+
"issues": "Issues",
1008+
"merges": "Merge Requests",
1009+
"projects": "Projects"
10041010
}
10051011
}

src/utils/proxy/handlers/credentialed.js

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ export default async function credentialedProxyHandler(req, res, map) {
9494
}
9595
} else if (widget.type === "wgeasy") {
9696
headers.Authorization = widget.password;
97+
} else if (widget.type === "gitlab") {
98+
headers["PRIVATE-TOKEN"] = widget.key;
9799
} else {
98100
headers["X-API-Key"] = `${widget.key}`;
99101
}

src/widgets/components.js

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const components = {
3838
gatus: dynamic(() => import("./gatus/component")),
3939
ghostfolio: dynamic(() => import("./ghostfolio/component")),
4040
gitea: dynamic(() => import("./gitea/component")),
41+
gitlab: dynamic(() => import("./gitlab/component")),
4142
glances: dynamic(() => import("./glances/component")),
4243
gluetun: dynamic(() => import("./gluetun/component")),
4344
gotify: dynamic(() => import("./gotify/component")),

src/widgets/gitlab/component.jsx

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { useTranslation } from "next-i18next";
2+
3+
import Container from "components/services/widget/container";
4+
import Block from "components/services/widget/block";
5+
import useWidgetAPI from "utils/proxy/use-widget-api";
6+
7+
export default function Component({ service }) {
8+
const { t } = useTranslation();
9+
const { widget } = service;
10+
11+
const { data: gitlabCounts, error: gitlabCountsError } = useWidgetAPI(widget, "counts");
12+
13+
if (gitlabCountsError) {
14+
return <Container service={service} error={gitlabCountsError} />;
15+
}
16+
17+
if (!gitlabCounts) {
18+
return (
19+
<Container service={service}>
20+
<Block label="gitlab.groups" />
21+
<Block label="gitlab.issues" />
22+
<Block label="gitlab.merges" />
23+
<Block label="gitlab.projects" />
24+
</Container>
25+
);
26+
}
27+
28+
return (
29+
<Container service={service}>
30+
<Block label="gitlab.groups" value={t("common.number", { value: gitlabCounts.groups_count })} />
31+
<Block label="gitlab.issues" value={t("common.number", { value: gitlabCounts.issues_count })} />
32+
<Block label="gitlab.merges" value={t("common.number", { value: gitlabCounts.merge_requests_count })} />
33+
<Block label="gitlab.projects" value={t("common.number", { value: gitlabCounts.projects_count })} />
34+
</Container>
35+
);
36+
}

src/widgets/gitlab/widget.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
2+
3+
const widget = {
4+
api: "{url}/api/v4/{endpoint}",
5+
proxyHandler: credentialedProxyHandler,
6+
mappings: {
7+
counts: {
8+
endpoint: "users/{user_id}/associations_count",
9+
},
10+
},
11+
};
12+
13+
export default widget;

src/widgets/widgets.js

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import gamedig from "./gamedig/widget";
3232
import gatus from "./gatus/widget";
3333
import ghostfolio from "./ghostfolio/widget";
3434
import gitea from "./gitea/widget";
35+
import gitlab from "./gitlab/widget";
3536
import glances from "./glances/widget";
3637
import gluetun from "./gluetun/widget";
3738
import gotify from "./gotify/widget";
@@ -164,6 +165,7 @@ const widgets = {
164165
gatus,
165166
ghostfolio,
166167
gitea,
168+
gitlab,
167169
glances,
168170
gluetun,
169171
gotify,

0 commit comments

Comments
 (0)