integrations.tsx 12 KB

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