committers.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import CommitterActions from 'sentry/actions/committerActions';
  2. import {Client} from 'sentry/api';
  3. import CommitterStore, {getCommitterStoreKey} from 'sentry/stores/committerStore';
  4. import {Committer} from 'sentry/types';
  5. type ParamsGet = {
  6. eventId: string;
  7. orgSlug: string;
  8. projectSlug: string;
  9. };
  10. export function getCommitters(api: Client, params: ParamsGet) {
  11. const {orgSlug, projectSlug, eventId} = params;
  12. const path = `/projects/${orgSlug}/${projectSlug}/events/${eventId}/committers/`;
  13. // HACK(leedongwei): Actions fired by the ActionCreators are queued to
  14. // the back of the event loop, allowing another getRepo for the same
  15. // repo to be fired before the loading state is updated in store.
  16. // This hack short-circuits that and update the state immediately.
  17. const storeKey = getCommitterStoreKey(orgSlug, projectSlug, eventId);
  18. CommitterStore.state[storeKey] = {
  19. ...CommitterStore.state[storeKey],
  20. committersLoading: true,
  21. };
  22. CommitterActions.load(orgSlug, projectSlug, eventId);
  23. return api
  24. .requestPromise(path, {
  25. method: 'GET',
  26. })
  27. .then((res: {committers: Committer[]}) => {
  28. CommitterActions.loadSuccess(orgSlug, projectSlug, eventId, res.committers);
  29. })
  30. .catch(err => {
  31. // NOTE: Do not captureException here as EventFileCommittersEndpoint returns
  32. // 404 Not Found if the project did not setup Releases or Commits
  33. CommitterActions.loadError(orgSlug, projectSlug, eventId, err);
  34. });
  35. }