Fix getGroupMembers with token that don't have sufficient permissions
Signed-off-by: Boris Gershanik <borbor154@gmail.com>
This commit is contained in:
@@ -429,6 +429,28 @@ describe('GitLabClient', () => {
|
||||
expect(members).toEqual([1]);
|
||||
});
|
||||
|
||||
it('gets member IDs with token without full permissions', async () => {
|
||||
server.use(
|
||||
graphql
|
||||
.link(`${MOCK_CONFIG.baseUrl}/api/graphql`)
|
||||
.operation((_, res, ctx) =>
|
||||
res(
|
||||
ctx.data({
|
||||
group: {},
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
const client = new GitLabClient({
|
||||
config: MOCK_CONFIG,
|
||||
logger: getVoidLogger(),
|
||||
});
|
||||
|
||||
const members = await client.getGroupMembers('group1');
|
||||
|
||||
expect(members).toEqual([]);
|
||||
});
|
||||
|
||||
it('rejects when GraphQL returns errors', async () => {
|
||||
server.use(
|
||||
graphql
|
||||
|
||||
@@ -127,6 +127,14 @@ export class GitLabClient {
|
||||
if (response.errors) {
|
||||
throw new Error(`GraphQL errors: ${JSON.stringify(response.errors)}`);
|
||||
}
|
||||
|
||||
if (!response.data.group?.groupMembers?.nodes) {
|
||||
this.logger.warn(
|
||||
`Couldn't get members for group ${groupPath}. The provided token might not have sufficient permissions`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
memberIds.push(
|
||||
...response.data.group.groupMembers.nodes
|
||||
.filter(n => n.user)
|
||||
|
||||
Reference in New Issue
Block a user