Skip to content

Commit

Permalink
Merge branch 'feat/rewrite-skizzle' of https://github.com/AxaGuilDEv/…
Browse files Browse the repository at this point in the history
…Skizzle into feat/rewrite-skizzle
  • Loading branch information
itupix authored and Debaerdm committed Mar 5, 2021
2 parents 29cb1d8 + 4140d92 commit 2824e2e
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 117 deletions.
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ export default {
nodePolyfills(),
svelte({
compilerOptions: {
// enable run-time checks when not in production
dev: !production,
},
preprocess: createPreprocessors(!production),
}),
css({ output: 'bundle.css' }),
css({
output: 'bundle.css',
sourceMap: !production,
}),
resolve({
browser: true,
dedupe: ['svelte'],
Expand Down
52 changes: 26 additions & 26 deletions src/components/AzureDevOps/AzureDevOps.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
import SearchResults from 'components/SearchResults';
import FollowedRepositories from 'components/FollowedRepositories';
import Search from 'components/Search';
import type { RepositoryType } from 'models/skizzle';
import type { ProfileType, RepositoryType } from 'models/skizzle';
let search: string = '';
const onSearchSubmit = (repositories: RepositoryType[]) => (
const onSearchSubmit = (profile: ProfileType) => async (
query: string,
): void => {
) => {
search = query;
fetchedAzureDevOpsRepositories = repositories.filter(
const result = await Service.getRepositories(ProviderEnum.AzureDevOps, { profile });
fetchedAzureDevOpsRepositories = result.filter(
({ projectName, name }) =>
name.toLocaleLowerCase().includes(search.toLocaleLowerCase()) ||
projectName.toLocaleLowerCase().includes(search.toLocaleLowerCase()),
Expand All @@ -44,31 +46,29 @@
<AccountSummary {profile} />
</section>
<div class="content">
{#await Service.getRepositories(ProviderEnum.AzureDevOps, { profile })}
<p class="loader">Chargement de la liste des repositories...</p>
{:then repositories}
<section>
<AccountTitle>Suivre un nouveau repository</AccountTitle>
<p class="intro">
Cherchez le nom de son projet et/ou repository associé.
</p>
<Search
onSubmit={onSearchSubmit(repositories)}
onCancel={onSearchCancel}
disabled={$isFetchingData}
placeholder="Rechercher un projet ou un repos"
/>
<section>
<AccountTitle>Suivre un nouveau repository</AccountTitle>
<p class="intro">
Cherchez le nom de son projet et/ou repository associé.
</p>
<Search
onSubmit={onSearchSubmit(profile)}
onCancel={onSearchCancel}
disabled={$isFetchingData}
placeholder="Rechercher un projet ou un repos"
/>

{#if search}
{#if search}
{#if $isFetchingData}
<p>Recherche en cours...</p>
{:else}
<SearchResults {search} repos={fetchedAzureDevOpsRepositories} />
{/if}
</section>
<section>
<FollowedRepositories {profile} />
</section>
{:catch}
<p class="error">Fetching profile failed.</p>
{/await}
{/if}
</section>
<section>
<FollowedRepositories {profile} />
</section>
</div>
{:catch}
<p class="error">Fetching profile failed.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
Vos repositories suivis
<button
title="Partager votre liste"
disabled={$isFetchingData}
on:click={() => (shareDisplayed = true)}
><Icons.Share /></button>
</AccountTitle>
Expand All @@ -53,7 +52,6 @@
repository.gitUrl,
`L'url du repository est copiée dans le presse-papiers.`,
)}
disabled={$isFetchingData}
title="Copier l'url de ce repository"
>
<Icons.Copy />
Expand All @@ -74,7 +72,6 @@
<ImportExport
{followedRepositories}
bind:shareDisplayed
provider={profile.provider}
/>
</Modale>
{/if}
Expand Down
7 changes: 2 additions & 5 deletions src/components/ImportExport/ImportExport.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<script lang="ts">
import { v4 as uuidv4 } from 'uuid';
import { isFetchingData, notifications, pullRequests, repositories } from 'shared/stores/default.store';
import { notifications, pullRequests, repositories } from 'shared/stores/default.store';
import { HighlightSvelte } from "svelte-highlight";
import { json } from "svelte-highlight/languages";
import Tabs from 'components/Tabs';
import AccountTitle from 'components/AccountTitle';
import { copyToClipboard, isJson } from 'shared/utils';
import Icons from 'components/icons';
import type { RepositoryType, ProviderEnum } from 'models/skizzle';
import 'svelte-highlight/styles/dark.css';
import { Service } from 'services';
import { Service } from 'services';
export let followedRepositories: RepositoryType[];
export let provider: ProviderEnum;
export let shareDisplayed: boolean;
let currentTab: string = 'import';
Expand Down Expand Up @@ -77,7 +75,6 @@ import { Service } from 'services';
<button
class="copy"
on:click={() => copyToClipboard(JSON.stringify(getExportCode(), undefined, 2), 'Code copié dans le presse-papier.')}
disabled={$isFetchingData}
title="Copier l'url de ce repository"
>
<Icons.Copy />
Expand Down
10 changes: 6 additions & 4 deletions src/components/SearchResults/SearchResults.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { checkRepository } from 'utils';
import { isFetchingData, repositories } from 'shared/stores/default.store';
import { repositories } from 'shared/stores/default.store';
import type { RepositoryType } from 'models/skizzle/RepositoryType';
export let search: string;
Expand Down Expand Up @@ -70,11 +70,13 @@
type="checkbox"
id={repository.repositoryId}
checked={$repositories.some(x => x.repositoryId === repository.repositoryId)}
on:change={event => checkRepository(event, repository)}
disabled={$isFetchingData} />
on:change={event => checkRepository(event, repository)} />
<label
class="follow"
for={repository.repositoryId}>{$repositories.some(x => x.repositoryId === repository.repositoryId) ? 'Ne plus suivre' : 'Suivre'}</label>
for={repository.repositoryId}
>
{$repositories.some(x => x.repositoryId === repository.repositoryId) ? 'Ne plus suivre' : 'Suivre'}
</label>
</li>
{/each}
</ul>
Expand Down
11 changes: 11 additions & 0 deletions src/components/Settings/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@
</select>
</Fieldset>

<Fieldset
title="Proxy"
>
<label for="proxy">Serveur et port (ex: http://localhost:3000) : </label>
<input
id="proxy"
type="url"
bind:value={$settings.proxy}
/>
</Fieldset>

<Fieldset
title="Theme"
intro="Choisissez un theme pour l'interface de Skizzle."
Expand Down
2 changes: 0 additions & 2 deletions src/components/Tabs/Tabs.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import Icons from 'components/icons';
import { isFetchingData } from 'shared/stores/default.store';
export let data: any;
export let onChange: (value: any) => void;
export let current: any;
Expand All @@ -15,7 +14,6 @@
class="tab"
class:current={current === tab || Object.keys(data).length === 1}
on:click={() => onChange(tab)}
disabled={$isFetchingData}
>
{#if data[tab].icon}
<svelte:component this={data[tab].icon} />
Expand Down
13 changes: 10 additions & 3 deletions src/electron/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type { SettingsType } from '../models/skizzle/SettingsType';
import { SkizzleUpdaterEnum } from '../models/skizzle/SkizzleUpdaterEnum';
import type { ExportType } from '../models/skizzle/ExportType';
import { WindowEnum } from '../models/skizzle/WindowEnum';
import { requester } from './requester';

try {
require('electron-reloader')(module);
Expand Down Expand Up @@ -76,9 +77,7 @@ const createWindow = () => {
window = null;
});

if (!app.isPackaged) {
window.webContents.openDevTools();
}
window.webContents.openDevTools({ mode: 'detach' });

//@ts-ignore
window.on('render-process-gone', () => hangOrCrash(window));
Expand Down Expand Up @@ -373,6 +372,14 @@ if (!gotTheLock) {
},
);

ipcMain.handle('request', async (event, args) => {
const { url, options, settings } = JSON.parse(args);

options['user-agent'] = window.webContents.session.getUserAgent();

return requester(url, options, settings);
});

ipcMain.on('notifier', (event, arg) => {
if (Notification.isSupported()) {
const iconName =
Expand Down
24 changes: 24 additions & 0 deletions src/electron/requester.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { SettingsType } from '../models/skizzle/SettingsType';
import type { HeaderType } from '../models/skizzle/HeaderType';

var superagent = require('superagent');
require('superagent-proxy')(superagent);

export const requester = async (
url: string,
headers?: HeaderType,
settings?: SettingsType,
) => {
try {
const result = await superagent
.get(url)
.retry(3)
.proxy(settings.proxy)
.set('User-Agent', headers['user-agent'])
.auth(headers?.authorization, { type: 'bearer' });

return result.body;
} catch (error) {
throw new Error(error);
}
};
6 changes: 6 additions & 0 deletions src/models/skizzle/HeaderType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type HeaderType = {
accept?: string;
'content-type'?: string;
authorization?: string;
'user-agent'?: string;
};
2 changes: 2 additions & 0 deletions src/models/skizzle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { ReviewType } from './ReviewType';
import type { SettingsType } from './SettingsType';
import type { NotificationType } from './NotificationType';
import type { ExportType } from './ExportType';
import type { HeaderType } from './HeaderType';

import { ProviderEnum } from './ProviderEnum';
import { ThemeEnum } from './ThemeEnum';
Expand All @@ -32,6 +33,7 @@ export type {
UserType,
NotificationType,
ExportType,
HeaderType,
};

export { ProviderEnum, ThemeEnum, Views, SkizzleUpdaterEnum, WindowEnum };
19 changes: 6 additions & 13 deletions src/requesters/OAuthAzureDevOps.requester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@ import type {
AzureDevOpsReviewApiType,
AzureDevOpsReviewsApiType,
} from 'models/api';
import type { HeaderType } from 'models/skizzle';
import type { OAuthAzureDevOpsConfigType } from 'providers/OAuthAzureDevOpsConfig.provider';
import { Requester } from './Requester';

export class OAuthAzureDevOpsRequester extends Requester<OAuthAzureDevOpsConfigType> {
private readonly API_VERSION = '6.1-preview';

protected getHeader(config: OAuthAzureDevOpsConfigType): HeadersInit {
const headers = new window.Headers();

headers.append('Content-Type', 'application/json');
headers.append('Authorization', `bearer ${config.access_token}`);

return headers;
protected getHeader(config: OAuthAzureDevOpsConfigType): HeaderType {
return {
'content-type': 'application/json',
authorization: config.access_token,
};
}

public async getProfile(userId: string): Promise<AzureDevOpsProfileApiType> {
Expand All @@ -41,9 +40,6 @@ export class OAuthAzureDevOpsRequester extends Requester<OAuthAzureDevOpsConfigT
return (
await super.fetch<AzureDevOpsDescriptorApiType>(
`https://vssps.dev.azure.com/_apis/graph/descriptors/${userId}?api-version=${this.API_VERSION}`,
{
cache: true,
},
)
).value;
}
Expand All @@ -55,9 +51,6 @@ export class OAuthAzureDevOpsRequester extends Requester<OAuthAzureDevOpsConfigT
return (
await super.fetch<AzureDevOpsAvatarApiType>(
`https://vssps.dev.azure.com/${organizationName}/_apis/graph/Subjects/${descriptor}/avatars?size=large&api-version=${this.API_VERSION}`,
{
cache: true,
},
)
).value;
}
Expand Down
15 changes: 7 additions & 8 deletions src/requesters/OAuthGithub.requester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ import type {
GithubReviewApiType,
GithubReviewsApiType,
} from 'models/api';
import type { HeaderType } from 'models/skizzle';
import type { OAuthGithubConfigType } from 'providers/OAuthGithubConfig.provider';
import { Requester } from './Requester';

export class OAuthGithubRequester extends Requester<OAuthGithubConfigType> {
protected getHeader(config: OAuthGithubConfigType): HeadersInit {
const headers = new window.Headers();

headers.append('Accept', 'application/vnd.github.v3+json');
headers.append('Authorization', `bearer ${config.access_token}`);

return headers;
protected getHeader(config: OAuthGithubConfigType): HeaderType {
return {
accept: 'application/vnd.github.v3+json',
authorization: config.access_token,
};
}

public async getProfile(): Promise<GithubProfileApiType> {
Expand Down Expand Up @@ -74,7 +73,7 @@ export class OAuthGithubRequester extends Requester<OAuthGithubConfigType> {
pullRequest?: string,
): Promise<GithubCommentApiType[]> {
return super.fetch<GithubCommentsApiType>(
`https://api.github.com/repos/${owner}/${repository}/issues/${pullRequest}/comments?sort=updated`,
`https://api.github.com/repos/${owner}/${repository}/pulls/${pullRequest}/comments?sort=updated`,
);
}

Expand Down
Loading

0 comments on commit 2824e2e

Please sign in to comment.