integrations.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. import type {AlertProps} from 'sentry/components/alert';
  2. import type {Field} from 'sentry/components/forms/types';
  3. import type {
  4. DISABLED as DISABLED_STATUS,
  5. INSTALLED,
  6. NOT_INSTALLED,
  7. PENDING,
  8. PENDING_DELETION,
  9. } from 'sentry/views/settings/organizationIntegrations/constants';
  10. import type {Avatar, Choice, Choices, ObjectStatus, Scope} from './core';
  11. import type {ParsedOwnershipRule} from './group';
  12. import type {PlatformKey} from './project';
  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 Integration {
  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. canDisable: boolean;
  409. // TODO(ts)
  410. contexts: any[];
  411. doc: string;
  412. featureDescriptions: IntegrationFeature[];
  413. features: string[];
  414. hasConfiguration: boolean;
  415. id: string;
  416. isDeprecated: boolean;
  417. isHidden: boolean;
  418. isTestable: boolean;
  419. metadata: any;
  420. name: string;
  421. shortName: string;
  422. slug: string;
  423. status: string;
  424. type: string;
  425. altIsSentryApp?: boolean;
  426. author?: {name: string; url: string};
  427. deprecationDate?: string;
  428. description?: string;
  429. firstPartyAlternative?: string;
  430. issue?: {
  431. issue_id: string;
  432. // TODO(TS): Label can be an object, unknown shape
  433. label: string | any;
  434. url: string;
  435. };
  436. resourceLinks?: Array<{title: string; url: string}>;
  437. version?: string;
  438. };
  439. export type Plugin = PluginNoProject & {
  440. enabled: boolean;
  441. };
  442. export type PluginProjectItem = {
  443. configured: boolean;
  444. enabled: boolean;
  445. projectId: string;
  446. projectName: string;
  447. projectPlatform: PlatformKey;
  448. projectSlug: string;
  449. };
  450. export type PluginWithProjectList = PluginNoProject & {
  451. projectList: PluginProjectItem[];
  452. };
  453. export type AppOrProviderOrPlugin =
  454. | SentryApp
  455. | IntegrationProvider
  456. | PluginWithProjectList
  457. | DocIntegration;
  458. /**
  459. * Webhooks and servicehooks
  460. */
  461. export type WebhookEvent = 'issue' | 'error' | 'comment';
  462. export type ServiceHook = {
  463. dateCreated: string;
  464. events: string[];
  465. id: string;
  466. secret: string;
  467. status: string;
  468. url: string;
  469. };
  470. /**
  471. * Codeowners and repository path mappings.
  472. */
  473. export type CodeOwner = {
  474. codeMappingId: string;
  475. /**
  476. * Link to the CODEOWNERS file in source control
  477. * 'unknown' if the api fails to fetch the file
  478. */
  479. codeOwnersUrl: string | 'unknown';
  480. dateCreated: string;
  481. dateUpdated: string;
  482. errors: {
  483. missing_external_teams: string[];
  484. missing_external_users: string[];
  485. missing_user_emails: string[];
  486. teams_without_access: string[];
  487. users_without_access: string[];
  488. };
  489. id: string;
  490. provider: 'github' | 'gitlab';
  491. raw: string;
  492. codeMapping?: RepositoryProjectPathConfig;
  493. ownershipSyntax?: string;
  494. schema?: {rules: ParsedOwnershipRule[]; version: number};
  495. };
  496. export type CodeownersFile = {
  497. filepath: string;
  498. html_url: string;
  499. raw: string;
  500. };
  501. export type FilesByRepository = {
  502. [repoName: string]: {
  503. authors?: {[email: string]: CommitAuthor};
  504. types?: Set<string>;
  505. };
  506. };
  507. interface BaseRepositoryProjectPathConfig {
  508. id: string;
  509. projectId: string;
  510. projectSlug: string;
  511. repoId: string;
  512. repoName: string;
  513. sourceRoot: string;
  514. stackRoot: string;
  515. defaultBranch?: string;
  516. }
  517. export interface RepositoryProjectPathConfig extends BaseRepositoryProjectPathConfig {
  518. integrationId: string | null;
  519. provider: BaseIntegrationProvider | null;
  520. }
  521. export interface RepositoryProjectPathConfigWithIntegration
  522. extends BaseRepositoryProjectPathConfig {
  523. integrationId: string;
  524. provider: BaseIntegrationProvider;
  525. }
  526. export type ServerlessFunction = {
  527. enabled: boolean;
  528. name: string;
  529. outOfDate: boolean;
  530. runtime: string;
  531. version: number;
  532. };