integrations.tsx 13 KB

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