MCPcopy
hub / github.com/gitify-app/gitify / refreshAccount

Function refreshAccount

src/renderer/utils/auth/utils.ts:113–155  ·  view source on GitHub ↗
(account: Account)

Source from the content-addressed store, hash-verified

111 * @throws If the API call fails.
112 */
113export async function refreshAccount(account: Account): Promise<Account> {
114 try {
115 const response = await fetchAuthenticatedUserDetails(account);
116
117 const user = response.data;
118
119 // Refresh user data
120 account.user = {
121 id: String(user.id),
122 login: user.login,
123 name: user.name,
124 avatar: user.avatar_url as Link,
125 };
126
127 account.version = 'latest';
128
129 account.version = extractHostVersion(
130 response.headers['x-github-enterprise-version'] as string,
131 );
132
133 const accountScopes = response.headers['x-oauth-scopes']
134 ?.split(',')
135 .map((scope: string) => scope.trim());
136
137 account.scopes = accountScopes ?? [];
138
139 if (!hasRequiredScopes(account)) {
140 rendererLogWarn(
141 'refreshAccount',
142 `account for user ${account.user.login} is missing required scopes`,
143 );
144 }
145 } catch (err) {
146 rendererLogError(
147 'refreshAccount',
148 `failed to refresh account for user ${account.user?.login ?? account.hostname}`,
149 toError(err),
150 );
151 throw err;
152 }
153
154 return account;
155}
156
157/**
158 * Normalize a GitHub Enterprise Server version string to a semver string.

Callers 3

handleRefreshFunction · 0.90
AppProviderFunction · 0.90
addAccountFunction · 0.85

Calls 6

hasRequiredScopesFunction · 0.90
rendererLogWarnFunction · 0.90
rendererLogErrorFunction · 0.90
toErrorFunction · 0.90
extractHostVersionFunction · 0.85

Tested by

no test coverage detected