Skip to content

Commit 7b34c09

Browse files
committed
refactor(gitlab): fetch login metadata in parallel and log dropped failures
1 parent 364e125 commit 7b34c09

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

‎src/renderer/utils/forges/gitlab/adapter.ts‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
RefreshAccountData,
1313
} from '../types';
1414

15+
import { rendererLogWarn, toError } from '../../core/logger';
1516
import { createNotificationHandler } from '../github/handlers';
1617
import {
1718
fetchGitLabAuthenticatedUser,
@@ -39,7 +40,11 @@ const capabilities: ForgeCapabilities = {
3940
};
4041

4142
async function fetchAuthenticatedUser(account: Account): Promise<RefreshAccountData> {
42-
const user = await fetchGitLabAuthenticatedUser(account);
43+
const [user, version, scopes] = await Promise.all([
44+
fetchGitLabAuthenticatedUser(account),
45+
fetchVersionOrUndefined(account),
46+
fetchScopesOrUndefined(account),
47+
]);
4348

4449
return {
4550
user: {
@@ -48,21 +53,25 @@ async function fetchAuthenticatedUser(account: Account): Promise<RefreshAccountD
4853
name: user.name ?? null,
4954
avatar: user.avatar_url ?? '',
5055
},
51-
version: await fetchVersionOrUndefined(account),
52-
scopes: await fetchScopesOrUndefined(account),
56+
version,
57+
scopes,
5358
};
5459
}
5560

5661
/**
5762
* Instance version and token scopes are supplementary: a token without the
58-
* breadth to read them still works for notifications, so a failure here must
59-
* not fail the login.
63+
* breadth to read them still works for notifications, so a failure here is
64+
* logged and dropped rather than failing the login.
6065
*/
6166
async function fetchVersionOrUndefined(account: Account): Promise<string | undefined> {
6267
try {
6368
const { version } = await fetchGitLabVersion(account);
6469
return version;
65-
} catch {
70+
} catch (err) {
71+
rendererLogWarn(
72+
'gitlab',
73+
`Could not read instance version for ${account.hostname}: ${toError(err).message}`,
74+
);
6675
return undefined;
6776
}
6877
}
@@ -71,7 +80,11 @@ async function fetchScopesOrUndefined(account: Account): Promise<string[] | unde
7180
try {
7281
const { scopes } = await fetchGitLabTokenMetadata(account);
7382
return scopes;
74-
} catch {
83+
} catch (err) {
84+
rendererLogWarn(
85+
'gitlab',
86+
`Could not read token scopes for ${account.hostname}: ${toError(err).message}`,
87+
);
7588
return undefined;
7689
}
7790
}

0 commit comments

Comments
 (0)