From ef2f928f4a1b7f9b421afce927b6183ecc7fffef Mon Sep 17 00:00:00 2001 From: sam-robson Date: Mon, 17 May 2021 15:08:11 +0100 Subject: [PATCH 1/4] feat: add deployment statuses to GithubDeployments plugin Signed-off-by: sam-robson --- .changeset/shiny-hotels-tell.md | 5 +++ plugins/github-deployments/src/api/index.ts | 22 +++++++++++-- plugins/github-deployments/src/mocks/mocks.ts | 32 ++++++++++++++++--- 3 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 .changeset/shiny-hotels-tell.md diff --git a/.changeset/shiny-hotels-tell.md b/.changeset/shiny-hotels-tell.md new file mode 100644 index 0000000000..d907f5e2b2 --- /dev/null +++ b/.changeset/shiny-hotels-tell.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-github-deployments': minor +--- + +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 d7e7e2fca6..4049e082da 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; }; + statuses: { + nodes: Node[]; + }; creator: { login: string; }; + repository: { + nameWithOwner: string; + }; payload: string; }; @@ -89,9 +99,9 @@ export type Options = { }; const deploymentsQuery = ` -query deployments($owner: String!, $repo: String!, $last: Int) { +query deployments($owner: String!, $repo: String!, $lastDeployments: Int, $lastStatuses: Int) { repository(owner: $owner, name: $repo) { - deployments(last: $last) { + deployments(last: $lastDeployments) { nodes { state environment @@ -100,9 +110,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/mocks/mocks.ts b/plugins/github-deployments/src/mocks/mocks.ts index b2a75ac7b0..132d3e9d19 100644 --- a/plugins/github-deployments/src/mocks/mocks.ts +++ b/plugins/github-deployments/src/mocks/mocks.ts @@ -51,7 +51,13 @@ export const responseStub: QueryResponse = { creator: { login: 'robot-user-001', }, - payload: '{"target":"moon"}', + statuses: { + nodes: [{ logUrl: 'taskrun/example-run' }], + }, + repository: { + nameWithOwner: 'org/owner', + }, + payload: '', }, { state: 'pending', @@ -62,9 +68,15 @@ export const responseStub: QueryResponse = { abbreviatedOid: '54321', }, creator: { - login: 'robot-user-002', + login: 'robot-user-001', }, - payload: '{"target":"sun"}', + statuses: { + nodes: [{ logUrl: '' }], + }, + repository: { + nameWithOwner: 'org/owner', + }, + payload: '', }, ], }, @@ -86,6 +98,12 @@ export const refreshedResponseStub: QueryResponse = { creator: { login: 'robot-user-001', }, + statuses: { + nodes: [{ logUrl: 'taskrun/example-run' }], + }, + repository: { + nameWithOwner: 'org/owner', + }, payload: '', }, { @@ -97,7 +115,13 @@ export const refreshedResponseStub: QueryResponse = { abbreviatedOid: '54321', }, creator: { - login: 'robot-user-002', + login: 'robot-user-001', + }, + statuses: { + nodes: [{ logUrl: 'taskrun/example-run' }], + }, + repository: { + nameWithOwner: 'org/owner', }, payload: '', }, From 79ce75ed467b9dde30c9e56ed0f385501b5e42cd Mon Sep 17 00:00:00 2001 From: Sam Robson Date: Fri, 21 May 2021 11:28:37 +0100 Subject: [PATCH 2/4] fix: json parsing in a test Signed-off-by: Sam Robson --- plugins/github-deployments/src/mocks/mocks.ts | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/plugins/github-deployments/src/mocks/mocks.ts b/plugins/github-deployments/src/mocks/mocks.ts index 132d3e9d19..f81f68c983 100644 --- a/plugins/github-deployments/src/mocks/mocks.ts +++ b/plugins/github-deployments/src/mocks/mocks.ts @@ -48,16 +48,16 @@ export const responseStub: QueryResponse = { commitUrl: 'https://exampleapi.com/123456789', abbreviatedOid: '12345', }, - creator: { - login: 'robot-user-001', - }, statuses: { nodes: [{ logUrl: 'taskrun/example-run' }], }, + creator: { + login: 'robot-user-001', + }, repository: { nameWithOwner: 'org/owner', }, - payload: '', + payload: '{"target":"moon"}', }, { state: 'pending', @@ -67,16 +67,16 @@ export const responseStub: QueryResponse = { commitUrl: 'https://exampleapi.com/543212345', abbreviatedOid: '54321', }, + statuses: { + nodes: [{ logUrl: 'taskrun/example-run' }], + }, creator: { login: 'robot-user-001', }, - statuses: { - nodes: [{ logUrl: '' }], - }, repository: { nameWithOwner: 'org/owner', }, - payload: '', + payload: '{"target":"sun"}', }, ], }, @@ -95,16 +95,16 @@ export const refreshedResponseStub: QueryResponse = { commitUrl: 'https://exampleapi.com/123456789', abbreviatedOid: '12345', }, - creator: { - login: 'robot-user-001', - }, statuses: { nodes: [{ logUrl: 'taskrun/example-run' }], }, + creator: { + login: 'robot-user-001', + }, repository: { nameWithOwner: 'org/owner', }, - payload: '', + payload: '{"target":"moon"}', }, { state: 'failure', @@ -114,16 +114,16 @@ export const refreshedResponseStub: QueryResponse = { commitUrl: 'https://exampleapi.com/543212345', abbreviatedOid: '54321', }, - creator: { - login: 'robot-user-001', - }, statuses: { nodes: [{ logUrl: 'taskrun/example-run' }], }, + creator: { + login: 'robot-user-001', + }, repository: { nameWithOwner: 'org/owner', }, - payload: '', + payload: '{"target":"sun"}', }, ], }, From e9702d811fd4c71be4e369e4daa70518cf28df14 Mon Sep 17 00:00:00 2001 From: Sam Robson Date: Wed, 26 May 2021 15:43:25 +0100 Subject: [PATCH 3/4] fix: update query params Signed-off-by: Sam Robson --- plugins/github-deployments/src/api/index.ts | 3 ++- .../src/components/GithubDeploymentsCard.tsx | 24 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/plugins/github-deployments/src/api/index.ts b/plugins/github-deployments/src/api/index.ts index 4049e082da..3c2b492b10 100644 --- a/plugins/github-deployments/src/api/index.ts +++ b/plugins/github-deployments/src/api/index.ts @@ -81,7 +81,8 @@ type QueryParams = { host: string | undefined; owner: string; repo: string; - last: number; + lastDeployments: number; + lastStatuses: number; }; export interface GithubDeploymentsApi { diff --git a/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx b/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx index a13c205084..b8a8ac1969 100644 --- a/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx +++ b/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx @@ -35,12 +35,14 @@ import { const GithubDeploymentsComponent = ({ projectSlug, - last, + lastDeployments, + lastStatuses, columns, host, }: { projectSlug: string; - last: number; + lastDeployments: 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, + lastStatuses, + lastDeployments, + }), ); if (error) { @@ -66,10 +75,12 @@ const GithubDeploymentsComponent = ({ }; export const GithubDeploymentsCard = ({ - last, + lastDeployments, + lastStatuses, columns, }: { - last?: number; + lastDeployments?: number; + lastStatuses?: number; columns?: TableColumn[]; }) => { const { entity } = useEntity(); @@ -85,7 +96,8 @@ export const GithubDeploymentsCard = ({ projectSlug={ entity?.metadata.annotations?.[GITHUB_PROJECT_SLUG_ANNOTATION] || '' } - last={last || 10} + lastDeployments={lastDeployments || 10} + lastStatuses={lastStatuses || 5} host={host} columns={columns || GithubDeploymentsTable.defaultDeploymentColumns} /> From 30af1c4d6b22d819354aeb4f9a9901c4eec7d8e0 Mon Sep 17 00:00:00 2001 From: Sam Robson Date: Wed, 26 May 2021 19:40:18 +0100 Subject: [PATCH 4/4] refactor: rename to avoid breaking changes Signed-off-by: Sam Robson --- .changeset/shiny-hotels-tell.md | 2 +- plugins/github-deployments/src/api/index.ts | 6 +++--- .../src/components/GithubDeploymentsCard.tsx | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.changeset/shiny-hotels-tell.md b/.changeset/shiny-hotels-tell.md index d907f5e2b2..7443a8d639 100644 --- a/.changeset/shiny-hotels-tell.md +++ b/.changeset/shiny-hotels-tell.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-github-deployments': minor +'@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 3c2b492b10..63b56d87e1 100644 --- a/plugins/github-deployments/src/api/index.ts +++ b/plugins/github-deployments/src/api/index.ts @@ -81,7 +81,7 @@ type QueryParams = { host: string | undefined; owner: string; repo: string; - lastDeployments: number; + last: number; lastStatuses: number; }; @@ -100,9 +100,9 @@ export type Options = { }; const deploymentsQuery = ` -query deployments($owner: String!, $repo: String!, $lastDeployments: Int, $lastStatuses: Int) { +query deployments($owner: String!, $repo: String!, $last: Int, $lastStatuses: Int) { repository(owner: $owner, name: $repo) { - deployments(last: $lastDeployments) { + deployments(last: $last) { nodes { state environment diff --git a/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx b/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx index b8a8ac1969..597b800cf5 100644 --- a/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx +++ b/plugins/github-deployments/src/components/GithubDeploymentsCard.tsx @@ -35,13 +35,13 @@ import { const GithubDeploymentsComponent = ({ projectSlug, - lastDeployments, + last, lastStatuses, columns, host, }: { projectSlug: string; - lastDeployments: number; + last: number; lastStatuses: number; columns: TableColumn[]; host: string | undefined; @@ -55,8 +55,8 @@ const GithubDeploymentsComponent = ({ host, owner, repo, + last, lastStatuses, - lastDeployments, }), ); @@ -75,11 +75,11 @@ const GithubDeploymentsComponent = ({ }; export const GithubDeploymentsCard = ({ - lastDeployments, + last, lastStatuses, columns, }: { - lastDeployments?: number; + last?: number; lastStatuses?: number; columns?: TableColumn[]; }) => { @@ -96,7 +96,7 @@ export const GithubDeploymentsCard = ({ projectSlug={ entity?.metadata.annotations?.[GITHUB_PROJECT_SLUG_ANNOTATION] || '' } - lastDeployments={lastDeployments || 10} + last={last || 10} lastStatuses={lastStatuses || 5} host={host} columns={columns || GithubDeploymentsTable.defaultDeploymentColumns}