integrations.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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: 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<AlertProps & {text: string; icon?: string | React.ReactNode}>;
  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. /**
  466. * Link to the CODEOWNERS file in source control
  467. * 'unknown' if the api fails to fetch the file
  468. */
  469. codeOwnersUrl: string | 'unknown';
  470. dateCreated: string;
  471. dateUpdated: string;
  472. errors: {
  473. missing_external_teams: string[];
  474. missing_external_users: string[];
  475. missing_user_emails: string[];
  476. teams_without_access: string[];
  477. users_without_access: string[];
  478. };
  479. id: string;
  480. provider: 'github' | 'gitlab';
  481. raw: string;
  482. codeMapping?: RepositoryProjectPathConfig;
  483. ownershipSyntax?: string;
  484. schema?: {rules: ParsedOwnershipRule[]; version: number};
  485. };
  486. export type CodeownersFile = {
  487. filepath: string;
  488. html_url: string;
  489. raw: string;
  490. };
  491. export type FilesByRepository = {
  492. [repoName: string]: {
  493. authors?: {[email: string]: CommitAuthor};
  494. types?: Set<string>;
  495. };
  496. };
  497. interface BaseRepositoryProjectPathConfig {
  498. id: string;
  499. projectId: string;
  500. projectSlug: string;
  501. repoId: string;
  502. repoName: string;
  503. sourceRoot: string;
  504. stackRoot: string;
  505. defaultBranch?: string;
  506. }
  507. export interface RepositoryProjectPathConfig extends BaseRepositoryProjectPathConfig {
  508. integrationId: string | null;
  509. provider: BaseIntegrationProvider | null;
  510. }
  511. export interface RepositoryProjectPathConfigWithIntegration
  512. extends BaseRepositoryProjectPathConfig {
  513. integrationId: string;
  514. provider: BaseIntegrationProvider;
  515. }
  516. export type ServerlessFunction = {
  517. enabled: boolean;
  518. name: string;
  519. outOfDate: boolean;
  520. runtime: string;
  521. version: number;
  522. };
  523. export type SentryFunction = {
  524. author: string;
  525. code: string;
  526. name: string;
  527. slug: string;
  528. env_variables?: Array<{
  529. name: string;
  530. value: string;
  531. }>;
  532. events?: string[];
  533. overview?: string;
  534. };