integrations.tsx 12 KB

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