integrations.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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. interface CommonIntegration {
  319. accountType: string | null;
  320. domainName: string | null;
  321. gracePeriodEnd: string | null;
  322. icon: string | null;
  323. id: string;
  324. name: string;
  325. organizationIntegrationStatus: ObjectStatus;
  326. provider: OrganizationIntegrationProvider;
  327. status: ObjectStatus;
  328. }
  329. export interface Integration extends CommonIntegration {
  330. dynamicDisplayInformation?: {
  331. configure_integration?: {
  332. instructions: string[];
  333. };
  334. integration_detail?: {
  335. uninstallationUrl?: string;
  336. };
  337. };
  338. scopes?: string[];
  339. }
  340. type ConfigData = {
  341. installationType?: string;
  342. };
  343. export interface OrganizationIntegration extends CommonIntegration {
  344. configData: ConfigData | null;
  345. configOrganization: Field[];
  346. externalId: string;
  347. organizationId: string;
  348. }
  349. // we include the configOrganization when we need it
  350. export interface IntegrationWithConfig extends Integration {
  351. configData: ConfigData;
  352. configOrganization: Field[];
  353. }
  354. /**
  355. * Integration & External issue links
  356. */
  357. export type IntegrationExternalIssue = {
  358. description: string;
  359. displayName: string;
  360. id: string;
  361. key: string;
  362. title: string;
  363. url: string;
  364. };
  365. export interface GroupIntegration extends Integration {
  366. externalIssues: IntegrationExternalIssue[];
  367. }
  368. export type PlatformExternalIssue = {
  369. displayName: string;
  370. id: string;
  371. issueId: string;
  372. serviceType: string;
  373. webUrl: string;
  374. };
  375. /**
  376. * The issue config form fields we get are basically the form fields we use in
  377. * the UI but with some extra information. Some fields marked optional in the
  378. * form field are guaranteed to exist so we can mark them as required here
  379. */
  380. export type IssueConfigField = Field & {
  381. name: string;
  382. choices?: Choices;
  383. default?: string | number | Choice;
  384. multiple?: boolean;
  385. url?: string;
  386. };
  387. export type IntegrationIssueConfig = {
  388. domainName: string;
  389. icon: string[];
  390. name: string;
  391. provider: IntegrationProvider;
  392. status: ObjectStatus;
  393. createIssueConfig?: IssueConfigField[];
  394. linkIssueConfig?: IssueConfigField[];
  395. };
  396. /**
  397. * Project Plugins
  398. */
  399. export type PluginNoProject = {
  400. assets: Array<{url: string}>;
  401. canDisable: boolean;
  402. // TODO(ts)
  403. contexts: any[];
  404. doc: string;
  405. featureDescriptions: IntegrationFeature[];
  406. features: string[];
  407. hasConfiguration: boolean;
  408. id: string;
  409. isDeprecated: boolean;
  410. isHidden: boolean;
  411. isTestable: boolean;
  412. metadata: any;
  413. name: string;
  414. shortName: string;
  415. slug: string;
  416. // TODO(ts)
  417. status: string;
  418. type: string;
  419. altIsSentryApp?: boolean;
  420. author?: {name: string; url: string};
  421. deprecationDate?: string;
  422. description?: string;
  423. firstPartyAlternative?: string;
  424. resourceLinks?: Array<{title: string; url: string}>;
  425. version?: string;
  426. };
  427. export type Plugin = PluginNoProject & {
  428. enabled: boolean;
  429. };
  430. export type PluginProjectItem = {
  431. configured: boolean;
  432. enabled: boolean;
  433. projectId: string;
  434. projectName: string;
  435. projectPlatform: PlatformKey;
  436. projectSlug: string;
  437. };
  438. export type PluginWithProjectList = PluginNoProject & {
  439. projectList: PluginProjectItem[];
  440. };
  441. export type AppOrProviderOrPlugin =
  442. | SentryApp
  443. | IntegrationProvider
  444. | PluginWithProjectList
  445. | DocIntegration;
  446. /**
  447. * Webhooks and servicehooks
  448. */
  449. export type WebhookEvent = 'issue' | 'error' | 'comment';
  450. export type ServiceHook = {
  451. dateCreated: string;
  452. events: string[];
  453. id: string;
  454. secret: string;
  455. status: string;
  456. url: string;
  457. };
  458. /**
  459. * Codeowners and repository path mappings.
  460. */
  461. export type CodeOwner = {
  462. codeMappingId: string;
  463. /**
  464. * Link to the CODEOWNERS file in source control
  465. * 'unknown' if the api fails to fetch the file
  466. */
  467. codeOwnersUrl: string | 'unknown';
  468. dateCreated: string;
  469. dateUpdated: string;
  470. errors: {
  471. missing_external_teams: string[];
  472. missing_external_users: string[];
  473. missing_user_emails: string[];
  474. teams_without_access: string[];
  475. users_without_access: string[];
  476. };
  477. id: string;
  478. provider: 'github' | 'gitlab';
  479. raw: string;
  480. codeMapping?: RepositoryProjectPathConfig;
  481. ownershipSyntax?: string;
  482. schema?: {rules: ParsedOwnershipRule[]; version: number};
  483. };
  484. export type CodeownersFile = {
  485. filepath: string;
  486. html_url: string;
  487. raw: string;
  488. };
  489. export type FilesByRepository = {
  490. [repoName: string]: {
  491. authors?: {[email: string]: CommitAuthor};
  492. types?: Set<string>;
  493. };
  494. };
  495. interface BaseRepositoryProjectPathConfig {
  496. id: string;
  497. projectId: string;
  498. projectSlug: string;
  499. repoId: string;
  500. repoName: string;
  501. sourceRoot: string;
  502. stackRoot: string;
  503. defaultBranch?: string;
  504. }
  505. export interface RepositoryProjectPathConfig extends BaseRepositoryProjectPathConfig {
  506. integrationId: string | null;
  507. provider: BaseIntegrationProvider | null;
  508. }
  509. export interface RepositoryProjectPathConfigWithIntegration
  510. extends BaseRepositoryProjectPathConfig {
  511. integrationId: string;
  512. provider: BaseIntegrationProvider;
  513. }
  514. export type ServerlessFunction = {
  515. enabled: boolean;
  516. name: string;
  517. outOfDate: boolean;
  518. runtime: string;
  519. version: number;
  520. };
  521. export type SentryFunction = {
  522. author: string;
  523. code: string;
  524. name: string;
  525. slug: string;
  526. env_variables?: Array<{
  527. name: string;
  528. value: string;
  529. }>;
  530. events?: string[];
  531. overview?: string;
  532. };