environments.tsx 845 B

12345678910111213141516171819202122232425262728
  1. import {Client} from 'sentry/api';
  2. import OrganizationEnvironmentsStore from 'sentry/stores/organizationEnvironmentsStore';
  3. /**
  4. * Fetches all environments for an organization
  5. *
  6. * @param organizationSlug The organization slug
  7. */
  8. export async function fetchOrganizationEnvironments(
  9. api: Client,
  10. organizationSlug: string
  11. ) {
  12. OrganizationEnvironmentsStore.onFetchEnvironments();
  13. try {
  14. const environments = await api.requestPromise(
  15. `/organizations/${organizationSlug}/environments/`
  16. );
  17. if (!environments) {
  18. OrganizationEnvironmentsStore.onFetchEnvironmentsError(
  19. new Error('retrieved environments is falsey')
  20. );
  21. return;
  22. }
  23. OrganizationEnvironmentsStore.onFetchEnvironmentsSuccess(environments);
  24. } catch (err) {
  25. OrganizationEnvironmentsStore.onFetchEnvironmentsError(err);
  26. }
  27. }