integrations.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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 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. };
  188. export type SentryAppWebhookRequest = {
  189. date: string;
  190. eventType: string;
  191. responseCode: number;
  192. sentryAppSlug: string;
  193. webhookUrl: string;
  194. errorUrl?: string;
  195. organization?: {
  196. name: string;
  197. slug: string;
  198. };
  199. };
  200. /**
  201. * Organization Integrations
  202. */
  203. export type IntegrationType = 'document' | 'plugin' | 'first_party' | 'sentry_app';
  204. export type IntegrationFeature = {
  205. description: string;
  206. featureGate: string;
  207. featureId: number;
  208. };
  209. export type IntegrationInstallationStatus =
  210. | typeof INSTALLED
  211. | typeof NOT_INSTALLED
  212. | typeof PENDING
  213. | typeof DISABLED_STATUS;
  214. type IntegrationDialog = {
  215. actionText: string;
  216. body: string;
  217. };
  218. export type DocIntegration = {
  219. author: string;
  220. description: string;
  221. isDraft: boolean;
  222. name: string;
  223. popularity: number;
  224. slug: string;
  225. url: string;
  226. avatar?: Avatar;
  227. features?: IntegrationFeature[];
  228. resources?: Array<{title: string; url: string}>;
  229. };
  230. type IntegrationAspects = {
  231. alerts?: Array<React.ComponentProps<typeof Alert> & {text: string}>;
  232. configure_integration?: {
  233. title: string;
  234. };
  235. disable_dialog?: IntegrationDialog;
  236. externalInstall?: {
  237. buttonText: string;
  238. noticeText: string;
  239. url: string;
  240. };
  241. removal_dialog?: IntegrationDialog;
  242. };
  243. type BaseIntegrationProvider = {
  244. canAdd: boolean;
  245. canDisable: boolean;
  246. features: string[];
  247. key: string;
  248. name: string;
  249. slug: string;
  250. };
  251. export type IntegrationProvider = BaseIntegrationProvider & {
  252. metadata: {
  253. aspects: IntegrationAspects;
  254. author: string;
  255. description: string;
  256. features: IntegrationFeature[];
  257. issue_url: string;
  258. noun: string;
  259. source_url: string;
  260. };
  261. setupDialog: {height: number; url: string; width: number};
  262. };
  263. type OrganizationIntegrationProvider = BaseIntegrationProvider & {
  264. aspects: IntegrationAspects;
  265. };
  266. export type Integration = {
  267. accountType: string;
  268. domainName: string;
  269. gracePeriodEnd: string;
  270. icon: string;
  271. id: string;
  272. name: string;
  273. organizationIntegrationStatus: ObjectStatus;
  274. provider: OrganizationIntegrationProvider;
  275. status: ObjectStatus;
  276. dynamicDisplayInformation?: {
  277. configure_integration?: {
  278. instructions: string[];
  279. };
  280. integration_detail?: {
  281. uninstallationUrl?: string;
  282. };
  283. };
  284. scopes?: string[];
  285. };
  286. type ConfigData = {
  287. installationType?: string;
  288. };
  289. export type OrganizationIntegration = {
  290. accountType: string | null;
  291. configData: ConfigData | null;
  292. configOrganization: Field[];
  293. domainName: string | null;
  294. externalId: string;
  295. gracePeriodEnd: string;
  296. icon: string | null;
  297. id: string;
  298. name: string;
  299. organizationId: string;
  300. organizationIntegrationStatus: ObjectStatus;
  301. provider: OrganizationIntegrationProvider;
  302. status: ObjectStatus;
  303. };
  304. // we include the configOrganization when we need it
  305. export type IntegrationWithConfig = Integration & {
  306. configData: ConfigData;
  307. configOrganization: Field[];
  308. };
  309. /**
  310. * Integration & External issue links
  311. */
  312. export type IntegrationExternalIssue = {
  313. description: string;
  314. displayName: string;
  315. id: string;
  316. key: string;
  317. title: string;
  318. url: string;
  319. };
  320. export type GroupIntegration = Integration & {
  321. externalIssues: IntegrationExternalIssue[];
  322. };
  323. export type PlatformExternalIssue = {
  324. displayName: string;
  325. id: string;
  326. issueId: string;
  327. serviceType: string;
  328. webUrl: string;
  329. };
  330. /**
  331. * The issue config form fields we get are basically the form fields we use in
  332. * the UI but with some extra information. Some fields marked optional in the
  333. * form field are guaranteed to exist so we can mark them as required here
  334. */
  335. export type IssueConfigField = Field & {
  336. name: string;
  337. choices?: Choices;
  338. default?: string | number;
  339. multiple?: boolean;
  340. url?: string;
  341. };
  342. export type IntegrationIssueConfig = {
  343. domainName: string;
  344. icon: string[];
  345. name: string;
  346. provider: IntegrationProvider;
  347. status: ObjectStatus;
  348. createIssueConfig?: IssueConfigField[];
  349. linkIssueConfig?: IssueConfigField[];
  350. };
  351. /**
  352. * Project Plugins
  353. */
  354. export type PluginNoProject = {
  355. assets: Array<{url: string}>;
  356. canDisable: boolean;
  357. // TODO(ts)
  358. contexts: any[];
  359. doc: string;
  360. featureDescriptions: IntegrationFeature[];
  361. features: string[];
  362. hasConfiguration: boolean;
  363. id: string;
  364. isDeprecated: boolean;
  365. isHidden: boolean;
  366. isTestable: boolean;
  367. metadata: any;
  368. name: string;
  369. shortName: string;
  370. slug: string;
  371. // TODO(ts)
  372. status: string;
  373. type: string;
  374. altIsSentryApp?: boolean;
  375. author?: {name: string; url: string};
  376. deprecationDate?: string;
  377. description?: string;
  378. firstPartyAlternative?: string;
  379. resourceLinks?: Array<{title: string; url: string}>;
  380. version?: string;
  381. };
  382. export type Plugin = PluginNoProject & {
  383. enabled: boolean;
  384. };
  385. export type PluginProjectItem = {
  386. configured: boolean;
  387. enabled: boolean;
  388. projectId: string;
  389. projectName: string;
  390. projectPlatform: PlatformKey;
  391. projectSlug: string;
  392. };
  393. export type PluginWithProjectList = PluginNoProject & {
  394. projectList: PluginProjectItem[];
  395. };
  396. export type AppOrProviderOrPlugin =
  397. | SentryApp
  398. | IntegrationProvider
  399. | PluginWithProjectList
  400. | DocIntegration;
  401. /**
  402. * Webhooks and servicehooks
  403. */
  404. export type WebhookEvent = 'issue' | 'error' | 'comment';
  405. export type ServiceHook = {
  406. dateCreated: string;
  407. events: string[];
  408. id: string;
  409. secret: string;
  410. status: string;
  411. url: string;
  412. };
  413. /**
  414. * Codeowners and repository path mappings.
  415. */
  416. export type CodeOwner = {
  417. codeMappingId: string;
  418. dateCreated: string;
  419. dateUpdated: string;
  420. errors: {
  421. missing_external_teams: string[];
  422. missing_external_users: string[];
  423. missing_user_emails: string[];
  424. teams_without_access: string[];
  425. users_without_access: string[];
  426. };
  427. id: string;
  428. provider: 'github' | 'gitlab';
  429. raw: string;
  430. codeMapping?: RepositoryProjectPathConfig;
  431. ownershipSyntax?: string;
  432. };
  433. export type CodeownersFile = {
  434. filepath: string;
  435. html_url: string;
  436. raw: string;
  437. };
  438. export type FilesByRepository = {
  439. [repoName: string]: {
  440. authors?: {[email: string]: CommitAuthor};
  441. types?: Set<string>;
  442. };
  443. };
  444. type BaseRepositoryProjectPathConfig = {
  445. id: string;
  446. projectId: string;
  447. projectSlug: string;
  448. repoId: string;
  449. repoName: string;
  450. sourceRoot: string;
  451. stackRoot: string;
  452. defaultBranch?: string;
  453. };
  454. export type RepositoryProjectPathConfig = BaseRepositoryProjectPathConfig & {
  455. integrationId: string | null;
  456. provider: BaseIntegrationProvider | null;
  457. };
  458. export type RepositoryProjectPathConfigWithIntegration =
  459. BaseRepositoryProjectPathConfig & {
  460. integrationId: string;
  461. provider: BaseIntegrationProvider;
  462. };
  463. export type ServerlessFunction = {
  464. enabled: boolean;
  465. name: string;
  466. outOfDate: boolean;
  467. runtime: string;
  468. version: number;
  469. };