0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 21:48:32 +00:00
renovatebot_renovate/lib/modules/platform/gitlab/http.ts
RahulGautamSingh cb804b00c4
fix(platform/gitlab): handle assignee id not found (#29307)
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
2024-06-04 17:03:26 +00:00

49 lines
1.4 KiB
TypeScript

import is from '@sindresorhus/is';
import { logger } from '../../../logger';
import { GitlabHttp } from '../../../util/http/gitlab';
import type { GitLabUser, GitlabUserStatus } from './types';
export const gitlabApi = new GitlabHttp();
export async function getUserID(username: string): Promise<number> {
const userInfo = (
await gitlabApi.getJson<{ id: number }[]>(`users?username=${username}`)
).body;
if (is.emptyArray(userInfo)) {
throw new Error(
`User ID for the username: ${username} could not be found.`,
);
}
return userInfo[0].id;
}
async function getMembers(group: string): Promise<GitLabUser[]> {
const groupEncoded = encodeURIComponent(group);
return (
await gitlabApi.getJson<GitLabUser[]>(`groups/${groupEncoded}/members`)
).body;
}
export async function getMemberUserIDs(group: string): Promise<number[]> {
const members = await getMembers(group);
return members.map((u) => u.id);
}
export async function getMemberUsernames(group: string): Promise<string[]> {
const members = await getMembers(group);
return members.map((u) => u.username);
}
export async function isUserBusy(user: string): Promise<boolean> {
try {
const url = `/users/${user}/status`;
const userStatus = (await gitlabApi.getJson<GitlabUserStatus>(url)).body;
return userStatus.availability === 'busy';
} catch (err) {
logger.warn({ err }, 'Failed to get user status');
return false;
}
}