From c7e796b681a532a83479bfe58039b488f7ad3c33 Mon Sep 17 00:00:00 2001
From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Thu, 21 Nov 2024 19:14:38 -0800
Subject: [PATCH] Use single user counts endpoint
---
docs/widgets/services/gitlab.md | 5 ++++-
public/locales/en/common.json | 5 +++--
src/widgets/gitlab/component.jsx | 20 ++++++++++----------
src/widgets/gitlab/widget.js | 20 ++------------------
4 files changed, 19 insertions(+), 31 deletions(-)
diff --git a/docs/widgets/services/gitlab.md b/docs/widgets/services/gitlab.md
index 155fd0f6..a92434d8 100644
--- a/docs/widgets/services/gitlab.md
+++ b/docs/widgets/services/gitlab.md
@@ -7,11 +7,14 @@ 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"]`.
+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).
+
+Allowed fields: `["events", "issues", "merges", "projects"]`.
```yaml
widget:
type: gitlab
url: http://gitlab.host.or.ip:port
key: personal-access-token
+ user_id: 123456
```
diff --git a/public/locales/en/common.json b/public/locales/en/common.json
index 3cf42b80..484f76b5 100644
--- a/public/locales/en/common.json
+++ b/public/locales/en/common.json
@@ -1003,8 +1003,9 @@
"loading": "Loading"
},
"gitlab": {
- "events": "Events",
+ "groups": "Groups",
"issues": "Issues",
- "merges": "Merge Requests"
+ "merges": "Merge Requests",
+ "projects": "Projects"
}
}
diff --git a/src/widgets/gitlab/component.jsx b/src/widgets/gitlab/component.jsx
index e5d9bfe4..fb6f898f 100644
--- a/src/widgets/gitlab/component.jsx
+++ b/src/widgets/gitlab/component.jsx
@@ -8,29 +8,29 @@ 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");
+ const { data: gitlabCounts, error: gitlabCountsError } = useWidgetAPI(widget, "counts");
- if (gitlabEventsError || gitlabIssuesError || gitlabMergesError) {
- return ;
+ if (gitlabCountsError) {
+ return ;
}
- if (!gitlabEvents || !gitlabIssues || !gitlabMerges) {
+ if (!gitlabCounts) {
return (
-
+
+
);
}
return (
-
-
-
+
+
+
+
);
}
diff --git a/src/widgets/gitlab/widget.js b/src/widgets/gitlab/widget.js
index 652674ab..26f77a77 100644
--- a/src/widgets/gitlab/widget.js
+++ b/src/widgets/gitlab/widget.js
@@ -1,27 +1,11 @@
-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,
- }),
+ counts: {
+ endpoint: "users/{user_id}/associations_count",
},
},
};