Skip to content

Commit

Permalink
fix(front): support gitlab self-hosted author url in notification (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlienard authored Dec 26, 2024
1 parent 5ff9490 commit 37e081f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { browser } from '$app/environment';
import { intersect } from '$lib/features';
import { intersect, storage } from '$lib/features';
import type { User } from '$lib/types';
type Description = Array<
Expand All @@ -20,7 +20,16 @@
export let from: 'github' | 'gitlab';
export let small = false;
$: authorUrl = author && !author.bot ? `https://${from}.com/${author.login}` : '';
$: authorUrl = (() => {
if (!author || author.bot) {
return '';
}
const origin =
from === 'github'
? 'https://github.com'
: (storage.get('gitlab-url') ?? 'https://gitlab.com');
return origin + '/' + author.login;
})();
let displayDescription: Description = (() => {
const parts = description.split(/(\*|_)/);
Expand Down
11 changes: 8 additions & 3 deletions src/lib/components/login/GitlabLoginButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
let error = '';
$: onTauriApp = browser && !!window.__TAURI__;
$: urlWithoutSlash = url.endsWith('/') ? url.slice(0, -1) : url;
$: if (open && browser) {
setTimeout(() => {
Expand Down Expand Up @@ -55,9 +56,9 @@
try {
const response = await fetchGitlab<GitlabUser>('user', {
accessToken: pat,
domain: url
domain: urlWithoutSlash
});
storage.set('gitlab-url', url);
storage.set('gitlab-url', urlWithoutSlash);
storage.set('gitlab-pat', pat);
storage.set('gitlab-user', {
name: response.name,
Expand Down Expand Up @@ -106,7 +107,11 @@
<div class="pat" class:disabled={!(url && urlIsValid)}>
<p class="text">
Create a new PAT
<a class="link" href={`${url}/-/user_settings/personal_access_tokens`} target="_blank">
<a
class="link"
href={`${urlWithoutSlash}/-/user_settings/personal_access_tokens`}
target="_blank"
>
here
</a>
with the <b>read_api</b> and <b>read_user</b> scopes and paste it below:
Expand Down

0 comments on commit 37e081f

Please sign in to comment.