integrations.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. import type {AlertProps} 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 extends SentryAppSchemaStacktraceLink | SentryAppSchemaElement =
  224. | SentryAppSchemaStacktraceLink
  225. | SentryAppSchemaElement
  226. > = {
  227. schema: Schema;
  228. sentryApp: {
  229. avatars: Avatar[];
  230. name: string;
  231. slug: string;
  232. uuid: string;
  233. };
  234. type: 'issue-link' | 'alert-rule-action' | 'issue-media' | 'stacktrace-link';
  235. uuid: string;
  236. error?: boolean;
  237. };
  238. export type SentryAppWebhookRequest = {
  239. date: string;
  240. eventType: string;
  241. responseCode: number;
  242. sentryAppSlug: string;
  243. webhookUrl: string;
  244. errorUrl?: string;
  245. organization?: {
  246. name: string;
  247. slug: string;
  248. };
  249. };
  250. /**
  251. * Organization Integrations
  252. */
  253. export type IntegrationType = 'document' | 'plugin' | 'first_party' | 'sentry_app';
  254. export type IntegrationFeature = {
  255. description: string;
  256. featureGate: string;
  257. featureId: number;
  258. };
  259. export type IntegrationInstallationStatus =
  260. | typeof INSTALLED
  261. | typeof NOT_INSTALLED
  262. | typeof PENDING
  263. | typeof DISABLED_STATUS
  264. | typeof PENDING_DELETION;
  265. type IntegrationDialog = {
  266. actionText: string;
  267. body: string;
  268. };
  269. export type DocIntegration = {
  270. author: string;
  271. description: string;
  272. isDraft: boolean;
  273. name: string;
  274. popularity: number;
  275. slug: string;
  276. url: string;
  277. avatar?: Avatar;
  278. features?: IntegrationFeature[];
  279. resources?: Array<{title: string; url: string}>;
  280. };
  281. type IntegrationAspects = {
  282. alerts?: Array<AlertProps & {text: string; icon?: string | React.ReactNode}>;
  283. configure_integration?: {
  284. title: string;
  285. };
  286. disable_dialog?: IntegrationDialog;
  287. externalInstall?: {
  288. buttonText: string;
  289. noticeText: string;
  290. url: string;
  291. };
  292. removal_dialog?: IntegrationDialog;
  293. };
  294. interface BaseIntegrationProvider {
  295. canAdd: boolean;
  296. canDisable: boolean;
  297. features: string[];
  298. key: string;
  299. name: string;
  300. slug: string;
  301. }
  302. export interface IntegrationProvider extends BaseIntegrationProvider {
  303. metadata: {
  304. aspects: IntegrationAspects;
  305. author: string;
  306. description: string;
  307. features: IntegrationFeature[];
  308. issue_url: string;
  309. noun: string;
  310. source_url: string;
  311. };
  312. setupDialog: {height: number; url: string; width: number};
  313. }
  314. export interface OrganizationIntegrationProvider extends BaseIntegrationProvider {
  315. aspects: IntegrationAspects;
  316. }
  317. export interface Integration {
  318. accountType: string;
  319. domainName: string;
  320. gracePeriodEnd: string;
  321. icon: string;
  322. id: string;
  323. name: string;
  324. organizationIntegrationStatus: ObjectStatus;
  325. provider: OrganizationIntegrationProvider;
  326. status: ObjectStatus;
  327. dynamicDisplayInformation?: {
  328. configure_integration?: {
  329. instructions: string[];
  330. };
  331. integration_detail?: {
  332. uninstallationUrl?: string;
  333. };
  334. };
  335. scopes?: string[];
  336. }
  337. type ConfigData = {
  338. installationType?: string;
  339. };
  340. export type OrganizationIntegration = {
  341. accountType: string | null;
  342. configData: ConfigData | null;
  343. configOrganization: Field[];
  344. domainName: string | null;
  345. externalId: string;
  346. gracePeriodEnd: string;
  347. icon: string | null;
  348. id: string;
  349. name: string;
  350. organizationId: string;
  351. organizationIntegrationStatus: ObjectStatus;
  352. provider: OrganizationIntegrationProvider;
  353. status: ObjectStatus;
  354. };
  355. // we include the configOrganization when we need it
  356. export interface IntegrationWithConfig extends Integration {
  357. configData: ConfigData;
  358. configOrganization: Field[];
  359. }
  360. /**
  361. * Integration & External issue links
  362. */
  363. export type IntegrationExternalIssue = {
  364. description: string;
  365. displayName: string;
  366. id: string;
  367. key: string;
  368. title: string;
  369. url: string;
  370. };
  371. export interface GroupIntegration extends Integration {
  372. externalIssues: IntegrationExternalIssue[];
  373. }
  374. export type PlatformExternalIssue = {
  375. displayName: string;
  376. id: string;
  377. issueId: string;
  378. serviceType: string;
  379. webUrl: string;
  380. };
  381. /**
  382. * The issue config form fields we get are basically the form fields we use in
  383. * the UI but with some extra information. Some fields marked optional in the
  384. * form field are guaranteed to exist so we can mark them as required here
  385. */
  386. export type IssueConfigField = Field & {
  387. name: string;
  388. choices?: Choices;
  389. default?: string | number | Choice;
  390. multiple?: boolean;
  391. url?: string;
  392. };
  393. export type IntegrationIssueConfig = {
  394. domainName: string;
  395. icon: string[];
  396. name: string;
  397. provider: IntegrationProvider;
  398. status: ObjectStatus;
  399. createIssueConfig?: IssueConfigField[];
  400. linkIssueConfig?: IssueConfigField[];
  401. };
  402. /**
  403. * Project Plugins
  404. */
  405. export type PluginNoProject = {
  406. assets: Array<{url: string}>;
  407. canDisable: boolean;
  408. // TODO(ts)
  409. contexts: any[];
  410. doc: string;
  411. featureDescriptions: IntegrationFeature[];
  412. features: string[];
  413. hasConfiguration: boolean;
  414. id: string;
  415. isDeprecated: boolean;
  416. isHidden: boolean;
  417. isTestable: boolean;
  418. metadata: any;
  419. name: string;
  420. shortName: string;
  421. slug: string;
  422. // TODO(ts)
  423. status: string;
  424. type: string;
  425. altIsSentryApp?: boolean;
  426. author?: {name: string; url: string};
  427. deprecationDate?: string;
  428. description?: string;
  429. firstPartyAlternative?: string;
  430. resourceLinks?: Array<{title: string; url: string}>;
  431. version?: string;
  432. };
  433. export type Plugin = PluginNoProject & {
  434. enabled: boolean;
  435. };
  436. export type PluginProjectItem = {
  437. configured: boolean;
  438. enabled: boolean;
  439. projectId: string;
  440. projectName: string;
  441. projectPlatform: PlatformKey;
  442. projectSlug: string;
  443. };
  444. export type PluginWithProjectList = PluginNoProject & {
  445. projectList: PluginProjectItem[];
  446. };
  447. export type AppOrProviderOrPlugin =
  448. | SentryApp
  449. | IntegrationProvider
  450. | PluginWithProjectList
  451. | DocIntegration;
  452. /**
  453. * Webhooks and servicehooks
  454. */
  455. export type WebhookEvent = 'issue' | 'error' | 'comment';
  456. export type ServiceHook = {
  457. dateCreated: string;
  458. events: string[];
  459. id: string;
  460. secret: string;
  461. status: string;
  462. url: string;
  463. };
  464. /**
  465. * Codeowners and repository path mappings.
  466. */
  467. export type CodeOwner = {
  468. codeMappingId: string;
  469. /**
  470. * Link to the CODEOWNERS file in source control
  471. * 'unknown' if the api fails to fetch the file
  472. */
  473. codeOwnersUrl: string | 'unknown';
  474. dateCreated: string;
  475. dateUpdated: string;
  476. errors: {
  477. missing_external_teams: string[];
  478. missing_external_users: string[];
  479. missing_user_emails: string[];
  480. teams_without_access: string[];
  481. users_without_access: string[];
  482. };
  483. id: string;
  484. provider: 'github' | 'gitlab';
  485. raw: string;
  486. codeMapping?: RepositoryProjectPathConfig;
  487. ownershipSyntax?: string;
  488. schema?: {rules: ParsedOwnershipRule[]; version: number};
  489. };
  490. export type CodeownersFile = {
  491. filepath: string;
  492. html_url: string;
  493. raw: string;
  494. };
  495. export type FilesByRepository = {
  496. [repoName: string]: {
  497. authors?: {[email: string]: CommitAuthor};
  498. types?: Set<string>;
  499. };
  500. };
  501. interface BaseRepositoryProjectPathConfig {
  502. id: string;
  503. projectId: string;
  504. projectSlug: string;
  505. repoId: string;
  506. repoName: string;
  507. sourceRoot: string;
  508. stackRoot: string;
  509. defaultBranch?: string;
  510. }
  511. export interface RepositoryProjectPathConfig extends BaseRepositoryProjectPathConfig {
  512. integrationId: string | null;
  513. provider: BaseIntegrationProvider | null;
  514. }
  515. export interface RepositoryProjectPathConfigWithIntegration
  516. extends BaseRepositoryProjectPathConfig {
  517. integrationId: string;
  518. provider: BaseIntegrationProvider;
  519. }
  520. export type ServerlessFunction = {
  521. enabled: boolean;
  522. name: string;
  523. outOfDate: boolean;
  524. runtime: string;
  525. version: number;
  526. };
  527. export type SentryFunction = {
  528. author: string;
  529. code: string;
  530. name: string;
  531. slug: string;
  532. env_variables?: Array<{
  533. name: string;
  534. value: string;
  535. }>;
  536. events?: string[];
  537. overview?: string;
  538. };