integrations.tsx 12 KB

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