integrations.tsx 12 KB

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