Files
2024-02-15 17:01:50 +00:00

38 lines
1.2 KiB
TypeScript

import * as Sentry from '@sentry/react';
import type {Client} from 'sentry/api';
import RepositoryStore from 'sentry/stores/repositoryStore';
import type {Repository} from 'sentry/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;
RepositoryStore.loadRepositories(orgSlug);
return api
.requestPromise(path, {
method: 'GET',
})
.then((res: Repository[]) => {
RepositoryStore.loadRepositoriesSuccess(res);
})
.catch(err => {
RepositoryStore.loadRepositoriesError(err);
Sentry.withScope(scope => {
scope.setLevel('warning');
scope.setFingerprint(['getRepositories-action-creator']);
Sentry.captureException(err);
});
});
}