integrations.tsx 12 KB

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