-
-
Notifications
You must be signed in to change notification settings - Fork 4k
/
repositories.tsx
38 lines (33 loc) · 1.22 KB
/
repositories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import * as Sentry from '@sentry/react';
import RepositoryActions from 'app/actions/repositoryActions';
import {Client} from 'app/api';
import RepositoryStore from 'app/stores/repositoryStore';
import {Repository} from 'app/types';
type ParamsGet = {
orgSlug: string;
};
export function getRepositories(api: Client, params: ParamsGet) {
const {orgSlug} = params;
const path = `/organizations/${orgSlug}/repos/`;
// HACK(leedongwei): Actions fired by the ActionCreators are queued to
// the back of the event loop, allowing another getRepo for the same
// repo to be fired before the loading state is updated in store.
// This hack short-circuits that and update the state immediately.
RepositoryStore.state.repositoriesLoading = true;
RepositoryActions.loadRepositories(orgSlug);
return api
.requestPromise(path, {
method: 'GET',
})
.then((res: Repository[]) => {
RepositoryActions.loadRepositoriesSuccess(res);
})
.catch(err => {
RepositoryActions.loadRepositoriesError(err);
Sentry.withScope(scope => {
scope.setLevel(Sentry.Severity.Warning);
scope.setFingerprint(['getRepositories-action-creator']);
Sentry.captureException(err);
});
});
}