Use single user counts endpoint
This commit is contained in:
parent
4adf24dfa9
commit
c7e796b681
@ -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.
|
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
|
```yaml
|
||||||
widget:
|
widget:
|
||||||
type: gitlab
|
type: gitlab
|
||||||
url: http://gitlab.host.or.ip:port
|
url: http://gitlab.host.or.ip:port
|
||||||
key: personal-access-token
|
key: personal-access-token
|
||||||
|
user_id: 123456
|
||||||
```
|
```
|
||||||
|
|||||||
@ -1003,8 +1003,9 @@
|
|||||||
"loading": "Loading"
|
"loading": "Loading"
|
||||||
},
|
},
|
||||||
"gitlab": {
|
"gitlab": {
|
||||||
"events": "Events",
|
"groups": "Groups",
|
||||||
"issues": "Issues",
|
"issues": "Issues",
|
||||||
"merges": "Merge Requests"
|
"merges": "Merge Requests",
|
||||||
|
"projects": "Projects"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,29 +8,29 @@ export default function Component({ service }) {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { widget } = service;
|
const { widget } = service;
|
||||||
|
|
||||||
const { data: gitlabEvents, error: gitlabEventsError } = useWidgetAPI(widget, "events");
|
const { data: gitlabCounts, error: gitlabCountsError } = useWidgetAPI(widget, "counts");
|
||||||
const { data: gitlabIssues, error: gitlabIssuesError } = useWidgetAPI(widget, "issues");
|
|
||||||
const { data: gitlabMerges, error: gitlabMergesError } = useWidgetAPI(widget, "merges");
|
|
||||||
|
|
||||||
if (gitlabEventsError || gitlabIssuesError || gitlabMergesError) {
|
if (gitlabCountsError) {
|
||||||
return <Container service={service} error={gitlabEventsError ?? gitlabIssuesError ?? gitlabMergesError} />;
|
return <Container service={service} error={gitlabCountsError} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gitlabEvents || !gitlabIssues || !gitlabMerges) {
|
if (!gitlabCounts) {
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="gitlab.events" />
|
<Block label="gitlab.groups" />
|
||||||
<Block label="gitlab.issues" />
|
<Block label="gitlab.issues" />
|
||||||
<Block label="gitlab.merges" />
|
<Block label="gitlab.merges" />
|
||||||
|
<Block label="gitlab.projects" />
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="gitlab.events" value={t("common.number", { value: gitlabEvents.count })} />
|
<Block label="gitlab.groups" value={t("common.number", { value: gitlabCounts.groups_count })} />
|
||||||
<Block label="gitlab.issues" value={t("common.number", { value: gitlabIssues.count })} />
|
<Block label="gitlab.issues" value={t("common.number", { value: gitlabCounts.issues_count })} />
|
||||||
<Block label="gitlab.merges" value={t("common.number", { value: gitlabMerges.count })} />
|
<Block label="gitlab.merges" value={t("common.number", { value: gitlabCounts.merge_requests_count })} />
|
||||||
|
<Block label="gitlab.projects" value={t("common.number", { value: gitlabCounts.projects_count })} />
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,27 +1,11 @@
|
|||||||
import { asJson } from "utils/proxy/api-helpers";
|
|
||||||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||||
|
|
||||||
const widget = {
|
const widget = {
|
||||||
api: "{url}/api/v4/{endpoint}",
|
api: "{url}/api/v4/{endpoint}",
|
||||||
proxyHandler: credentialedProxyHandler,
|
proxyHandler: credentialedProxyHandler,
|
||||||
mappings: {
|
mappings: {
|
||||||
events: {
|
counts: {
|
||||||
endpoint: "events",
|
endpoint: "users/{user_id}/associations_count",
|
||||||
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,
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user