integrations.tsx 13 KB

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