integrations.tsx 11 KB

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