integrations.tsx 11 KB

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