repositories.tsx 1.2 KB

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