integrations.tsx 12 KB

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