integrations.tsx 12 KB

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