integrations.tsx 12 KB

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