Skip to content

Commit

Permalink
Merge pull request #3 from Work-m8/Release_please
Browse files Browse the repository at this point in the history
Fix: Fixed release please action
  • Loading branch information
pascalwilbrink authored Oct 24, 2023
2 parents 92bec31 + 3b0d5d5 commit 603107d
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/release-please.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

name: release-please
jobs:
release-please:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ In your `EntityPage.tsx` file located in `packages\app\src\components\catalog` w
First we need to add the following imports:

```ts
import { DockerRepositoriesWidget } from '@workm8/backstage-docker-plugin';
import { DockerTagsTableWidget } from '@workm8/backstage-docker-plugin';
```

You can display the Widget by adding the following code (for example, the `overviewContent`):

```diff
+ const dockerImagesContent = (
+ <DockerRepositoriesWidget
+ const dockerTagsContent = (
+ <DockerTagsTableWidget
+ heading="Docker"
+ columns={['name', 'username', 'status']} />
+ );
Expand All @@ -53,7 +53,7 @@ const overviewContent = (
<EntityCatalogGraphCard variant="gridItem" height={400} />
</Grid>
+ <Grid item md={4} xs={12}>
+ {dockerImagesContent}
+ {dockerTagsContent}
+ </Grid>
<Grid item md={4} xs={12}>
<EntityLinksCard />
Expand Down
18 changes: 14 additions & 4 deletions src/apis/Docker/DockerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,23 @@ export class DockerClient implements DockerApi {
pageNumber: number,
pageSize: number,
): Promise<TagsResponse> {
console.log(this.options.configApi);
const baseUrl = await this.options.discoveryApi.getBaseUrl('');

const targetUrl = `${baseUrl}proxy${url}`;

return this.options.fetchApi
.fetch(`${targetUrl}?page=${pageNumber}&page_size=${pageSize}`)
.then(res => res.json());
return new Promise((resolve, reject) => {
this.options.fetchApi
.fetch(`${targetUrl}?page=${pageNumber}&page_size=${pageSize}`)
.then(res => res.json())
.then(res => {
if ('errinfo' in res) {
return reject({
name: 'Error',
message: `Could not find namespace ${res.errinfo.namespace} or repository ${res.errinfo.repository}`,
});
}
return resolve(res);
});
});
}
}
6 changes: 3 additions & 3 deletions src/apis/Docker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export type Image = {
export type Repository = {
creator: number;
id: number;
images: Image[];
images: Partial<Image>[];
last_updated: string;
last_updater: number;
last_updated_username: string;
last_updater_username: string;
name: string;
repository: number;
full_size: number;
Expand All @@ -39,7 +39,7 @@ export type TagsResponse = {
count: number;
next?: string;
previous?: string;
results: Repository[];
results: Partial<Repository>[];
};

export interface DockerApi {
Expand Down
247 changes: 247 additions & 0 deletions src/components/Docker/DockerTagsTable.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
import React from 'react';
import { DockerTagsTable } from './DockerTagsTable';
import {
renderInTestApp,
setupRequestMockHandlers,
TestApiProvider
} from '@backstage/test-utils';

import { Entity } from '@backstage/catalog-model';
import { EntityProvider } from '@backstage/plugin-catalog-react';

import { setupServer } from 'msw/node';

import { DockerApi, dockerApiRef } from '../../apis';

describe('DockerTagsTable', () => {
const worker = setupServer();
setupRequestMockHandlers(worker);

const dockerApi: jest.Mocked<DockerApi> = {
getRepositories: jest.fn()
};

let Wrapper: React.ComponentType<React.PropsWithChildren<{}>>;

beforeEach(() => {
Wrapper = ({ children }: { children?: React.ReactNode }) => (
<TestApiProvider apis={[[dockerApiRef, dockerApi]]}>
{children}
</TestApiProvider>
);
});

it('renders missing Annotation error', async () => {
const entity: Entity = {
apiVersion: 'v1',
kind: 'Component',
metadata: {
name: 'my-name',
},
};
const widget = await renderInTestApp(
<Wrapper>
<EntityProvider entity={entity}>
<DockerTagsTable />
</EntityProvider>
</Wrapper>
)
expect(widget.getByText(/Missing Annotation/i)).toBeInTheDocument();
expect(widget.getByText('docker.com/repository')).toBeInTheDocument();
});

it('renders basic table', async () => {
const entity: Entity = {
apiVersion: 'v1',
kind: 'Component',
metadata: {
name: 'my-name',
annotations: {
'docker.com/repository': 'foo/bar'
}
},
};

dockerApi.getRepositories.mockResolvedValue({
count: 1,
results: [
{
name: 'V1.0.0',
tag_status: 'Active',
last_updater_username: 'TEST_USERNAME',
images: [
{
architecture: 'AMD64'
}
]
}
]
});

const widget = await renderInTestApp(
<Wrapper>
<EntityProvider entity={entity}>
<DockerTagsTable />
</EntityProvider>
</Wrapper>
)

expect(widget.getByText('Docker Tags (1)')).toBeInTheDocument();
expect(widget.getByText('V1.0.0')).toBeInTheDocument();
expect(widget.getByText('Active')).toBeInTheDocument();
expect(widget.getByText('TEST_USERNAME')).toBeInTheDocument();
expect(widget.getByText('AMD64')).toBeInTheDocument();
});

['name', 'status', 'username', 'architecture'].forEach((column) => {
it(`renders table with column ${column}`, async () => {
const entity: Entity = {
apiVersion: 'v1',
kind: 'Component',
metadata: {
name: 'my-name',
annotations: {
'docker.com/repository': 'foo/bar'
}
},
};

dockerApi.getRepositories.mockResolvedValue({
count: 1,
results: [
{
name: 'V1.0.0',
tag_status: 'Active',
last_updater_username: 'TEST_USERNAME',
images: [
{
architecture: 'AMD64'
}
]
}
]
});

const widget = await renderInTestApp(
<Wrapper>
<EntityProvider entity={entity}>
<DockerTagsTable columns={[column]} />
</EntityProvider>
</Wrapper>
)

expect(widget.getByText('Docker Tags (1)')).toBeInTheDocument();

switch (column) {
case 'name':
expect(widget.getByText('V1.0.0')).toBeInTheDocument();
break;
case 'status':
expect(widget.getByText('Active')).toBeInTheDocument();
break;
case 'username':
expect(widget.getByText('TEST_USERNAME')).toBeInTheDocument();
break;
case 'architecture':
expect(widget.getByText('AMD64')).toBeInTheDocument();
break;
}
});
});

it('renders empty table', async () => {
const entity: Entity = {
apiVersion: 'v1',
kind: 'Component',
metadata: {
name: 'my-name',
annotations: {
'docker.com/repository': 'foo/bar'
}
},
};

dockerApi.getRepositories.mockResolvedValue({
count: 0,
results: []
});

const widget = await renderInTestApp(
<Wrapper>
<EntityProvider entity={entity}>
<DockerTagsTable />
</EntityProvider>
</Wrapper>
)
expect(widget.getByText('Docker Tags (0)')).toBeInTheDocument();
expect(widget.getByText('No records to display')).toBeInTheDocument();
});

it('renders a table with mock data', async () => {
const entity: Entity = {
apiVersion: 'v1',
kind: 'Component',
metadata: {
name: 'my-name',
annotations: {
'docker.com/repository': 'foo/bar',
},
},
};

const columns = [
{
name: 'V1.0.0',
tag_status: 'Active',
last_updater_username: 'TEST',
},
{
name: 'V0.9.0',
tag_status: 'Inactive',
last_updater_username: 'TEST',
},
];
dockerApi.getRepositories.mockResolvedValue({
count: 2,
results: columns,
});

const widget = await renderInTestApp(
<Wrapper>
<EntityProvider entity={entity}>
<DockerTagsTable />
</EntityProvider>
</Wrapper>,
);

expect(widget.getByText('Docker Tags (2)')).toBeInTheDocument();
});

it('Renders custom header', async () => {
const entity: Entity = {
apiVersion: 'v1',
kind: 'Component',
metadata: {
name: 'my-name',
annotations: {
'docker.com/repository': 'foo/bar'
}
},
};

dockerApi.getRepositories.mockResolvedValue({
count: 0,
results: []
});

const widget = await renderInTestApp(
<Wrapper>
<EntityProvider entity={entity}>
<DockerTagsTable heading="Tags" />
</EntityProvider>
</Wrapper>
)
expect(widget.getByText('Tags (0)')).toBeInTheDocument();
});

});
Loading

0 comments on commit 603107d

Please sign in to comment.