diff --git a/.changeset/flat-crabs-love.md b/.changeset/flat-crabs-love.md new file mode 100644 index 0000000000..96f566d712 --- /dev/null +++ b/.changeset/flat-crabs-love.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-node': minor +--- + +Added refresh function to the `EntityProviderConnection` to be able to schedule refreshes from entity providers. diff --git a/.changeset/gorgeous-pillows-retire.md b/.changeset/gorgeous-pillows-retire.md new file mode 100644 index 0000000000..d6d4009ac2 --- /dev/null +++ b/.changeset/gorgeous-pillows-retire.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-react': patch +--- + +Support showing counts in option labels of the `EntityTagPicker`. You can enable this by adding the `showCounts` property diff --git a/.changeset/large-books-deny.md b/.changeset/large-books-deny.md new file mode 100644 index 0000000000..c88d391639 --- /dev/null +++ b/.changeset/large-books-deny.md @@ -0,0 +1,5 @@ +--- +'@backstage/catalog-client': minor +--- + +Adding `validateEntity` method that calls `/validate-entity` endpoint. diff --git a/.changeset/rude-weeks-retire.md b/.changeset/rude-weeks-retire.md new file mode 100644 index 0000000000..c2073c5826 --- /dev/null +++ b/.changeset/rude-weeks-retire.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': minor +--- + +Added the `refresh` function to the Connection of the entity providers. diff --git a/.changeset/tame-socks-sniff.md b/.changeset/tame-socks-sniff.md new file mode 100644 index 0000000000..b6cca23380 --- /dev/null +++ b/.changeset/tame-socks-sniff.md @@ -0,0 +1,6 @@ +--- +'@backstage/app-defaults': patch +'@backstage/test-utils': patch +--- + +Add missing peer dependencies diff --git a/.changeset/weak-radios-sin.md b/.changeset/weak-radios-sin.md new file mode 100644 index 0000000000..e2aac006d4 --- /dev/null +++ b/.changeset/weak-radios-sin.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Updated `versions:bump` command to be compatible with Yarn 3. diff --git a/microsite/blog/2022-09-08-fyi-plugin-analytics-api.md b/microsite/blog/2022-09-08-fyi-plugin-analytics-api.md new file mode 100644 index 0000000000..4fba242e3e --- /dev/null +++ b/microsite/blog/2022-09-08-fyi-plugin-analytics-api.md @@ -0,0 +1,92 @@ +--- +# prettier-ignore +title: FYI 📣 The Plugin Analytics API +author: Eric Peterson, Spotify +authorURL: https://github.com/iamEAP +authorImageURL: https://avatars.githubusercontent.com/u/3496491?v=4 +--- + +**TL;DR** If you didn't know, now you know: the Backstage plugin analytics API is here to help you understand how developers in your organization are using Backstage. + +![The Plugin Analytics API](assets/22-09-08/analytics-api-fyi.png) + + + +## What is the plugin analytics API? + +The plugin analytics API is a [utility api](https://backstage.io/docs/api/utility-apis) available by default in every Backstage instance, intended to bridge the gap between the needs of Backstage integrators and plugin developers. While Backstage integrators want visibility into the plugins they’ve installed, they lack the power to instrument those plugins. And although plugin developers have the power to instrument plugins, they can’t do so without a single, vendor-agnostic way to track events. Enter: the plugin analytics API. + +While “analytics” as a concept can be broad, the goal of the API is narrowly focused: empower those deploying Backstage to understand usage of their instance. The plugin analytics API isn’t designed to solve for observability use-cases like tracing, logging, performance monitoring, error metrics, or alerting. Rather, the API is designed to capture and quantify real user interactions, which can form the basis for metrics like daily active users, top plugins, and more. + +## Start collecting data + +Backstage core (and a few other plugins) are already instrumented with [key events](https://backstage.io/docs/plugins/analytics#key-events) that are ready for you to start collecting and analyzing. + +The simplest way to get started is to use one of the [supported analytics tools](https://backstage.io/docs/plugins/analytics#supported-analytics-tools) and install its provided API implementation like you would any other utility API. For example: + +```tsx +// packages/app/src/apis.ts +import { + analyticsApiRef, + configApiRef, + identityApiRef, +} from '@backstage/core-plugin-api'; +import { GoogleAnalytics } from '@backstage/plugin-analytics-module-ga'; + +export const apis: AnyApiFactory[] = [ + // Instantiate and register the GA Analytics API Implementation. + createApiFactory({ + api: analyticsApiRef, + deps: { configApi: configApiRef, identityApi: identityApiRef }, + factory: ({ configApi, identityApi }) => + GoogleAnalytics.fromConfig(configApi, { + identityApi, + }), + }), +]; +``` + +If your chosen analytics tool doesn’t have an integration yet, you can write a custom integration by [following these instructions](https://backstage.io/docs/plugins/analytics#writing-integrations). (And if you’re integrating with a publicly available analytics service, as opposed to a custom in-house system, why not [consider contributing it back to the community](https://backstage.io/docs/plugins/create-a-plugin)?) + +## Instrument plugins + +While some key events are already instrumented, there may be important actions in open source plugins that are un-instrumented, not to mention in your custom, InnerSource plugins. Luckily, the plugin analytics API can be leveraged by open source and InnerSource plugins all the same. + +To capture an event, invoke the `useAnalytics()` react hook and call the function it returns when the user performs the action you wish to track (e.g. merging a pull request): + +```tsx +import { useAnalytics } from '@backstage/core-plugin-api'; + +const analytics = useAnalytics(); +analytics.captureEvent('merge', pullRequestName); +``` + +Don’t worry about having to stuff additional levels of detail into just the event action and subject, you can provide extra dimensional data on the `attributes` property, as well as a primary metric on the `value` property, like this: + +```tsx +analytics.captureEvent('merge', pullRequestName, { + value: pullRequestAgeInMinutes, + attributes: { + org: orgName, + repo: repoName, + }, +}); +``` + +In situations where your plugin is tracking multiple events and you want all of those events to share common dimensional data, you can use the ``. Every event captured in child components underneath this context automatically inherits the values you set: + +```tsx +import { AnalyticsContext } from '@backstage/core-plugin-api'; + + + {children} +` to automatically decorate every event with a corresponding plugin ID and an extension name in order to facilitate plugin-level analysis. + +While the above should be enough to get you going, don’t forget to check out [the complete guide to event capture](https://backstage.io/docs/plugins/analytics#capturing-events), which covers event naming considerations, testing, and more. + +## Get involved + +If you didn’t know, now you know! If you’re passionate about data and want to help push the Backstage analytics ecosystem forward, join us in the [#analytics channel on discord](https://discord.com/channels/687207715902193673/1007303347914690610), contribute [integration ideas](https://github.com/backstage/backstage/issues/new?assignees=&labels=plugin&template=plugin_template.md&title=%5BAnalytics+Module%5D+THE+ANALYTICS+TOOL+TO+INTEGRATE), or [suggest a new analytics event](https://github.com/backstage/backstage/issues/new?assignees=&labels=enhancement&template=feature_template.md&title=[Analytics%20Event]:%20THE+EVENT+TO+CAPTURE). diff --git a/microsite/blog/assets/22-09-08/analytics-api-fyi.png b/microsite/blog/assets/22-09-08/analytics-api-fyi.png new file mode 100644 index 0000000000..444d3fa465 Binary files /dev/null and b/microsite/blog/assets/22-09-08/analytics-api-fyi.png differ diff --git a/microsite/data/plugins/backstage-plugin-ldap-auth.yml b/microsite/data/plugins/backstage-plugin-ldap-auth.yml new file mode 100644 index 0000000000..1800f7370c --- /dev/null +++ b/microsite/data/plugins/backstage-plugin-ldap-auth.yml @@ -0,0 +1,9 @@ +--- +title: LDAP Auth +author: ImmobiliareLabs +authorUrl: https://github.com/immobiliare +category: Authentication +description: Authenticate users to an external LDAP server +documentation: https://github.com/immobiliare/backstage-plugin-ldap-auth/blob/main/README.md +iconUrl: https://avatars.githubusercontent.com/u/10090828 +npmPackageName: '@immobiliarelabs/backstage-plugin-ldap-auth' diff --git a/package.json b/package.json index 312d71858d..3c9e2743cb 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "concurrently": "^7.0.0", "cross-env": "^7.0.0", "e2e-test": "workspace:*", + "eslint": "^8.6.0", "eslint-plugin-notice": "^0.9.10", "fs-extra": "10.1.0", "husky": "^8.0.0", diff --git a/packages/app-defaults/package.json b/packages/app-defaults/package.json index 6ed935394f..355a7ee77e 100644 --- a/packages/app-defaults/package.json +++ b/packages/app-defaults/package.json @@ -42,6 +42,8 @@ }, "peerDependencies": { "react": "^16.13.1 || ^17.0.0", + "react-dom": "^16.13.1 || ^17.0.0", + "react-router": "6.0.0-beta.0 || ^6.3.0", "react-router-dom": "6.0.0-beta.0 || ^6.3.0" }, "devDependencies": { diff --git a/packages/app/package.json b/packages/app/package.json index 2faeb38a6c..e9c9632d81 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -66,10 +66,10 @@ "@material-ui/icons": "^4.9.1", "@material-ui/lab": "4.0.0-alpha.57", "@octokit/rest": "^19.0.3", - "@roadiehq/backstage-plugin-buildkite": "^2.0.0", - "@roadiehq/backstage-plugin-github-insights": "^2.0.0", - "@roadiehq/backstage-plugin-github-pull-requests": "^2.0.0", - "@roadiehq/backstage-plugin-travis-ci": "^2.0.0", + "@roadiehq/backstage-plugin-buildkite": "^2.0.8", + "@roadiehq/backstage-plugin-github-insights": "^2.0.5", + "@roadiehq/backstage-plugin-github-pull-requests": "^2.2.7", + "@roadiehq/backstage-plugin-travis-ci": "^2.0.5", "history": "^5.0.0", "prop-types": "^15.7.2", "react": "^17.0.2", @@ -88,6 +88,7 @@ "@testing-library/user-event": "^14.0.0", "@types/jquery": "^3.3.34", "@types/node": "^16.11.26", + "@types/react": "*", "@types/react-dom": "*", "@types/zen-observable": "^0.8.0", "cross-env": "^7.0.0", diff --git a/packages/catalog-client/api-report.md b/packages/catalog-client/api-report.md index 964a3c1018..0ad77ce39c 100644 --- a/packages/catalog-client/api-report.md +++ b/packages/catalog-client/api-report.md @@ -5,6 +5,7 @@ ```ts import { CompoundEntityRef } from '@backstage/catalog-model'; import { Entity } from '@backstage/catalog-model'; +import { SerializedError } from '@backstage/errors'; // @public export type AddLocationRequest = { @@ -65,6 +66,11 @@ export interface CatalogApi { id: string, options?: CatalogRequestOptions, ): Promise; + validateEntity( + entity: Entity, + location: string, + options?: CatalogRequestOptions, + ): Promise; } // @public @@ -122,6 +128,11 @@ export class CatalogClient implements CatalogApi { id: string, options?: CatalogRequestOptions, ): Promise; + validateEntity( + entity: Entity, + location: string, + options?: CatalogRequestOptions, + ): Promise; } // @public @@ -196,4 +207,14 @@ type Location_2 = { target: string; }; export { Location_2 as Location }; + +// @public +export type ValidateEntityResponse = + | { + valid: true; + } + | { + valid: false; + errors: SerializedError[]; + }; ``` diff --git a/packages/catalog-client/src/CatalogClient.test.ts b/packages/catalog-client/src/CatalogClient.test.ts index 0b838eb4c2..6c9c68efa2 100644 --- a/packages/catalog-client/src/CatalogClient.test.ts +++ b/packages/catalog-client/src/CatalogClient.test.ts @@ -295,4 +295,87 @@ describe('CatalogClient', () => { await client.getLocationById('42'); }); }); + + describe('validateEntity', () => { + it('returns valid false when validation fails', async () => { + server.use( + rest.post(`${mockBaseUrl}/validate-entity`, (_req, res, ctx) => { + return res( + ctx.status(400), + ctx.json({ + errors: [ + { + message: 'Missing name', + }, + ], + }), + ); + }), + ); + + expect( + await client.validateEntity( + { + apiVersion: '1', + kind: 'Component', + metadata: { + name: '', + }, + }, + 'http://example.com', + ), + ).toMatchObject({ + valid: false, + errors: [ + { + message: 'Missing name', + }, + ], + }); + }); + + it('returns valid true when validation fails', async () => { + server.use( + rest.post(`${mockBaseUrl}/validate-entity`, (_req, res, ctx) => { + return res(ctx.status(200), ctx.text('')); + }), + ); + + expect( + await client.validateEntity( + { + apiVersion: '1', + kind: 'Component', + metadata: { + name: 'good', + }, + }, + 'http://example.com', + ), + ).toMatchObject({ + valid: true, + }); + }); + + it('throws unexpected error', async () => { + server.use( + rest.post(`${mockBaseUrl}/validate-entity`, (_req, res, ctx) => { + return res(ctx.status(500), ctx.json({})); + }), + ); + + await expect(() => + client.validateEntity( + { + apiVersion: '1', + kind: 'Component', + metadata: { + name: 'good', + }, + }, + 'http://example.com', + ), + ).rejects.toThrow(/Request failed with 500 Error/); + }); + }); }); diff --git a/packages/catalog-client/src/CatalogClient.ts b/packages/catalog-client/src/CatalogClient.ts index 8ddc3eb36d..f2b4186bfb 100644 --- a/packages/catalog-client/src/CatalogClient.ts +++ b/packages/catalog-client/src/CatalogClient.ts @@ -36,6 +36,7 @@ import { Location, GetEntityFacetsRequest, GetEntityFacetsResponse, + ValidateEntityResponse, } from './types/api'; import { DiscoveryApi } from './types/discovery'; import { FetchApi } from './types/fetch'; @@ -353,6 +354,44 @@ export class CatalogClient implements CatalogApi { ); } + /** + * {@inheritdoc CatalogApi.validateEntity} + */ + async validateEntity( + entity: Entity, + location: string, + options?: CatalogRequestOptions, + ): Promise { + const response = await this.fetchApi.fetch( + `${await this.discoveryApi.getBaseUrl('catalog')}/validate-entity`, + { + headers: { + 'Content-Type': 'application/json', + ...(options?.token && { Authorization: `Bearer ${options?.token}` }), + }, + method: 'POST', + body: JSON.stringify({ entity, location }), + }, + ); + + if (response.ok) { + return { + valid: true, + }; + } + + if (response.status !== 400) { + throw await ResponseError.fromResponse(response); + } + + const { errors = [] } = await response.json(); + + return { + valid: false, + errors, + }; + } + // // Private methods // diff --git a/packages/catalog-client/src/types/api.ts b/packages/catalog-client/src/types/api.ts index 389b82c081..f483c3454c 100644 --- a/packages/catalog-client/src/types/api.ts +++ b/packages/catalog-client/src/types/api.ts @@ -15,6 +15,7 @@ */ import { CompoundEntityRef, Entity } from '@backstage/catalog-model'; +import { SerializedError } from '@backstage/errors'; /** * This symbol can be used in place of a value when passed to filters in e.g. @@ -269,6 +270,15 @@ export type AddLocationResponse = { exists?: boolean; }; +/** + * The response type for {@link CatalogClient.validateEntity} + * + * @public + */ +export type ValidateEntityResponse = + | { valid: true } + | { valid: false; errors: SerializedError[] }; + /** * A client for interacting with the Backstage software catalog through its API. * @@ -390,4 +400,16 @@ export interface CatalogApi { id: string, options?: CatalogRequestOptions, ): Promise; + + /** + * Validate entity and its location. + * + * @param entity - Entity to validate + * @param location - URL location of the entity + */ + validateEntity( + entity: Entity, + location: string, + options?: CatalogRequestOptions, + ): Promise; } diff --git a/packages/catalog-client/src/types/index.ts b/packages/catalog-client/src/types/index.ts index 8bf4e34da2..86f7b18ab0 100644 --- a/packages/catalog-client/src/types/index.ts +++ b/packages/catalog-client/src/types/index.ts @@ -27,5 +27,6 @@ export type { Location, GetEntityFacetsRequest, GetEntityFacetsResponse, + ValidateEntityResponse, } from './api'; export { ENTITY_STATUS_CATALOG_PROCESSING_TYPE } from './status'; diff --git a/packages/cli/src/commands/versions/bump.test.ts b/packages/cli/src/commands/versions/bump.test.ts index a127d15953..25682a4cd4 100644 --- a/packages/cli/src/commands/versions/bump.test.ts +++ b/packages/cli/src/commands/versions/bump.test.ts @@ -28,6 +28,7 @@ import { import { YarnInfoInspectData } from '../../lib/versioning/packages'; import { setupServer } from 'msw/node'; import { rest } from 'msw'; +import { NotFoundError } from '@backstage/errors'; // Remove log coloring to simplify log matching jest.mock('chalk', () => ({ @@ -54,7 +55,15 @@ jest.mock('ora', () => ({ jest.mock('../../lib/run', () => { return { run: jest.fn(), - runPlain: jest.fn(), + }; +}); + +const mockFetchPackageInfo = jest.fn(); +jest.mock('../../lib/versioning/packages', () => { + const actual = jest.requireActual('../../lib/versioning/packages'); + return { + ...actual, + fetchPackageInfo: (name: string) => mockFetchPackageInfo(name), }; }); @@ -105,6 +114,14 @@ const lockfileMockResult = `${HEADER} `; describe('bump', () => { + beforeEach(() => { + mockFetchPackageInfo.mockImplementation(async name => ({ + name: name, + 'dist-tags': { + latest: REGISTRY_VERSIONS[name], + }, + })); + }); afterEach(() => { mockFs.restore(); jest.resetAllMocks(); @@ -138,17 +155,6 @@ describe('bump', () => { jest .spyOn(paths, 'resolveTargetRoot') .mockImplementation((...path) => resolvePath('/', ...path)); - jest.spyOn(runObj, 'runPlain').mockImplementation(async (...[, , , name]) => - JSON.stringify({ - type: 'inspect', - data: { - name: name, - 'dist-tags': { - latest: REGISTRY_VERSIONS[name], - }, - }, - }), - ); jest.spyOn(runObj, 'run').mockResolvedValue(undefined); worker.use( rest.get( @@ -184,19 +190,10 @@ describe('bump', () => { 'Version bump complete!', ]); - expect(runObj.runPlain).toHaveBeenCalledTimes(3); - expect(runObj.runPlain).toHaveBeenCalledWith( - 'yarn', - 'info', - '--json', - '@backstage/core', - ); - expect(runObj.runPlain).toHaveBeenCalledWith( - 'yarn', - 'info', - '--json', - '@backstage/theme', - ); + expect(mockFetchPackageInfo).toHaveBeenCalledTimes(3); + expect(mockFetchPackageInfo).toHaveBeenCalledWith('@backstage/core'); + expect(mockFetchPackageInfo).toHaveBeenCalledWith('@backstage/core-api'); + expect(mockFetchPackageInfo).toHaveBeenCalledWith('@backstage/theme'); expect(runObj.run).toHaveBeenCalledTimes(1); expect(runObj.run).toHaveBeenCalledWith( @@ -251,17 +248,6 @@ describe('bump', () => { jest .spyOn(paths, 'resolveTargetRoot') .mockImplementation((...path) => resolvePath('/', ...path)); - jest.spyOn(runObj, 'runPlain').mockImplementation(async (...[, , , name]) => - JSON.stringify({ - type: 'inspect', - data: { - name: name, - 'dist-tags': { - latest: REGISTRY_VERSIONS[name], - }, - }, - }), - ); jest.spyOn(runObj, 'run').mockResolvedValue(undefined); worker.use( rest.get( @@ -309,19 +295,9 @@ describe('bump', () => { 'Version bump complete!', ]); - expect(runObj.runPlain).toHaveBeenCalledTimes(2); - expect(runObj.runPlain).toHaveBeenCalledWith( - 'yarn', - 'info', - '--json', - '@backstage/core', - ); - expect(runObj.runPlain).not.toHaveBeenCalledWith( - 'yarn', - 'info', - '--json', - '@backstage/theme', - ); + expect(mockFetchPackageInfo).toHaveBeenCalledTimes(2); + expect(mockFetchPackageInfo).toHaveBeenCalledWith('@backstage/core'); + expect(mockFetchPackageInfo).not.toHaveBeenCalledWith('@backstage/theme'); expect(runObj.run).toHaveBeenCalledTimes(1); expect(runObj.run).toHaveBeenCalledWith( @@ -372,17 +348,6 @@ describe('bump', () => { }, }), }); - jest.spyOn(runObj, 'runPlain').mockImplementation(async (...[, , , name]) => - JSON.stringify({ - type: 'inspect', - data: { - name: name, - 'dist-tags': { - latest: REGISTRY_VERSIONS[name], - }, - }, - }), - ); jest .spyOn(paths, 'resolveTargetRoot') .mockImplementation((...path) => resolvePath('/', ...path)); @@ -480,17 +445,6 @@ describe('bump', () => { jest .spyOn(paths, 'resolveTargetRoot') .mockImplementation((...path) => resolvePath('/', ...path)); - jest.spyOn(runObj, 'runPlain').mockImplementation(async (...[, , , name]) => - JSON.stringify({ - type: 'inspect', - data: { - name: name, - 'dist-tags': { - latest: REGISTRY_VERSIONS[name], - }, - }, - }), - ); jest.spyOn(runObj, 'run').mockResolvedValue(undefined); worker.use( rest.get( @@ -614,17 +568,6 @@ describe('bump', () => { jest .spyOn(paths, 'resolveTargetRoot') .mockImplementation((...path) => resolvePath('/', ...path)); - jest.spyOn(runObj, 'runPlain').mockImplementation(async (...[, , , name]) => - JSON.stringify({ - type: 'inspect', - data: { - name: name, - 'dist-tags': { - latest: REGISTRY_VERSIONS[name], - }, - }, - }), - ); jest.spyOn(runObj, 'run').mockResolvedValue(undefined); worker.use( rest.get( @@ -672,19 +615,9 @@ describe('bump', () => { 'Version bump complete!', ]); - expect(runObj.runPlain).toHaveBeenCalledTimes(5); - expect(runObj.runPlain).toHaveBeenCalledWith( - 'yarn', - 'info', - '--json', - '@backstage/core', - ); - expect(runObj.runPlain).toHaveBeenCalledWith( - 'yarn', - 'info', - '--json', - '@backstage/theme', - ); + expect(mockFetchPackageInfo).toHaveBeenCalledTimes(5); + expect(mockFetchPackageInfo).toHaveBeenCalledWith('@backstage/core'); + expect(mockFetchPackageInfo).toHaveBeenCalledWith('@backstage/theme'); expect(runObj.run).toHaveBeenCalledTimes(1); expect(runObj.run).toHaveBeenCalledWith( @@ -743,7 +676,7 @@ describe('bump', () => { jest .spyOn(paths, 'resolveTargetRoot') .mockImplementation((...path) => resolvePath('/', ...path)); - jest.spyOn(runObj, 'runPlain').mockImplementation(async () => ''); + mockFetchPackageInfo.mockRejectedValue(new NotFoundError('Nope')); jest.spyOn(runObj, 'run').mockResolvedValue(undefined); worker.use( rest.get( diff --git a/packages/cli/src/lib/run.ts b/packages/cli/src/lib/run.ts index 4efb791c30..1ef25cae62 100644 --- a/packages/cli/src/lib/run.ts +++ b/packages/cli/src/lib/run.ts @@ -25,7 +25,7 @@ import { promisify } from 'util'; import { LogFunc } from './logging'; import { assertError, ForwardedError } from '@backstage/errors'; -const execFile = promisify(execFileCb); +export const execFile = promisify(execFileCb); type SpawnOptionsPartialEnv = Omit & { env?: Partial; diff --git a/packages/cli/src/lib/versioning/packages.test.ts b/packages/cli/src/lib/versioning/packages.test.ts index 975be74abd..5a255532f9 100644 --- a/packages/cli/src/lib/versioning/packages.test.ts +++ b/packages/cli/src/lib/versioning/packages.test.ts @@ -17,13 +17,20 @@ import mockFs from 'mock-fs'; import path from 'path'; import * as runObj from '../run'; +import * as yarn from '../yarn'; import { fetchPackageInfo, mapDependencies } from './packages'; import { NotFoundError } from '../errors'; jest.mock('../run', () => { return { run: jest.fn(), - runPlain: jest.fn(), + execFile: jest.fn(), + }; +}); + +jest.mock('../yarn', () => { + return { + detectYarnVersion: jest.fn(), }; }); @@ -32,24 +39,55 @@ describe('fetchPackageInfo', () => { jest.resetAllMocks(); }); - it('should forward info', async () => { - jest - .spyOn(runObj, 'runPlain') - .mockResolvedValue(`{"type":"inspect","data":{"the":"data"}}`); + it('should forward info for yarn classic', async () => { + jest.spyOn(runObj, 'execFile').mockResolvedValue({ + stdout: `{"type":"inspect","data":{"the":"data"}}`, + stderr: '', + }); + jest.spyOn(yarn, 'detectYarnVersion').mockResolvedValue('classic'); await expect(fetchPackageInfo('my-package')).resolves.toEqual({ the: 'data', }); - expect(runObj.runPlain).toHaveBeenCalledWith( + expect(runObj.execFile).toHaveBeenCalledWith( 'yarn', - 'info', - '--json', - 'my-package', + ['info', '--json', 'my-package'], + { shell: true }, ); }); - it('should throw if no info', async () => { - jest.spyOn(runObj, 'runPlain').mockResolvedValue(''); + it('should forward info for yarn berry', async () => { + jest + .spyOn(runObj, 'execFile') + .mockResolvedValue({ stdout: `{"the":"data"}`, stderr: '' }); + jest.spyOn(yarn, 'detectYarnVersion').mockResolvedValue('berry'); + + await expect(fetchPackageInfo('my-package')).resolves.toEqual({ + the: 'data', + }); + expect(runObj.execFile).toHaveBeenCalledWith( + 'yarn', + ['npm', 'info', '--json', 'my-package'], + { shell: true }, + ); + }); + + it('should throw if no info with yarn classic', async () => { + jest + .spyOn(runObj, 'execFile') + .mockResolvedValue({ stdout: '', stderr: '' }); + jest.spyOn(yarn, 'detectYarnVersion').mockResolvedValue('classic'); + + await expect(fetchPackageInfo('my-package')).rejects.toThrow( + new NotFoundError(`No package information found for package my-package`), + ); + }); + + it('should throw if no info with yarn berry', async () => { + jest + .spyOn(runObj, 'execFile') + .mockRejectedValue({ stdout: 'bla bla bla Response Code: 404 bla bla' }); + jest.spyOn(yarn, 'detectYarnVersion').mockResolvedValue('berry'); await expect(fetchPackageInfo('my-package')).rejects.toThrow( new NotFoundError(`No package information found for package my-package`), diff --git a/packages/cli/src/lib/versioning/packages.ts b/packages/cli/src/lib/versioning/packages.ts index ed7266a692..70229b6fed 100644 --- a/packages/cli/src/lib/versioning/packages.ts +++ b/packages/cli/src/lib/versioning/packages.ts @@ -13,10 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import minimatch from 'minimatch'; import { getPackages } from '@manypkg/get-packages'; -import { runPlain } from '../../lib/run'; import { NotFoundError } from '../errors'; +import { detectYarnVersion } from '../yarn'; +import { execFile } from '../run'; const DEP_TYPES = [ 'dependencies', @@ -48,18 +50,45 @@ type PkgVersionInfo = { export async function fetchPackageInfo( name: string, ): Promise { - const output = await runPlain('yarn', 'info', '--json', name); + const yarnVersion = await detectYarnVersion(); - if (!output) { - throw new NotFoundError(`No package information found for package ${name}`); + const cmd = yarnVersion === 'classic' ? ['info'] : ['npm', 'info']; + try { + const { stdout: output } = await execFile( + 'yarn', + [...cmd, '--json', name], + { shell: true }, + ); + + if (!output) { + throw new NotFoundError( + `No package information found for package ${name}`, + ); + } + + if (yarnVersion === 'berry') { + return JSON.parse(output) as YarnInfoInspectData; + } + + const info = JSON.parse(output) as YarnInfo; + if (info.type !== 'inspect') { + throw new Error(`Received unknown yarn info for ${name}, ${output}`); + } + + return info.data as YarnInfoInspectData; + } catch (error) { + if (yarnVersion === 'classic') { + throw error; + } + + if (error?.stdout.includes('Response Code: 404')) { + throw new NotFoundError( + `No package information found for package ${name}`, + ); + } + + throw error; } - - const info = JSON.parse(output) as YarnInfo; - if (info.type !== 'inspect') { - throw new Error(`Received unknown yarn info for ${name}, ${output}`); - } - - return info.data as YarnInfoInspectData; } /** Map all dependencies in the repo as dependency => dependents */ diff --git a/packages/cli/src/lib/yarn.ts b/packages/cli/src/lib/yarn.ts new file mode 100644 index 0000000000..b6c0383bc2 --- /dev/null +++ b/packages/cli/src/lib/yarn.ts @@ -0,0 +1,49 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { assertError, ForwardedError } from '@backstage/errors'; +import { execFile as execFileCb } from 'child_process'; +import { promisify } from 'util'; + +const execFile = promisify(execFileCb); + +const versions = new Map>(); + +export function detectYarnVersion(dir?: string): Promise<'classic' | 'berry'> { + const cwd = dir ?? process.cwd(); + if (versions.has(cwd)) { + return versions.get(cwd)!; + } + + const promise = Promise.resolve().then(async () => { + try { + const { stdout } = await execFile('yarn', ['--version'], { + shell: true, + cwd, + }); + return stdout.trim().startsWith('1.') ? 'classic' : 'berry'; + } catch (error) { + assertError(error); + if ('stderr' in error) { + process.stderr.write(error.stderr as Buffer); + } + throw new ForwardedError('Failed to determine yarn version', error); + } + }); + + versions.set(cwd, promise); + return promise; +} diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index 80d4b2fcbb..8399e09357 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -50,6 +50,7 @@ "peerDependencies": { "@types/react": "^16.13.1 || ^17.0.0", "react": "^16.13.1 || ^17.0.0", + "react-dom": "^16.13.1 || ^17.0.0", "react-router": "6.0.0-beta.0 || ^6.3.0", "react-router-dom": "6.0.0-beta.0 || ^6.3.0" }, diff --git a/plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.test.ts b/plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.test.ts index 587b433ca1..e4d9304892 100644 --- a/plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.test.ts +++ b/plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.test.ts @@ -35,6 +35,7 @@ describe('CatalogIdentityClient', () => { refreshEntity: jest.fn(), getEntityAncestors: jest.fn(), getEntityFacets: jest.fn(), + validateEntity: jest.fn(), }; const tokenManager: jest.Mocked = { getToken: jest.fn(), diff --git a/plugins/badges-backend/src/service/router.test.ts b/plugins/badges-backend/src/service/router.test.ts index 1750a55be7..5fc809906f 100644 --- a/plugins/badges-backend/src/service/router.test.ts +++ b/plugins/badges-backend/src/service/router.test.ts @@ -68,6 +68,7 @@ describe('createRouter', () => { refreshEntity: jest.fn(), getEntityAncestors: jest.fn(), getEntityFacets: jest.fn(), + validateEntity: jest.fn(), }; config = new ConfigReader({ diff --git a/plugins/catalog-backend-module-aws/src/providers/AwsS3EntityProvider.test.ts b/plugins/catalog-backend-module-aws/src/providers/AwsS3EntityProvider.test.ts index 9d3bba0e8a..3d59d738cf 100644 --- a/plugins/catalog-backend-module-aws/src/providers/AwsS3EntityProvider.test.ts +++ b/plugins/catalog-backend-module-aws/src/providers/AwsS3EntityProvider.test.ts @@ -100,6 +100,7 @@ describe('AwsS3EntityProvider', () => { const schedule = new PersistingTaskRunner(); const entityProviderConnection: EntityProviderConnection = { applyMutation: jest.fn(), + refresh: jest.fn(), }; const provider = AwsS3EntityProvider.fromConfig(config, { diff --git a/plugins/catalog-backend-module-azure/src/providers/AzureDevOpsEntityProvider.test.ts b/plugins/catalog-backend-module-azure/src/providers/AzureDevOpsEntityProvider.test.ts index 1c2c3d0082..c57455d8d6 100644 --- a/plugins/catalog-backend-module-azure/src/providers/AzureDevOpsEntityProvider.test.ts +++ b/plugins/catalog-backend-module-azure/src/providers/AzureDevOpsEntityProvider.test.ts @@ -71,6 +71,7 @@ describe('AzureDevOpsEntityProvider', () => { const schedule = new PersistingTaskRunner(); const entityProviderConnection: EntityProviderConnection = { applyMutation: jest.fn(), + refresh: jest.fn(), }; const provider = AzureDevOpsEntityProvider.fromConfig(config, { diff --git a/plugins/catalog-backend-module-bitbucket-cloud/src/BitbucketCloudEntityProvider.test.ts b/plugins/catalog-backend-module-bitbucket-cloud/src/BitbucketCloudEntityProvider.test.ts index 08b127f69e..641150acbf 100644 --- a/plugins/catalog-backend-module-bitbucket-cloud/src/BitbucketCloudEntityProvider.test.ts +++ b/plugins/catalog-backend-module-bitbucket-cloud/src/BitbucketCloudEntityProvider.test.ts @@ -127,6 +127,7 @@ describe('BitbucketCloudEntityProvider', () => { const schedule = new PersistingTaskRunner(); const entityProviderConnection: EntityProviderConnection = { applyMutation: jest.fn(), + refresh: jest.fn(), }; const provider = BitbucketCloudEntityProvider.fromConfig(config, { logger, diff --git a/plugins/catalog-backend-module-bitbucket-server/src/providers/BitbucketServerEntityProvider.test.ts b/plugins/catalog-backend-module-bitbucket-server/src/providers/BitbucketServerEntityProvider.test.ts index fe2c81b9b6..39689b6c1d 100644 --- a/plugins/catalog-backend-module-bitbucket-server/src/providers/BitbucketServerEntityProvider.test.ts +++ b/plugins/catalog-backend-module-bitbucket-server/src/providers/BitbucketServerEntityProvider.test.ts @@ -221,6 +221,7 @@ describe('BitbucketServerEntityProvider', () => { const schedule = new PersistingTaskRunner(); const entityProviderConnection: EntityProviderConnection = { applyMutation: jest.fn(), + refresh: jest.fn(), }; const provider = BitbucketServerEntityProvider.fromConfig(config, { logger, @@ -296,6 +297,7 @@ describe('BitbucketServerEntityProvider', () => { const schedule = new PersistingTaskRunner(); const entityProviderConnection: EntityProviderConnection = { applyMutation: jest.fn(), + refresh: jest.fn(), }; const provider = BitbucketServerEntityProvider.fromConfig(config, { logger, diff --git a/plugins/catalog-backend-module-gerrit/src/providers/GerritEntityProvider.test.ts b/plugins/catalog-backend-module-gerrit/src/providers/GerritEntityProvider.test.ts index d5be045e6c..d6ad0ff668 100644 --- a/plugins/catalog-backend-module-gerrit/src/providers/GerritEntityProvider.test.ts +++ b/plugins/catalog-backend-module-gerrit/src/providers/GerritEntityProvider.test.ts @@ -83,6 +83,7 @@ describe('GerritEntityProvider', () => { const entityProviderConnection: EntityProviderConnection = { applyMutation: jest.fn(), + refresh: jest.fn(), }; it('discovers projects from the api.', async () => { diff --git a/plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.test.ts b/plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.test.ts index 871718cc05..63fb77288b 100644 --- a/plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.test.ts +++ b/plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.test.ts @@ -146,6 +146,7 @@ describe('GitHubEntityProvider', () => { const schedule = new PersistingTaskRunner(); const entityProviderConnection: EntityProviderConnection = { applyMutation: jest.fn(), + refresh: jest.fn(), }; const provider = GitHubEntityProvider.fromConfig(config, { @@ -233,6 +234,7 @@ describe('GitHubEntityProvider', () => { const schedule = new PersistingTaskRunner(); const entityProviderConnection: EntityProviderConnection = { applyMutation: jest.fn(), + refresh: jest.fn(), }; const provider = GitHubEntityProvider.fromConfig(config, { @@ -306,6 +308,7 @@ describe('GitHubEntityProvider', () => { const schedule = new PersistingTaskRunner(); const entityProviderConnection: EntityProviderConnection = { applyMutation: jest.fn(), + refresh: jest.fn(), }; const provider = GitHubEntityProvider.fromConfig(config, { @@ -404,6 +407,7 @@ it('apply full update on scheduled execution with topic exclusion taking priorit const schedule = new PersistingTaskRunner(); const entityProviderConnection: EntityProviderConnection = { applyMutation: jest.fn(), + refresh: jest.fn(), }; const provider = GitHubEntityProvider.fromConfig(config, { diff --git a/plugins/catalog-backend-module-github/src/providers/GitHubOrgEntityProvider.test.ts b/plugins/catalog-backend-module-github/src/providers/GitHubOrgEntityProvider.test.ts index 77d585eae1..2d05346f01 100644 --- a/plugins/catalog-backend-module-github/src/providers/GitHubOrgEntityProvider.test.ts +++ b/plugins/catalog-backend-module-github/src/providers/GitHubOrgEntityProvider.test.ts @@ -83,6 +83,7 @@ describe('GitHubOrgEntityProvider', () => { const entityProviderConnection: EntityProviderConnection = { applyMutation: jest.fn(), + refresh: jest.fn(), }; const logger = getVoidLogger(); diff --git a/plugins/catalog-backend-module-gitlab/src/providers/GitlabDiscoveryEntityProvider.test.ts b/plugins/catalog-backend-module-gitlab/src/providers/GitlabDiscoveryEntityProvider.test.ts index 7fb4bf8d09..3f3c4e7f91 100644 --- a/plugins/catalog-backend-module-gitlab/src/providers/GitlabDiscoveryEntityProvider.test.ts +++ b/plugins/catalog-backend-module-gitlab/src/providers/GitlabDiscoveryEntityProvider.test.ts @@ -155,6 +155,7 @@ describe('GitlabDiscoveryEntityProvider', () => { const schedule = new PersistingTaskRunner(); const entityProviderConnection: EntityProviderConnection = { applyMutation: jest.fn(), + refresh: jest.fn(), }; const provider = GitlabDiscoveryEntityProvider.fromConfig(config, { logger, @@ -253,6 +254,7 @@ describe('GitlabDiscoveryEntityProvider', () => { const schedule = new PersistingTaskRunner(); const entityProviderConnection: EntityProviderConnection = { applyMutation: jest.fn(), + refresh: jest.fn(), }; const provider = GitlabDiscoveryEntityProvider.fromConfig(config, { logger, diff --git a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.test.ts b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.test.ts index e34eee0499..ff68235c4c 100644 --- a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.test.ts +++ b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.test.ts @@ -95,6 +95,7 @@ describe('MicrosoftGraphOrgEntityProvider', () => { }; const entityProviderConnection: EntityProviderConnection = { applyMutation: jest.fn(), + refresh: jest.fn(), }; const provider = MicrosoftGraphOrgEntityProvider.fromConfig( new ConfigReader(config), diff --git a/plugins/catalog-backend/src/database/types.ts b/plugins/catalog-backend/src/database/types.ts index 07241f0682..2d30f8bd86 100644 --- a/plugins/catalog-backend/src/database/types.ts +++ b/plugins/catalog-backend/src/database/types.ts @@ -157,6 +157,14 @@ export interface ProcessingDatabase { */ refresh(txOpaque: Transaction, options: RefreshOptions): Promise; + /** + * Schedules a refresh for every entity that has a matching set of refresh key stored for it. + */ + refreshByRefreshKeys( + txOpaque: Transaction, + options: RefreshByKeyOptions, + ): Promise; + /** * Lists all ancestors of a given entityRef. * diff --git a/plugins/catalog-backend/src/modules/core/DefaultLocationStore.test.ts b/plugins/catalog-backend/src/modules/core/DefaultLocationStore.test.ts index dfbc37f6c9..2a9b1f8d65 100644 --- a/plugins/catalog-backend/src/modules/core/DefaultLocationStore.test.ts +++ b/plugins/catalog-backend/src/modules/core/DefaultLocationStore.test.ts @@ -26,7 +26,7 @@ describe('DefaultLocationStore', () => { async function createLocationStore(databaseId: TestDatabaseId) { const knex = await databases.init(databaseId); await applyDatabaseMigrations(knex); - const connection = { applyMutation: jest.fn() }; + const connection = { applyMutation: jest.fn(), refresh: jest.fn() }; const store = new DefaultLocationStore(knex); await store.connect(connection); return { store, connection }; diff --git a/plugins/catalog-backend/src/processing/connectEntityProviders.ts b/plugins/catalog-backend/src/processing/connectEntityProviders.ts index 70a43de589..a4795532f0 100644 --- a/plugins/catalog-backend/src/processing/connectEntityProviders.ts +++ b/plugins/catalog-backend/src/processing/connectEntityProviders.ts @@ -22,6 +22,7 @@ import { ProcessingDatabase } from '../database/types'; import { EntityProvider, EntityProviderConnection, + EntityProviderRefreshOptions, EntityProviderMutation, } from '@backstage/plugin-catalog-node'; @@ -61,6 +62,16 @@ class Connection implements EntityProviderConnection { } } + async refresh(options: EntityProviderRefreshOptions): Promise { + const db = this.config.processingDatabase; + + await db.transaction(async (tx: any) => { + return db.refreshByRefreshKeys(tx, { + keys: options.keys, + }); + }); + } + private check(entities: Entity[]) { for (const entity of entities) { try { diff --git a/plugins/catalog-graph/src/components/CatalogGraphCard/CatalogGraphCard.test.tsx b/plugins/catalog-graph/src/components/CatalogGraphCard/CatalogGraphCard.test.tsx index 9b354b5f38..74fcd4e501 100644 --- a/plugins/catalog-graph/src/components/CatalogGraphCard/CatalogGraphCard.test.tsx +++ b/plugins/catalog-graph/src/components/CatalogGraphCard/CatalogGraphCard.test.tsx @@ -59,6 +59,7 @@ describe('', () => { refreshEntity: jest.fn(), getEntityAncestors: jest.fn(), getEntityFacets: jest.fn(), + validateEntity: jest.fn(), }; apis = TestApiRegistry.from([catalogApiRef, catalog]); diff --git a/plugins/catalog-graph/src/components/CatalogGraphPage/CatalogGraphPage.test.tsx b/plugins/catalog-graph/src/components/CatalogGraphPage/CatalogGraphPage.test.tsx index d8b7ede2c2..9cca6ef9be 100644 --- a/plugins/catalog-graph/src/components/CatalogGraphPage/CatalogGraphPage.test.tsx +++ b/plugins/catalog-graph/src/components/CatalogGraphPage/CatalogGraphPage.test.tsx @@ -92,6 +92,7 @@ describe('', () => { refreshEntity: jest.fn(), getEntityAncestors: jest.fn(), getEntityFacets: jest.fn(), + validateEntity: jest.fn(), }; wrapper = ( diff --git a/plugins/catalog-graph/src/components/EntityRelationsGraph/EntityRelationsGraph.test.tsx b/plugins/catalog-graph/src/components/EntityRelationsGraph/EntityRelationsGraph.test.tsx index db6711a0a5..c79f975789 100644 --- a/plugins/catalog-graph/src/components/EntityRelationsGraph/EntityRelationsGraph.test.tsx +++ b/plugins/catalog-graph/src/components/EntityRelationsGraph/EntityRelationsGraph.test.tsx @@ -119,6 +119,7 @@ describe('', () => { refreshEntity: jest.fn(), getEntityAncestors: jest.fn(), getEntityFacets: jest.fn(), + validateEntity: jest.fn(), }; Wrapper = ({ children }) => ( diff --git a/plugins/catalog-graph/src/components/EntityRelationsGraph/useEntityStore.test.ts b/plugins/catalog-graph/src/components/EntityRelationsGraph/useEntityStore.test.ts index 74d7423eea..e76b1001c6 100644 --- a/plugins/catalog-graph/src/components/EntityRelationsGraph/useEntityStore.test.ts +++ b/plugins/catalog-graph/src/components/EntityRelationsGraph/useEntityStore.test.ts @@ -38,6 +38,7 @@ describe('useEntityStore', () => { refreshEntity: jest.fn(), getEntityAncestors: jest.fn(), getEntityFacets: jest.fn(), + validateEntity: jest.fn(), }; useApi.mockReturnValue(catalogApi); diff --git a/plugins/catalog-import/src/api/CatalogImportClient.test.ts b/plugins/catalog-import/src/api/CatalogImportClient.test.ts index e26d6c5d6a..30b9f47d99 100644 --- a/plugins/catalog-import/src/api/CatalogImportClient.test.ts +++ b/plugins/catalog-import/src/api/CatalogImportClient.test.ts @@ -100,6 +100,7 @@ describe('CatalogImportClient', () => { refreshEntity: jest.fn(), getEntityAncestors: jest.fn(), getEntityFacets: jest.fn(), + validateEntity: jest.fn(), }; let catalogImportClient: CatalogImportClient; diff --git a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.test.tsx b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.test.tsx index f3dc1f2144..5ad7e27c4b 100644 --- a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.test.tsx +++ b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.test.tsx @@ -46,6 +46,7 @@ describe('', () => { refreshEntity: jest.fn(), getEntityAncestors: jest.fn(), getEntityFacets: jest.fn(), + validateEntity: jest.fn(), }; const errorApi: jest.Mocked = { diff --git a/plugins/catalog-node/api-report.md b/plugins/catalog-node/api-report.md index 7d12c2e065..3873e3376d 100644 --- a/plugins/catalog-node/api-report.md +++ b/plugins/catalog-node/api-report.md @@ -126,6 +126,7 @@ export interface EntityProvider { // @public export interface EntityProviderConnection { applyMutation(mutation: EntityProviderMutation): Promise; + refresh(options: EntityProviderRefreshOptions): Promise; } // @public @@ -140,6 +141,11 @@ export type EntityProviderMutation = removed: DeferredEntity[]; }; +// @public (undocumented) +export type EntityProviderRefreshOptions = { + keys: string[]; +}; + // @public export type EntityRelationSpec = { source: CompoundEntityRef; diff --git a/plugins/catalog-node/src/api/index.ts b/plugins/catalog-node/src/api/index.ts index 136c23d20d..66e8d6bd21 100644 --- a/plugins/catalog-node/src/api/index.ts +++ b/plugins/catalog-node/src/api/index.ts @@ -32,4 +32,5 @@ export type { EntityProvider, EntityProviderConnection, EntityProviderMutation, + EntityProviderRefreshOptions, } from './provider'; diff --git a/plugins/catalog-node/src/api/provider.ts b/plugins/catalog-node/src/api/provider.ts index fa7659ee32..fc9a172e0d 100644 --- a/plugins/catalog-node/src/api/provider.ts +++ b/plugins/catalog-node/src/api/provider.ts @@ -26,6 +26,13 @@ export type EntityProviderMutation = | { type: 'full'; entities: DeferredEntity[] } | { type: 'delta'; added: DeferredEntity[]; removed: DeferredEntity[] }; +/** + * @public + */ +export type EntityProviderRefreshOptions = { + keys: string[]; +}; + /** * The EntityProviderConnection is the connection between the catalog and the entity provider. * The EntityProvider use this connection to add and remove entities from the catalog. @@ -36,6 +43,11 @@ export interface EntityProviderConnection { * Applies either a full or delta update to the catalog engine. */ applyMutation(mutation: EntityProviderMutation): Promise; + + /** + * Schedules a refresh on all of the entities that has a matching refresh key associated with the provided keys. + */ + refresh(options: EntityProviderRefreshOptions): Promise; } /** diff --git a/plugins/catalog-react/api-report.md b/plugins/catalog-react/api-report.md index 6e0ba235b7..1ae82f702b 100644 --- a/plugins/catalog-react/api-report.md +++ b/plugins/catalog-react/api-report.md @@ -364,7 +364,14 @@ export class EntityTagFilter implements EntityFilter { } // @public (undocumented) -export const EntityTagPicker: () => JSX.Element | null; +export const EntityTagPicker: ( + props: EntityTagPickerProps, +) => JSX.Element | null; + +// @public (undocumented) +export type EntityTagPickerProps = { + showCounts?: boolean; +}; // @public export class EntityTextFilter implements EntityFilter { diff --git a/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.test.tsx b/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.test.tsx index 2be521203f..78bdde1994 100644 --- a/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.test.tsx +++ b/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.test.tsx @@ -28,7 +28,9 @@ const tags = ['tag1', 'tag2', 'tag3', 'tag4']; describe('', () => { const mockCatalogApiRef = { getEntityFacets: async () => ({ - facets: { 'metadata.tags': tags.map(value => ({ value })) }, + facets: { + 'metadata.tags': tags.map((value, idx) => ({ value, count: idx })), + }, }), } as unknown as CatalogApi; @@ -68,6 +70,26 @@ describe('', () => { ]); }); + it('renders tags with counts', async () => { + const rendered = render( + + + + + , + ); + await waitFor(() => expect(rendered.getByText('Tags')).toBeInTheDocument()); + + fireEvent.click(rendered.getByTestId('tag-picker-expand')); + + expect(rendered.getAllByRole('option').map(o => o.textContent)).toEqual([ + 'tag1 (0)', + 'tag2 (1)', + 'tag3 (2)', + 'tag4 (3)', + ]); + }); + it('respects the query parameter filter value', async () => { const updateFilters = jest.fn(); const queryParameters = { tags: ['tag3'] }; diff --git a/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.tsx b/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.tsx index 39895f229d..25f02e8adc 100644 --- a/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.tsx +++ b/plugins/catalog-react/src/components/EntityTagPicker/EntityTagPicker.tsx @@ -49,7 +49,12 @@ const icon = ; const checkedIcon = ; /** @public */ -export const EntityTagPicker = () => { +export type EntityTagPickerProps = { + showCounts?: boolean; +}; + +/** @public */ +export const EntityTagPicker = (props: EntityTagPickerProps) => { const classes = useStyles(); const { updateFilters, @@ -65,7 +70,9 @@ export const EntityTagPicker = () => { filter: filters.kind?.getCatalogFilters(), }); - return facets[facet].map(({ value }) => value); + return Object.fromEntries( + facets[facet].map(({ value, count }) => [value, count]), + ); }, [filters.kind]); const queryParamTags = useMemo( @@ -91,7 +98,7 @@ export const EntityTagPicker = () => { }); }, [selectedTags, updateFilters]); - if (!availableTags?.length) return null; + if (!Object.keys(availableTags ?? {}).length) return null; return ( @@ -99,7 +106,7 @@ export const EntityTagPicker = () => { Tags setSelectedTags(value)} renderOption={(option, { selected }) => ( @@ -111,7 +118,11 @@ export const EntityTagPicker = () => { checked={selected} /> } - label={option} + label={ + props.showCounts + ? `${option} (${availableTags?.[option]})` + : option + } /> )} size="small" diff --git a/plugins/catalog-react/src/components/EntityTagPicker/index.ts b/plugins/catalog-react/src/components/EntityTagPicker/index.ts index c982d33df0..28c8c844f8 100644 --- a/plugins/catalog-react/src/components/EntityTagPicker/index.ts +++ b/plugins/catalog-react/src/components/EntityTagPicker/index.ts @@ -15,4 +15,7 @@ */ export { EntityTagPicker } from './EntityTagPicker'; -export type { CatalogReactEntityTagPickerClassKey } from './EntityTagPicker'; +export type { + CatalogReactEntityTagPickerClassKey, + EntityTagPickerProps, +} from './EntityTagPicker'; diff --git a/plugins/explore/src/components/DefaultExplorePage/DefaultExplorePage.test.tsx b/plugins/explore/src/components/DefaultExplorePage/DefaultExplorePage.test.tsx index a79d02a2a0..399112fac6 100644 --- a/plugins/explore/src/components/DefaultExplorePage/DefaultExplorePage.test.tsx +++ b/plugins/explore/src/components/DefaultExplorePage/DefaultExplorePage.test.tsx @@ -32,6 +32,7 @@ describe('', () => { refreshEntity: jest.fn(), getEntityAncestors: jest.fn(), getEntityFacets: jest.fn(), + validateEntity: jest.fn(), }; const Wrapper = ({ children }: { children?: React.ReactNode }) => ( diff --git a/plugins/explore/src/components/DomainExplorerContent/DomainExplorerContent.test.tsx b/plugins/explore/src/components/DomainExplorerContent/DomainExplorerContent.test.tsx index c30e845112..c84363f5c6 100644 --- a/plugins/explore/src/components/DomainExplorerContent/DomainExplorerContent.test.tsx +++ b/plugins/explore/src/components/DomainExplorerContent/DomainExplorerContent.test.tsx @@ -33,6 +33,7 @@ describe('', () => { refreshEntity: jest.fn(), getEntityAncestors: jest.fn(), getEntityFacets: jest.fn(), + validateEntity: jest.fn(), }; const Wrapper = ({ children }: { children?: React.ReactNode }) => ( diff --git a/plugins/explore/src/components/GroupsExplorerContent/GroupsExplorerContent.test.tsx b/plugins/explore/src/components/GroupsExplorerContent/GroupsExplorerContent.test.tsx index 4488a4d0d9..a4769e8f4f 100644 --- a/plugins/explore/src/components/GroupsExplorerContent/GroupsExplorerContent.test.tsx +++ b/plugins/explore/src/components/GroupsExplorerContent/GroupsExplorerContent.test.tsx @@ -33,6 +33,7 @@ describe('', () => { refreshEntity: jest.fn(), getEntityAncestors: jest.fn(), getEntityFacets: jest.fn(), + validateEntity: jest.fn(), }; const Wrapper = ({ children }: { children?: React.ReactNode }) => ( diff --git a/plugins/fossa/src/components/FossaPage/FossaPage.test.tsx b/plugins/fossa/src/components/FossaPage/FossaPage.test.tsx index 7ef6c799df..676a3cff3c 100644 --- a/plugins/fossa/src/components/FossaPage/FossaPage.test.tsx +++ b/plugins/fossa/src/components/FossaPage/FossaPage.test.tsx @@ -37,6 +37,7 @@ describe('', () => { refreshEntity: jest.fn(), getEntityAncestors: jest.fn(), getEntityFacets: jest.fn(), + validateEntity: jest.fn(), }; const fossaApi: jest.Mocked = { getFindingSummary: jest.fn(), diff --git a/plugins/kubernetes-backend/.snyk b/plugins/kubernetes-backend/.snyk new file mode 100644 index 0000000000..2f19f3fcf7 --- /dev/null +++ b/plugins/kubernetes-backend/.snyk @@ -0,0 +1,10 @@ +# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. +version: v1.22.1 +# ignores vulnerabilities until expiry date; change duration by modifying expiry date +ignore: + SNYK-JS-TAFFYDB-2992450: + - '*': + reason: Development dependency only + expires: 2023-03-07T20:23:00.000Z + created: 2022-09-07T20:23:00.000Z +patch: {} diff --git a/plugins/todo-backend/src/service/TodoReaderService.test.ts b/plugins/todo-backend/src/service/TodoReaderService.test.ts index 6dd14afcb4..8077e2ddb9 100644 --- a/plugins/todo-backend/src/service/TodoReaderService.test.ts +++ b/plugins/todo-backend/src/service/TodoReaderService.test.ts @@ -53,6 +53,7 @@ function mockCatalogClient(entity?: Entity): jest.Mocked { refreshEntity: jest.fn(), getEntityAncestors: jest.fn(), getEntityFacets: jest.fn(), + validateEntity: jest.fn(), }; if (entity) { mock.getEntityByRef.mockReturnValue(entity); diff --git a/yarn.lock b/yarn.lock index 34bcd2aacb..c1728d70b0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2833,6 +2833,8 @@ __metadata: "@types/react": ^16.13.1 || ^17.0.0 peerDependencies: react: ^16.13.1 || ^17.0.0 + react-dom: ^16.13.1 || ^17.0.0 + react-router: 6.0.0-beta.0 || ^6.3.0 react-router-dom: 6.0.0-beta.0 || ^6.3.0 languageName: unknown linkType: soft @@ -7423,6 +7425,7 @@ __metadata: peerDependencies: "@types/react": ^16.13.1 || ^17.0.0 react: ^16.13.1 || ^17.0.0 + react-dom: ^16.13.1 || ^17.0.0 react-router: 6.0.0-beta.0 || ^6.3.0 react-router-dom: 6.0.0-beta.0 || ^6.3.0 languageName: unknown @@ -12491,9 +12494,9 @@ __metadata: languageName: node linkType: hard -"@roadiehq/backstage-plugin-buildkite@npm:^2.0.0": - version: 2.0.7 - resolution: "@roadiehq/backstage-plugin-buildkite@npm:2.0.7" +"@roadiehq/backstage-plugin-buildkite@npm:^2.0.8": + version: 2.0.8 + resolution: "@roadiehq/backstage-plugin-buildkite@npm:2.0.8" dependencies: "@backstage/catalog-model": ^1.0.0 "@backstage/core-components": ^0.11.0 @@ -12505,19 +12508,19 @@ __metadata: "@material-ui/lab": 4.0.0-alpha.57 history: ^5.0.0 moment: ^2.29.1 - react-router: 6.0.0-beta.0 - react-router-dom: 6.0.0-beta.0 react-use: ^17.2.4 peerDependencies: react: ^16.13.1 || ^17.0.0 react-dom: ^16.13.1 || ^17.0.0 - checksum: cf7ba623c418d3ea7ea56c67b0fe10d6be7fe36531539c31e87b586897fcb9c3474a432239d7d6c01623ff6fc29fb4ae905564a9d2aae11e2ce54b8502cc1c29 + react-router: 6.0.0-beta.0 || ^6.3.0 + react-router-dom: 6.0.0-beta.0 || ^6.3.0 + checksum: 589f89b53ff166ca9099ea8d2a5b6f96b87a3daf2e0cb115e94c8880639f69bc25a04cab2926cba0c99dc9bb70a159528c6f1fc10a9fba67e4fb3abe40bce0bf languageName: node linkType: hard -"@roadiehq/backstage-plugin-github-insights@npm:^2.0.0": - version: 2.0.4 - resolution: "@roadiehq/backstage-plugin-github-insights@npm:2.0.4" +"@roadiehq/backstage-plugin-github-insights@npm:^2.0.5": + version: 2.0.5 + resolution: "@roadiehq/backstage-plugin-github-insights@npm:2.0.5" dependencies: "@backstage/catalog-model": ^1.0.0 "@backstage/core-components": ^0.11.0 @@ -12533,19 +12536,19 @@ __metadata: "@octokit/types": ^6.14.2 history: ^5.0.0 immer: 9.0.7 - react-router: ^6.0.0-beta.0 react-use: ^17.2.4 zustand: 3.6.9 peerDependencies: react: ^16.13.1 || ^17.0.0 react-dom: ^16.13.1 || ^17.0.0 - checksum: 2cc6eb992e78d7ce32ecce09996bda4eb34d4af3564ab54d180543d3a195a8b6e93f3137724569c49e645d44bfc00f3802285418f690393c456700668be01c25 + react-router: 6.0.0-beta.0 || ^6.3.0 + checksum: 37f99d0478dee6acbbafaf334a2eb1f75c251e96f8b10cead0d6f6dc203667dca51ded935ca704900251c01493b6287a66814f79245410a79ad66c843a3d4803 languageName: node linkType: hard -"@roadiehq/backstage-plugin-github-pull-requests@npm:^2.0.0": - version: 2.2.6 - resolution: "@roadiehq/backstage-plugin-github-pull-requests@npm:2.2.6" +"@roadiehq/backstage-plugin-github-pull-requests@npm:^2.2.7": + version: 2.2.7 + resolution: "@roadiehq/backstage-plugin-github-pull-requests@npm:2.2.7" dependencies: "@backstage/catalog-model": ^1.0.0 "@backstage/core-components": ^0.11.0 @@ -12563,18 +12566,18 @@ __metadata: moment: ^2.27.0 msw: ^0.39.2 node-fetch: ^2.6.1 - react-router: 6.0.0-beta.0 react-use: ^17.2.4 peerDependencies: react: ^16.13.1 || ^17.0.0 react-dom: ^16.13.1 || ^17.0.0 - checksum: 1b6d584a1e6cc668026d9bcdea7e5588ad22084412e5e2c52659aed9da0f90fa5edb81e8d90d2ff67b645e0fb96790b91cb0a1024f1682319c7fb4799b62baa8 + react-router: 6.0.0-beta.0 || ^6.3.0 + checksum: 2453f72c4b853e4d6f43cb27aaf27cbce5d122fbcdc71625b1e1493486acde551798524cc84f792d986397011ab458ba9b7e56eec34cde55660ccd69ea488cb0 languageName: node linkType: hard -"@roadiehq/backstage-plugin-travis-ci@npm:^2.0.0": - version: 2.0.4 - resolution: "@roadiehq/backstage-plugin-travis-ci@npm:2.0.4" +"@roadiehq/backstage-plugin-travis-ci@npm:^2.0.5": + version: 2.0.5 + resolution: "@roadiehq/backstage-plugin-travis-ci@npm:2.0.5" dependencies: "@backstage/catalog-model": ^1.0.0 "@backstage/core-components": ^0.11.0 @@ -12588,13 +12591,13 @@ __metadata: date-fns: ^2.18.0 history: ^5.0.0 moment: ^2.29.1 - react-router: 6.0.0-beta.0 - react-router-dom: 6.0.0-beta.0 react-use: ^17.2.4 peerDependencies: react: ^16.13.1 || ^17.0.0 react-dom: ^16.13.1 || ^17.0.0 - checksum: 1c0f3389f6415d23fe1926e3387433da7f3d22b4a237c3a690c894cfa4c281b21307a3ec51a2c48cfa115727cca182c15017ef1e58a2e9b893d89d06df6db35e + react-router: 6.0.0-beta.0 || ^6.3.0 + react-router-dom: 6.0.0-beta.0 || ^6.3.0 + checksum: bafcef69ca1b36585dbafcf8964d897942bd026f74dad81f372aed9ee1ce496a4821570f462b62b1b8d0cb86013615ad39e103827163bde8cf32037143b05c7a languageName: node linkType: hard @@ -22447,16 +22450,17 @@ __metadata: "@material-ui/lab": 4.0.0-alpha.57 "@octokit/rest": ^19.0.3 "@rjsf/core": ^3.2.1 - "@roadiehq/backstage-plugin-buildkite": ^2.0.0 - "@roadiehq/backstage-plugin-github-insights": ^2.0.0 - "@roadiehq/backstage-plugin-github-pull-requests": ^2.0.0 - "@roadiehq/backstage-plugin-travis-ci": ^2.0.0 + "@roadiehq/backstage-plugin-buildkite": ^2.0.8 + "@roadiehq/backstage-plugin-github-insights": ^2.0.5 + "@roadiehq/backstage-plugin-github-pull-requests": ^2.2.7 + "@roadiehq/backstage-plugin-travis-ci": ^2.0.5 "@testing-library/cypress": ^8.0.2 "@testing-library/jest-dom": ^5.10.1 "@testing-library/react": ^12.1.3 "@testing-library/user-event": ^14.0.0 "@types/jquery": ^3.3.34 "@types/node": ^16.11.26 + "@types/react": "*" "@types/react-dom": "*" "@types/zen-observable": ^0.8.0 cross-env: ^7.0.0 @@ -34588,7 +34592,7 @@ __metadata: languageName: node linkType: hard -"react-router-stable@npm:react-router@^6.3.0, react-router@npm:6.3.0, react-router@npm:^6.0.0-beta.0, react-router@npm:^6.3.0": +"react-router-stable@npm:react-router@^6.3.0, react-router@npm:6.3.0, react-router@npm:^6.3.0": version: 6.3.0 resolution: "react-router@npm:6.3.0" dependencies: @@ -36022,6 +36026,7 @@ __metadata: concurrently: ^7.0.0 cross-env: ^7.0.0 e2e-test: "workspace:*" + eslint: ^8.6.0 eslint-plugin-notice: ^0.9.10 fs-extra: 10.1.0 husky: ^8.0.0