diff --git a/.changeset/shiny-hotels-tell.md b/.changeset/shiny-hotels-tell.md new file mode 100644 index 0000000000..7443a8d639 --- /dev/null +++ b/.changeset/shiny-hotels-tell.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-github-deployments': patch +--- + +Add deployment statuses to the GithubDeployments plugin diff --git a/plugins/github-deployments/src/api/index.ts b/plugins/github-deployments/src/api/index.ts index a5d824914e..6f1b7e4772 100644 --- a/plugins/github-deployments/src/api/index.ts +++ b/plugins/github-deployments/src/api/index.ts @@ -53,6 +53,10 @@ const getBaseUrl = ( return config?.config.apiBaseUrl; }; +type Node = { + logUrl?: string; +}; + export type GithubDeployment = { environment: string; state: string; @@ -61,9 +65,15 @@ export type GithubDeployment = { abbreviatedOid: string; commitUrl: string; } | null; + statuses: { + nodes: Node[]; + }; creator: { login: string; }; + repository: { + nameWithOwner: string; + }; payload: string; }; @@ -72,6 +82,7 @@ type QueryParams = { owner: string; repo: string; last: number; + lastStatuses: number; }; export interface GithubDeploymentsApi { @@ -89,7 +100,7 @@ export type Options = { }; const deploymentsQuery = ` -query deployments($owner: String!, $repo: String!, $last: Int) { +query deployments($owner: String!, $repo: String!, $last: Int, $lastStatuses: Int) { repository(owner: $owner, name: $repo) { deployments(last: $last) { nodes { @@ -100,9 +111,17 @@ query deployments($owner: String!, $repo: String!, $last: Int) { abbreviatedOid commitUrl } + statuses(last: $lastStatuses) { + nodes { + logUrl + } + } creator { login } + repository { + nameWithOwner + } payload } } diff --git a/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx b/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx index a13c205084..597b800cf5 100644 --- a/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx +++ b/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx @@ -36,11 +36,13 @@ import { const GithubDeploymentsComponent = ({ projectSlug, last, + lastStatuses, columns, host, }: { projectSlug: string; last: number; + lastStatuses: number; columns: TableColumn[]; host: string | undefined; }) => { @@ -48,7 +50,14 @@ const GithubDeploymentsComponent = ({ const [owner, repo] = projectSlug.split('/'); const { loading, value, error, retry: reload } = useAsyncRetry( - async () => await api.listDeployments({ host, owner, repo, last }), + async () => + await api.listDeployments({ + host, + owner, + repo, + last, + lastStatuses, + }), ); if (error) { @@ -67,9 +76,11 @@ const GithubDeploymentsComponent = ({ export const GithubDeploymentsCard = ({ last, + lastStatuses, columns, }: { last?: number; + lastStatuses?: number; columns?: TableColumn[]; }) => { const { entity } = useEntity(); @@ -86,6 +97,7 @@ export const GithubDeploymentsCard = ({ entity?.metadata.annotations?.[GITHUB_PROJECT_SLUG_ANNOTATION] || '' } last={last || 10} + lastStatuses={lastStatuses || 5} host={host} columns={columns || GithubDeploymentsTable.defaultDeploymentColumns} /> diff --git a/plugins/github-deployments/src/mocks/mocks.ts b/plugins/github-deployments/src/mocks/mocks.ts index b2a75ac7b0..f81f68c983 100644 --- a/plugins/github-deployments/src/mocks/mocks.ts +++ b/plugins/github-deployments/src/mocks/mocks.ts @@ -48,9 +48,15 @@ export const responseStub: QueryResponse = { commitUrl: 'https://exampleapi.com/123456789', abbreviatedOid: '12345', }, + statuses: { + nodes: [{ logUrl: 'taskrun/example-run' }], + }, creator: { login: 'robot-user-001', }, + repository: { + nameWithOwner: 'org/owner', + }, payload: '{"target":"moon"}', }, { @@ -61,8 +67,14 @@ export const responseStub: QueryResponse = { commitUrl: 'https://exampleapi.com/543212345', abbreviatedOid: '54321', }, + statuses: { + nodes: [{ logUrl: 'taskrun/example-run' }], + }, creator: { - login: 'robot-user-002', + login: 'robot-user-001', + }, + repository: { + nameWithOwner: 'org/owner', }, payload: '{"target":"sun"}', }, @@ -83,10 +95,16 @@ export const refreshedResponseStub: QueryResponse = { commitUrl: 'https://exampleapi.com/123456789', abbreviatedOid: '12345', }, + statuses: { + nodes: [{ logUrl: 'taskrun/example-run' }], + }, creator: { login: 'robot-user-001', }, - payload: '', + repository: { + nameWithOwner: 'org/owner', + }, + payload: '{"target":"moon"}', }, { state: 'failure', @@ -96,10 +114,16 @@ export const refreshedResponseStub: QueryResponse = { commitUrl: 'https://exampleapi.com/543212345', abbreviatedOid: '54321', }, - creator: { - login: 'robot-user-002', + statuses: { + nodes: [{ logUrl: 'taskrun/example-run' }], }, - payload: '', + creator: { + login: 'robot-user-001', + }, + repository: { + nameWithOwner: 'org/owner', + }, + payload: '{"target":"sun"}', }, ], },