integrations.tsx 13 KB

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