committers.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import type {Client} from 'sentry/api';
  2. import CommitterStore, {getCommitterStoreKey} from 'sentry/stores/committerStore';
  3. import type {Committer, ReleaseCommitter} from 'sentry/types';
  4. type ParamsGet = {
  5. eventId: string;
  6. orgSlug: string;
  7. projectSlug: string;
  8. };
  9. export function getCommitters(api: Client, params: ParamsGet) {
  10. const {orgSlug, projectSlug, eventId} = params;
  11. const path = `/projects/${orgSlug}/${projectSlug}/events/${eventId}/committers/`;
  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. const storeKey = getCommitterStoreKey(orgSlug, projectSlug, eventId);
  17. CommitterStore.state[storeKey] = {
  18. ...CommitterStore.state[storeKey],
  19. committersLoading: true,
  20. };
  21. CommitterStore.load(orgSlug, projectSlug, eventId);
  22. return api
  23. .requestPromise(path, {
  24. method: 'GET',
  25. })
  26. .then((res: {committers: Committer[]; releaseCommitters: ReleaseCommitter[]}) => {
  27. CommitterStore.loadSuccess(
  28. orgSlug,
  29. projectSlug,
  30. eventId,
  31. res.committers,
  32. res.releaseCommitters
  33. );
  34. })
  35. .catch(err => {
  36. // NOTE: Do not captureException here as EventFileCommittersEndpoint returns
  37. // 404 Not Found if the project did not setup Releases or Commits
  38. CommitterStore.loadError(orgSlug, projectSlug, eventId, err);
  39. });
  40. }