repositories.tsx 1.2 KB

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