integrations.tsx 11 KB

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