integrations.tsx 11 KB

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