integrations.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. import type Alert from 'sentry/components/alert';
  2. import type {Field} from 'sentry/components/forms/type';
  3. import type {PlatformKey} from 'sentry/data/platformCategories';
  4. import type {
  5. DISABLED as DISABLED_STATUS,
  6. INSTALLED,
  7. NOT_INSTALLED,
  8. PENDING,
  9. } from 'sentry/views/organizationIntegrations/constants';
  10. import type {Avatar, Choice, Choices, ObjectStatus, Scope} from './core';
  11. import type {BaseRelease} from './release';
  12. import type {User} from './user';
  13. export type PermissionValue = 'no-access' | 'read' | 'write' | 'admin';
  14. export type Permissions = {
  15. Event: PermissionValue;
  16. Member: PermissionValue;
  17. Organization: PermissionValue;
  18. Project: PermissionValue;
  19. Release: PermissionValue;
  20. Team: PermissionValue;
  21. };
  22. export type PermissionResource = keyof Permissions;
  23. export type ExternalActorMapping = {
  24. externalName: string;
  25. id: string;
  26. sentryName: string;
  27. teamId?: string;
  28. userId?: string;
  29. };
  30. export type ExternalActorSuggestion = {
  31. externalName: string;
  32. teamId?: string;
  33. userId?: string;
  34. };
  35. export type ExternalActorMappingOrSuggestion =
  36. | ExternalActorMapping
  37. | ExternalActorSuggestion;
  38. export type ExternalUser = {
  39. externalName: string;
  40. id: string;
  41. integrationId: string;
  42. memberId: string;
  43. provider: string;
  44. };
  45. export type ExternalTeam = {
  46. externalName: string;
  47. id: string;
  48. integrationId: string;
  49. provider: string;
  50. teamId: string;
  51. };
  52. /**
  53. * Repositories, pull requests, and commits
  54. */
  55. export enum RepositoryStatus {
  56. ACTIVE = 'active',
  57. DISABLED = 'disabled',
  58. HIDDEN = 'hidden',
  59. PENDING_DELETION = 'pending_deletion',
  60. DELETION_IN_PROGRESS = 'deletion_in_progress',
  61. }
  62. export type Repository = {
  63. dateCreated: string;
  64. externalSlug: string;
  65. id: string;
  66. integrationId: string;
  67. name: string;
  68. provider: {id: string; name: string};
  69. status: RepositoryStatus;
  70. url: string;
  71. };
  72. export type Commit = {
  73. dateCreated: string;
  74. id: string;
  75. message: string | null;
  76. releases: BaseRelease[];
  77. author?: User;
  78. repository?: Repository;
  79. };
  80. export type Committer = {
  81. author: User;
  82. commits: Commit[];
  83. };
  84. export type CommitAuthor = {
  85. email?: string;
  86. name?: string;
  87. };
  88. export type CommitFile = {
  89. author: CommitAuthor;
  90. commitMessage: string;
  91. filename: string;
  92. id: string;
  93. orgId: number;
  94. repoName: string;
  95. type: string;
  96. };
  97. export type PullRequest = {
  98. externalUrl: string;
  99. id: string;
  100. repository: Repository;
  101. title: string;
  102. };
  103. /**
  104. * Sentry Apps
  105. */
  106. export type SentryAppStatus = 'unpublished' | 'published' | 'internal';
  107. export type SentryAppSchemaIssueLink = {
  108. create: {
  109. required_fields: any[];
  110. uri: string;
  111. optional_fields?: any[];
  112. };
  113. link: {
  114. required_fields: any[];
  115. uri: string;
  116. optional_fields?: any[];
  117. };
  118. type: 'issue-link';
  119. };
  120. export type SentryAppSchemaStacktraceLink = {
  121. type: 'stacktrace-link';
  122. uri: string;
  123. url: string;
  124. params?: Array<string>;
  125. };
  126. export type SentryAppSchemaElement =
  127. | SentryAppSchemaIssueLink
  128. | SentryAppSchemaStacktraceLink;
  129. export type SentryApp = {
  130. author: string;
  131. events: WebhookEvent[];
  132. featureData: IntegrationFeature[];
  133. isAlertable: boolean;
  134. name: string;
  135. overview: string | null;
  136. // possible null params
  137. popularity: number | null;
  138. redirectUrl: string | null;
  139. schema: {
  140. elements?: SentryAppSchemaElement[];
  141. };
  142. scopes: Scope[];
  143. slug: string;
  144. status: SentryAppStatus;
  145. uuid: string;
  146. verifyInstall: boolean;
  147. webhookUrl: string | null;
  148. avatars?: Avatar[];
  149. clientId?: string;
  150. clientSecret?: string;
  151. // optional params below
  152. datePublished?: string;
  153. owner?: {
  154. id: number;
  155. slug: string;
  156. };
  157. };
  158. // Minimal Sentry App representation for use with avatars
  159. export type AvatarSentryApp = {
  160. name: string;
  161. slug: string;
  162. uuid: string;
  163. avatars?: Avatar[];
  164. };
  165. export type SentryAppInstallation = {
  166. app: {
  167. slug: string;
  168. uuid: string;
  169. };
  170. organization: {
  171. slug: string;
  172. };
  173. status: 'installed' | 'pending';
  174. uuid: string;
  175. code?: string;
  176. };
  177. export type SentryAppComponent = {
  178. schema: SentryAppSchemaStacktraceLink;
  179. sentryApp: {
  180. avatars: Avatar[];
  181. name: string;
  182. slug: string;
  183. uuid: string;
  184. };
  185. type: 'issue-link' | 'alert-rule-action' | 'issue-media' | 'stacktrace-link';
  186. uuid: string;
  187. };
  188. export type SentryAppWebhookRequest = {
  189. date: string;
  190. eventType: string;
  191. responseCode: number;
  192. sentryAppSlug: string;
  193. webhookUrl: string;
  194. errorUrl?: string;
  195. organization?: {
  196. name: string;
  197. slug: string;
  198. };
  199. };
  200. /**
  201. * Organization Integrations
  202. */
  203. export type IntegrationType = 'document' | 'plugin' | 'first_party' | 'sentry_app';
  204. export type IntegrationFeature = {
  205. description: string;
  206. featureGate: string;
  207. featureId: number;
  208. };
  209. export type IntegrationInstallationStatus =
  210. | typeof INSTALLED
  211. | typeof NOT_INSTALLED
  212. | typeof PENDING
  213. | typeof DISABLED_STATUS;
  214. type IntegrationDialog = {
  215. actionText: string;
  216. body: string;
  217. };
  218. export type DocIntegration = {
  219. author: string;
  220. description: string;
  221. isDraft: boolean;
  222. name: string;
  223. popularity: number;
  224. slug: string;
  225. url: string;
  226. avatar?: Avatar;
  227. features?: IntegrationFeature[];
  228. resources?: Array<{title: string; url: string}>;
  229. };
  230. type IntegrationAspects = {
  231. alerts?: Array<
  232. React.ComponentProps<typeof Alert> & {text: string; icon?: string | React.ReactNode}
  233. >;
  234. configure_integration?: {
  235. title: string;
  236. };
  237. disable_dialog?: IntegrationDialog;
  238. externalInstall?: {
  239. buttonText: string;
  240. noticeText: string;
  241. url: string;
  242. };
  243. removal_dialog?: IntegrationDialog;
  244. };
  245. type BaseIntegrationProvider = {
  246. canAdd: boolean;
  247. canDisable: boolean;
  248. features: string[];
  249. key: string;
  250. name: string;
  251. slug: string;
  252. };
  253. export type IntegrationProvider = BaseIntegrationProvider & {
  254. metadata: {
  255. aspects: IntegrationAspects;
  256. author: string;
  257. description: string;
  258. features: IntegrationFeature[];
  259. issue_url: string;
  260. noun: string;
  261. source_url: string;
  262. };
  263. setupDialog: {height: number; url: string; width: number};
  264. };
  265. type OrganizationIntegrationProvider = BaseIntegrationProvider & {
  266. aspects: IntegrationAspects;
  267. };
  268. export type Integration = {
  269. accountType: string;
  270. domainName: string;
  271. gracePeriodEnd: string;
  272. icon: string;
  273. id: string;
  274. name: string;
  275. organizationIntegrationStatus: ObjectStatus;
  276. provider: OrganizationIntegrationProvider;
  277. status: ObjectStatus;
  278. dynamicDisplayInformation?: {
  279. configure_integration?: {
  280. instructions: string[];
  281. };
  282. integration_detail?: {
  283. uninstallationUrl?: string;
  284. };
  285. };
  286. scopes?: string[];
  287. };
  288. type ConfigData = {
  289. installationType?: string;
  290. };
  291. export type OrganizationIntegration = {
  292. accountType: string | null;
  293. configData: ConfigData | null;
  294. configOrganization: Field[];
  295. domainName: string | null;
  296. externalId: string;
  297. gracePeriodEnd: string;
  298. icon: string | null;
  299. id: string;
  300. name: string;
  301. organizationId: string;
  302. organizationIntegrationStatus: ObjectStatus;
  303. provider: OrganizationIntegrationProvider;
  304. status: ObjectStatus;
  305. };
  306. // we include the configOrganization when we need it
  307. export type IntegrationWithConfig = Integration & {
  308. configData: ConfigData;
  309. configOrganization: Field[];
  310. };
  311. /**
  312. * Integration & External issue links
  313. */
  314. export type IntegrationExternalIssue = {
  315. description: string;
  316. displayName: string;
  317. id: string;
  318. key: string;
  319. title: string;
  320. url: string;
  321. };
  322. export type GroupIntegration = Integration & {
  323. externalIssues: IntegrationExternalIssue[];
  324. };
  325. export type PlatformExternalIssue = {
  326. displayName: string;
  327. id: string;
  328. issueId: string;
  329. serviceType: string;
  330. webUrl: string;
  331. };
  332. /**
  333. * The issue config form fields we get are basically the form fields we use in
  334. * the UI but with some extra information. Some fields marked optional in the
  335. * form field are guaranteed to exist so we can mark them as required here
  336. */
  337. export type IssueConfigField = Field & {
  338. name: string;
  339. choices?: Choices;
  340. default?: string | number | Choice;
  341. multiple?: boolean;
  342. url?: string;
  343. };
  344. export type IntegrationIssueConfig = {
  345. domainName: string;
  346. icon: string[];
  347. name: string;
  348. provider: IntegrationProvider;
  349. status: ObjectStatus;
  350. createIssueConfig?: IssueConfigField[];
  351. linkIssueConfig?: IssueConfigField[];
  352. };
  353. /**
  354. * Project Plugins
  355. */
  356. export type PluginNoProject = {
  357. assets: Array<{url: string}>;
  358. canDisable: boolean;
  359. // TODO(ts)
  360. contexts: any[];
  361. doc: string;
  362. featureDescriptions: IntegrationFeature[];
  363. features: string[];
  364. hasConfiguration: boolean;
  365. id: string;
  366. isDeprecated: boolean;
  367. isHidden: boolean;
  368. isTestable: boolean;
  369. metadata: any;
  370. name: string;
  371. shortName: string;
  372. slug: string;
  373. // TODO(ts)
  374. status: string;
  375. type: string;
  376. altIsSentryApp?: boolean;
  377. author?: {name: string; url: string};
  378. deprecationDate?: string;
  379. description?: string;
  380. firstPartyAlternative?: string;
  381. resourceLinks?: Array<{title: string; url: string}>;
  382. version?: string;
  383. };
  384. export type Plugin = PluginNoProject & {
  385. enabled: boolean;
  386. };
  387. export type PluginProjectItem = {
  388. configured: boolean;
  389. enabled: boolean;
  390. projectId: string;
  391. projectName: string;
  392. projectPlatform: PlatformKey;
  393. projectSlug: string;
  394. };
  395. export type PluginWithProjectList = PluginNoProject & {
  396. projectList: PluginProjectItem[];
  397. };
  398. export type AppOrProviderOrPlugin =
  399. | SentryApp
  400. | IntegrationProvider
  401. | PluginWithProjectList
  402. | DocIntegration;
  403. /**
  404. * Webhooks and servicehooks
  405. */
  406. export type WebhookEvent = 'issue' | 'error' | 'comment';
  407. export type ServiceHook = {
  408. dateCreated: string;
  409. events: string[];
  410. id: string;
  411. secret: string;
  412. status: string;
  413. url: string;
  414. };
  415. /**
  416. * Codeowners and repository path mappings.
  417. */
  418. export type CodeOwner = {
  419. codeMappingId: string;
  420. dateCreated: string;
  421. dateUpdated: string;
  422. errors: {
  423. missing_external_teams: string[];
  424. missing_external_users: string[];
  425. missing_user_emails: string[];
  426. teams_without_access: string[];
  427. users_without_access: string[];
  428. };
  429. id: string;
  430. provider: 'github' | 'gitlab';
  431. raw: string;
  432. codeMapping?: RepositoryProjectPathConfig;
  433. ownershipSyntax?: string;
  434. };
  435. export type CodeownersFile = {
  436. filepath: string;
  437. html_url: string;
  438. raw: string;
  439. };
  440. export type FilesByRepository = {
  441. [repoName: string]: {
  442. authors?: {[email: string]: CommitAuthor};
  443. types?: Set<string>;
  444. };
  445. };
  446. type BaseRepositoryProjectPathConfig = {
  447. id: string;
  448. projectId: string;
  449. projectSlug: string;
  450. repoId: string;
  451. repoName: string;
  452. sourceRoot: string;
  453. stackRoot: string;
  454. defaultBranch?: string;
  455. };
  456. export type RepositoryProjectPathConfig = BaseRepositoryProjectPathConfig & {
  457. integrationId: string | null;
  458. provider: BaseIntegrationProvider | null;
  459. };
  460. export type RepositoryProjectPathConfigWithIntegration =
  461. BaseRepositoryProjectPathConfig & {
  462. integrationId: string;
  463. provider: BaseIntegrationProvider;
  464. };
  465. export type ServerlessFunction = {
  466. enabled: boolean;
  467. name: string;
  468. outOfDate: boolean;
  469. runtime: string;
  470. version: number;
  471. };
  472. export type SentryFunction = {
  473. author: string;
  474. code: string;
  475. name: string;
  476. slug: string;
  477. overview?: string;
  478. };