Merge pull request #5699 from sam-robson/statuses-for-github-deployments-plugin

feat: add deployment statuses to GithubDeployments plugin
This commit is contained in:
Fredrik Adelöw
2021-06-09 15:08:36 +02:00
committed by GitHub
4 changed files with 67 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-github-deployments': patch
---
Add deployment statuses to the GithubDeployments plugin
+20 -1
View File
@@ -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
}
}
@@ -36,11 +36,13 @@ import {
const GithubDeploymentsComponent = ({
projectSlug,
last,
lastStatuses,
columns,
host,
}: {
projectSlug: string;
last: number;
lastStatuses: number;
columns: TableColumn<GithubDeployment>[];
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<GithubDeployment>[];
}) => {
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}
/>
+29 -5
View File
@@ -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"}',
},
],
},