Skip to content

Commit 93869e7

Browse files
committed
Handles hostless avatar URLs coming from GraphQL
(#3788, #3795)
1 parent 0ce3c6b commit 93869e7

File tree

1 file changed

+15
-1
lines changed
  • src/plus/integrations/providers/gitlab

1 file changed

+15
-1
lines changed

src/plus/integrations/providers/gitlab/models.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,20 @@ export function fromGitLabMergeRequestProvidersApi(pr: ProviderPullRequest, prov
179179
}
180180

181181
export function fromGitLabMergeRequest(pr: GitLabMergeRequestFull, provider: Provider): PullRequest {
182+
let avatarUrl: string | undefined;
183+
try {
184+
avatarUrl = new URL(pr.author?.avatarUrl ?? '').toString();
185+
} catch {
186+
try {
187+
const authorUrl = new URL(pr.author?.webUrl ?? '');
188+
authorUrl.pathname = '';
189+
authorUrl.search = '';
190+
authorUrl.hash = '';
191+
avatarUrl = pr.author?.avatarUrl ? authorUrl.toString() + pr.author?.avatarUrl : undefined;
192+
} catch {
193+
avatarUrl = undefined;
194+
}
195+
}
182196
const [owner, repo] = pr.project.fullPath.split('/');
183197

184198
return new PullRequest(
@@ -187,7 +201,7 @@ export function fromGitLabMergeRequest(pr: GitLabMergeRequestFull, provider: Pro
187201
// author
188202
id: pr.author?.id ?? '',
189203
name: pr.author?.name ?? 'Unknown',
190-
avatarUrl: pr.author?.avatarUrl ?? '',
204+
avatarUrl: avatarUrl,
191205
url: pr.author?.webUrl ?? '',
192206
},
193207
pr.iid, // id

0 commit comments

Comments
 (0)