integrations.tsx 11 KB

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