From 09dfdbad5c7ae3bbbb7a3643132623a0ada49285 Mon Sep 17 00:00:00 2001 From: Nikita Nek Dudnik Date: Fri, 10 Jul 2020 09:24:32 +0200 Subject: [PATCH 1/4] feat: github actions api type with a mock implementation --- packages/app/src/apis.ts | 5 +++ plugins/github-actions/package.json | 1 + .../src/api/GithubActionsApi.ts | 28 ++++++++++++ .../MockGithubActionsClient.ts} | 12 ++--- plugins/github-actions/src/api/index.test.ts | 44 +++++++++++++++++++ .../src/{apis/builds => api}/index.ts | 3 +- .../src/{apis/builds => api}/types.ts | 0 .../BuildDetailsPage/BuildDetailsPage.tsx | 8 ++-- .../BuildInfoCard/BuildInfoCard.tsx | 8 ++-- .../BuildListPage/BuildListPage.tsx | 8 ++-- .../BuildStatusIndicator.tsx | 2 +- plugins/github-actions/src/index.ts | 1 + 12 files changed, 98 insertions(+), 22 deletions(-) create mode 100644 plugins/github-actions/src/api/GithubActionsApi.ts rename plugins/github-actions/src/{apis/builds/BuildsClient.ts => api/MockGithubActionsClient.ts} (77%) create mode 100644 plugins/github-actions/src/api/index.test.ts rename plugins/github-actions/src/{apis/builds => api}/index.ts (88%) rename plugins/github-actions/src/{apis/builds => api}/types.ts (100%) diff --git a/packages/app/src/apis.ts b/packages/app/src/apis.ts index abc490b658..df17886216 100644 --- a/packages/app/src/apis.ts +++ b/packages/app/src/apis.ts @@ -58,6 +58,10 @@ import { import { scaffolderApiRef, ScaffolderApi } from '@backstage/plugin-scaffolder'; import { rollbarApiRef, RollbarClient } from '@backstage/plugin-rollbar'; +import { + MockGithubActionsClient, + githubActionsApiRef, +} from '@backstage/plugin-github-actions'; export const apis = (config: ConfigApi) => { // eslint-disable-next-line no-console @@ -75,6 +79,7 @@ export const apis = (config: ConfigApi) => { builder.add(storageApiRef, WebStorage.create({ errorApi })); builder.add(circleCIApiRef, new CircleCIApi()); + builder.add(githubActionsApiRef, new MockGithubActionsClient()); builder.add(featureFlagsApiRef, new FeatureFlags()); builder.add(lighthouseApiRef, new LighthouseRestApi('http://localhost:3003')); diff --git a/plugins/github-actions/package.json b/plugins/github-actions/package.json index 456bd826c0..a4528c42a5 100644 --- a/plugins/github-actions/package.json +++ b/plugins/github-actions/package.json @@ -22,6 +22,7 @@ }, "dependencies": { "@backstage/core": "^0.1.1-alpha.13", + "@backstage/core-api": "^0.1.1-alpha.13", "@backstage/theme": "^0.1.1-alpha.13", "@material-ui/core": "^4.9.1", "@material-ui/icons": "^4.9.1", diff --git a/plugins/github-actions/src/api/GithubActionsApi.ts b/plugins/github-actions/src/api/GithubActionsApi.ts new file mode 100644 index 0000000000..7c52bbcb70 --- /dev/null +++ b/plugins/github-actions/src/api/GithubActionsApi.ts @@ -0,0 +1,28 @@ +/* + * Copyright 2020 Spotify AB + * + * 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 { createApiRef } from '@backstage/core'; +import { Build, BuildDetails } from './types'; + +export const githubActionsApiRef = createApiRef({ + id: 'plugin.githubactions.service', + description: 'Used by the Github Actions plugin to make requests', +}); + +export type GithubActionsApi = { + listBuilds: (_entityUri: string) => Promise; + getBuild: (_buildUri: string) => Promise; +}; diff --git a/plugins/github-actions/src/apis/builds/BuildsClient.ts b/plugins/github-actions/src/api/MockGithubActionsClient.ts similarity index 77% rename from plugins/github-actions/src/apis/builds/BuildsClient.ts rename to plugins/github-actions/src/api/MockGithubActionsClient.ts index 6fbc6a6c53..89ecad3931 100644 --- a/plugins/github-actions/src/apis/builds/BuildsClient.ts +++ b/plugins/github-actions/src/api/MockGithubActionsClient.ts @@ -14,20 +14,16 @@ * limitations under the License. */ +import { GithubActionsApi } from './GithubActionsApi'; import { Build, BuildDetails, BuildStatus } from './types'; -export class BuildsClient { - static create(): BuildsClient { - return new BuildsClient(); - } - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - async listBuilds(_entityUri: string): Promise { +export class MockGithubActionsClient implements GithubActionsApi { + async listBuilds(): Promise { return []; } // eslint-disable-next-line @typescript-eslint/no-unused-vars - async getBuild(_buildUri: string): Promise { + async getBuild(): Promise { return { build: { commitId: 'TODO', diff --git a/plugins/github-actions/src/api/index.test.ts b/plugins/github-actions/src/api/index.test.ts new file mode 100644 index 0000000000..70319b8120 --- /dev/null +++ b/plugins/github-actions/src/api/index.test.ts @@ -0,0 +1,44 @@ +/* + * Copyright 2020 Spotify AB + * + * 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 { MockGithubActionsClient } from './MockGithubActionsClient'; +import { BuildStatus } from './types'; + +describe('Github Actions API', () => { + let client: MockGithubActionsClient; + beforeEach(() => { + client = new MockGithubActionsClient(); + }); + describe('Mock client', () => { + it('gets a list of builds by a project id', async () => { + await expect(client.listBuilds()).resolves.toEqual([]); + }); + it('gets a build info by its id', async () => { + await expect(client.getBuild()).resolves.toEqual({ + build: { + commitId: 'TODO', + branch: 'TODO', + uri: 'TODO', + status: BuildStatus.Running, + message: 'TODO', + }, + author: 'TODO', + logUrl: 'TODO', + overviewUrl: 'TODO', + }); + }); + }); +}); diff --git a/plugins/github-actions/src/apis/builds/index.ts b/plugins/github-actions/src/api/index.ts similarity index 88% rename from plugins/github-actions/src/apis/builds/index.ts rename to plugins/github-actions/src/api/index.ts index 9ce2150893..66c2c053fe 100644 --- a/plugins/github-actions/src/apis/builds/index.ts +++ b/plugins/github-actions/src/api/index.ts @@ -14,5 +14,6 @@ * limitations under the License. */ -export { BuildsClient } from './BuildsClient'; +export * from './GithubActionsApi'; +export * from './MockGithubActionsClient'; export * from './types'; diff --git a/plugins/github-actions/src/apis/builds/types.ts b/plugins/github-actions/src/api/types.ts similarity index 100% rename from plugins/github-actions/src/apis/builds/types.ts rename to plugins/github-actions/src/api/types.ts diff --git a/plugins/github-actions/src/components/BuildDetailsPage/BuildDetailsPage.tsx b/plugins/github-actions/src/components/BuildDetailsPage/BuildDetailsPage.tsx index bb07e0d6aa..2244a4c432 100644 --- a/plugins/github-actions/src/components/BuildDetailsPage/BuildDetailsPage.tsx +++ b/plugins/github-actions/src/components/BuildDetailsPage/BuildDetailsPage.tsx @@ -32,8 +32,9 @@ import { import React from 'react'; import { useParams } from 'react-router-dom'; import { useAsync } from 'react-use'; -import { BuildsClient } from '../../apis/builds'; import { BuildStatusIndicator } from '../BuildStatusIndicator'; +import { useApi } from '@backstage/core-api'; +import { githubActionsApiRef } from '../../api'; const useStyles = makeStyles(theme => ({ root: { @@ -48,12 +49,11 @@ const useStyles = makeStyles(theme => ({ }, })); -const client = BuildsClient.create(); - export const BuildDetailsPage = () => { + const api = useApi(githubActionsApiRef); const classes = useStyles(); const { buildUri } = useParams(); - const status = useAsync(() => client.getBuild(buildUri), [buildUri]); + const status = useAsync(() => api.getBuild(buildUri), [buildUri]); if (status.loading) { return ; diff --git a/plugins/github-actions/src/components/BuildInfoCard/BuildInfoCard.tsx b/plugins/github-actions/src/components/BuildInfoCard/BuildInfoCard.tsx index a04189debc..2e4cbb03bd 100644 --- a/plugins/github-actions/src/components/BuildInfoCard/BuildInfoCard.tsx +++ b/plugins/github-actions/src/components/BuildInfoCard/BuildInfoCard.tsx @@ -27,10 +27,9 @@ import { } from '@material-ui/core'; import React from 'react'; import { useAsync } from 'react-use'; -import { BuildsClient } from '../../apis/builds'; import { BuildStatusIndicator } from '../BuildStatusIndicator'; - -const client = BuildsClient.create(); +import { githubActionsApiRef } from '../../api'; +import { useApi } from '@backstage/core-api'; const useStyles = makeStyles(theme => ({ root: { @@ -43,7 +42,8 @@ const useStyles = makeStyles(theme => ({ export const BuildInfoCard = () => { const classes = useStyles(); - const status = useAsync(() => client.listBuilds('entity:spotify:backstage')); + const api = useApi(githubActionsApiRef); + const status = useAsync(() => api.listBuilds('entity:spotify:backstage')); let content: JSX.Element; diff --git a/plugins/github-actions/src/components/BuildListPage/BuildListPage.tsx b/plugins/github-actions/src/components/BuildListPage/BuildListPage.tsx index fc784108d4..d68f756129 100644 --- a/plugins/github-actions/src/components/BuildListPage/BuildListPage.tsx +++ b/plugins/github-actions/src/components/BuildListPage/BuildListPage.tsx @@ -31,10 +31,9 @@ import { } from '@material-ui/core'; import React from 'react'; import { useAsync } from 'react-use'; -import { BuildsClient } from '../../apis/builds'; import { BuildStatusIndicator } from '../BuildStatusIndicator'; - -const client = BuildsClient.create(); +import { githubActionsApiRef } from '../../api'; +import { useApi } from '@backstage/core-api'; const LongText = ({ text, max }: { text: string; max: number }) => { if (text.length < max) { @@ -57,8 +56,9 @@ const useStyles = makeStyles(theme => ({ })); const PageContents = () => { + const api = useApi(githubActionsApiRef); const { loading, error, value } = useAsync(() => - client.listBuilds('entity:spotify:backstage'), + api.listBuilds('entity:spotify:backstage'), ); if (loading) { diff --git a/plugins/github-actions/src/components/BuildStatusIndicator/BuildStatusIndicator.tsx b/plugins/github-actions/src/components/BuildStatusIndicator/BuildStatusIndicator.tsx index 332a03d67a..1a198f4df2 100644 --- a/plugins/github-actions/src/components/BuildStatusIndicator/BuildStatusIndicator.tsx +++ b/plugins/github-actions/src/components/BuildStatusIndicator/BuildStatusIndicator.tsx @@ -21,7 +21,7 @@ import SuccessIcon from '@material-ui/icons/CheckCircle'; import FailureIcon from '@material-ui/icons/Error'; import UnknownIcon from '@material-ui/icons/Help'; import React from 'react'; -import { BuildStatus } from '../../apis/builds'; +import { BuildStatus } from '../../api/types'; type Props = { status?: BuildStatus; diff --git a/plugins/github-actions/src/index.ts b/plugins/github-actions/src/index.ts index 3a0a0fe2d3..d67bc6a864 100644 --- a/plugins/github-actions/src/index.ts +++ b/plugins/github-actions/src/index.ts @@ -15,3 +15,4 @@ */ export { plugin } from './plugin'; +export * from './api'; From 5e93d376b515f2260656daeac3cefbacf7efa79e Mon Sep 17 00:00:00 2001 From: ebarrios Date: Fri, 10 Jul 2020 15:48:03 +0200 Subject: [PATCH 2/4] Removed Mock implementation and tried to add the real one --- plugins/github-actions/package.json | 2 + .../src/api/GithubActionsApi.ts | 29 +++ .../src/api/GithubActionsClient.ts | 154 ++++++++++++ plugins/github-actions/src/api/index.test.ts | 44 ++++ plugins/github-actions/src/api/index.ts | 19 ++ plugins/github-actions/src/api/types.ts | 224 ++++++++++++++++++ .../BuildDetailsPage/BuildDetailsPage.tsx | 11 +- .../BuildInfoCard/BuildInfoCard.tsx | 8 +- .../BuildListPage/BuildListPage.tsx | 20 +- .../BuildStatusIndicator.tsx | 2 +- plugins/github-actions/src/index.ts | 1 + 11 files changed, 497 insertions(+), 17 deletions(-) create mode 100644 plugins/github-actions/src/api/GithubActionsApi.ts create mode 100644 plugins/github-actions/src/api/GithubActionsClient.ts create mode 100644 plugins/github-actions/src/api/index.test.ts create mode 100644 plugins/github-actions/src/api/index.ts create mode 100644 plugins/github-actions/src/api/types.ts diff --git a/plugins/github-actions/package.json b/plugins/github-actions/package.json index 456bd826c0..8ac474169f 100644 --- a/plugins/github-actions/package.json +++ b/plugins/github-actions/package.json @@ -21,7 +21,9 @@ "clean": "backstage-cli clean" }, "dependencies": { + "@backstage/catalog-model": "^0.1.1-alpha.13", "@backstage/core": "^0.1.1-alpha.13", + "@backstage/core-api": "^0.1.1-alpha.13", "@backstage/theme": "^0.1.1-alpha.13", "@material-ui/core": "^4.9.1", "@material-ui/icons": "^4.9.1", diff --git a/plugins/github-actions/src/api/GithubActionsApi.ts b/plugins/github-actions/src/api/GithubActionsApi.ts new file mode 100644 index 0000000000..58892173ed --- /dev/null +++ b/plugins/github-actions/src/api/GithubActionsApi.ts @@ -0,0 +1,29 @@ +/* + * Copyright 2020 Spotify AB + * + * 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 { createApiRef } from '@backstage/core'; +import { Build, BuildDetails } from './types'; +import { Entity } from '@backstage/catalog-model'; + +export const githubActionsApiRef = createApiRef({ + id: 'plugin.githubactions.service', + description: 'Used by the Github Actions plugin to make requests', +}); + +export type GithubActionsApi = { + listBuilds: (entity: Entity, token: Promise) => Promise; + getBuild: (buildUri: string, token: Promise) => Promise; +}; diff --git a/plugins/github-actions/src/api/GithubActionsClient.ts b/plugins/github-actions/src/api/GithubActionsClient.ts new file mode 100644 index 0000000000..0c9a98e57c --- /dev/null +++ b/plugins/github-actions/src/api/GithubActionsClient.ts @@ -0,0 +1,154 @@ +/* + * Copyright 2020 Spotify AB + * + * 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 { GithubActionsApi } from './GithubActionsApi'; +import { Build, BuildDetails, BuildStatus, WorkflowRun } from './types'; +import { Entity } from '@backstage/catalog-model'; + +export class GithubActionsClient implements GithubActionsApi { + async listBuilds(entity: Entity, token: Promise): Promise { + // ### Feedback request ### + // I asumed the following: (maybe not the best. Ideally this should come from the link to the component.yaml file) + // entity.metadata.namespace => org name + // entity.metadata.name => repo name + // entityUri -> entity:spotify:backstage + + let url: string; + if (entity.metadata.name !== '') { + url = `https://api.github.com/repos/${entity.metadata.namespace}/${entity.metadata.name}/runs`; + } else { + url = 'https://api.github.com/repos/spotify/backstage/actions/runs'; + } + + const response = await fetch(url, { + headers: new Headers({ + Authorization: `Bearer ${await token}`, + }), + }); + + if (response.status > 200) { + return [ + { + commitId: 'Error', + message: 'ResponseCode > 200', + branch: 'Error', + status: BuildStatus.Failure, + uri: 'Error', + }, + ]; + } + + const data = await response.json(); + + const newData: WorkflowRun[] = data.workflow_runs; + + const endData: Build[] = []; + + newData.forEach((element, index) => { + const transData: Build = { + commitId: '', + message: '', + branch: '', + status: BuildStatus.Null, + uri: '', + }; + transData.commitId = String(element.head_commit.id); + transData.branch = element.head_branch; + + // ### Feedback request ### + // TODO: I am not sure about this part. Looks ugly. Maybe there is a better way of doing this. + if (element.conclusion === 'success') { + transData.status = BuildStatus.Success; + } else if (element.conclusion === 'failure') { + transData.status = BuildStatus.Failure; + } else if (element.conclusion === 'pending') { + transData.status = BuildStatus.Pending; + } else if (element.conclusion === 'running') { + transData.status = BuildStatus.Running; + } else { + if (element.status === 'in_progress') { + transData.status = BuildStatus.Running; + } else { + transData.status = BuildStatus.Null; + } + } + transData.message = element.head_commit.message; + transData.uri = element.url; + endData[index] = transData; + }); + + return endData; + } + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + async getBuild( + buildUri: string, + token: Promise, + ): Promise { + const response = await fetch(buildUri, { + headers: new Headers({ + Authorization: `Bearer ${await token}`, + }), + }); + const buildBlank: Build = { + commitId: '', + message: '', + branch: '', + status: BuildStatus.Null, + uri: '', + }; + + const dataBlank: BuildDetails = { + build: buildBlank, + author: '', + logUrl: '', + overviewUrl: '', + }; + + if (response.status > 200) { + return dataBlank; + } + + const data = await response.json(); + + const newData: WorkflowRun = data; + + dataBlank.author = newData.head_commit.author.name; + dataBlank.build.branch = newData.head_branch; + dataBlank.build.commitId = newData.head_commit.id; + dataBlank.build.message = newData.head_commit.message; + + // ### Feedback request ### + // TODO: I am not sure about this part. Look ugly. Maybe there is a better way of doing this. + if (newData.status === 'completed') { + dataBlank.build.status = BuildStatus.Success; + } else if (newData.status === 'in_progress') { + dataBlank.build.status = BuildStatus.Running; + } else if (newData.status === 'pending') { + dataBlank.build.status = BuildStatus.Pending; + } else if (newData.status === 'failure') { + dataBlank.build.status = BuildStatus.Failure; + } else { + dataBlank.build.status = BuildStatus.Null; + } + + dataBlank.build.uri = newData.url; + dataBlank.logUrl = newData.logs_url; + dataBlank.overviewUrl = newData.html_url; + + return dataBlank; + } +} diff --git a/plugins/github-actions/src/api/index.test.ts b/plugins/github-actions/src/api/index.test.ts new file mode 100644 index 0000000000..feff353115 --- /dev/null +++ b/plugins/github-actions/src/api/index.test.ts @@ -0,0 +1,44 @@ +/* + * Copyright 2020 Spotify AB + * + * 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 { GithubActionsClient } from './GithubActionsClient'; +import { BuildStatus } from './types'; + +describe('Github Actions API', () => { + let client: GithubActionsClient; + beforeEach(() => { + client = new GithubActionsClient(); + }); + describe('Mock client', () => { + it('gets a list of builds by a project id', async () => { + await expect(client.listBuilds()).resolves.toEqual([]); + }); + it('gets a build info by its id', async () => { + await expect(client.getBuild()).resolves.toEqual({ + build: { + commitId: 'TODO', + branch: 'TODO', + uri: 'TODO', + status: BuildStatus.Running, + message: 'TODO', + }, + author: 'TODO', + logUrl: 'TODO', + overviewUrl: 'TODO', + }); + }); + }); +}); diff --git a/plugins/github-actions/src/api/index.ts b/plugins/github-actions/src/api/index.ts new file mode 100644 index 0000000000..9383250bfb --- /dev/null +++ b/plugins/github-actions/src/api/index.ts @@ -0,0 +1,19 @@ +/* + * Copyright 2020 Spotify AB + * + * 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. + */ + +export * from './GithubActionsApi'; +export * from './GithubActionsClient'; +export * from './types'; diff --git a/plugins/github-actions/src/api/types.ts b/plugins/github-actions/src/api/types.ts new file mode 100644 index 0000000000..8a7b2ca548 --- /dev/null +++ b/plugins/github-actions/src/api/types.ts @@ -0,0 +1,224 @@ +/* + * Copyright 2020 Spotify AB + * + * 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. + */ + +export enum BuildStatus { + Null, + Success, + Failure, + Pending, + Running, +} + +export type Build = { + commitId: string; + message: string; + branch: string; + status: BuildStatus; + uri: string; +}; + +export type BuildDetails = { + build: Build; + author: string; + logUrl: string; + overviewUrl: string; +}; + +export interface Author { + name: string; + email: string; +} + +export interface Committer { + name: string; + email: string; +} + +export interface HeadCommit { + id: string; + tree_id: string; + message: string; + timestamp: Date; + author: Author; + committer: Committer; +} + +export interface Owner { + login: string; + id: number; + node_id: string; + avatar_url: string; + gravatar_id: string; + url: string; + html_url: string; + followers_url: string; + following_url: string; + gists_url: string; + starred_url: string; + subscriptions_url: string; + organizations_url: string; + repos_url: string; + events_url: string; + received_events_url: string; + type: string; + site_admin: boolean; +} + +export interface Repository { + id: number; + node_id: string; + name: string; + full_name: string; + private: boolean; + owner: Owner; + html_url: string; + description?: any; + fork: boolean; + url: string; + forks_url: string; + keys_url: string; + collaborators_url: string; + teams_url: string; + hooks_url: string; + issue_events_url: string; + events_url: string; + assignees_url: string; + branches_url: string; + tags_url: string; + blobs_url: string; + git_tags_url: string; + git_refs_url: string; + trees_url: string; + statuses_url: string; + languages_url: string; + stargazers_url: string; + contributors_url: string; + subscribers_url: string; + subscription_url: string; + commits_url: string; + git_commits_url: string; + comments_url: string; + issue_comment_url: string; + contents_url: string; + compare_url: string; + merges_url: string; + archive_url: string; + downloads_url: string; + issues_url: string; + pulls_url: string; + milestones_url: string; + notifications_url: string; + labels_url: string; + releases_url: string; + deployments_url: string; +} + +export interface Owner2 { + login: string; + id: number; + node_id: string; + avatar_url: string; + gravatar_id: string; + url: string; + html_url: string; + followers_url: string; + following_url: string; + gists_url: string; + starred_url: string; + subscriptions_url: string; + organizations_url: string; + repos_url: string; + events_url: string; + received_events_url: string; + type: string; + site_admin: boolean; +} + +export interface HeadRepository { + id: number; + node_id: string; + name: string; + full_name: string; + private: boolean; + owner: Owner2; + html_url: string; + description?: any; + fork: boolean; + url: string; + forks_url: string; + keys_url: string; + collaborators_url: string; + teams_url: string; + hooks_url: string; + issue_events_url: string; + events_url: string; + assignees_url: string; + branches_url: string; + tags_url: string; + blobs_url: string; + git_tags_url: string; + git_refs_url: string; + trees_url: string; + statuses_url: string; + languages_url: string; + stargazers_url: string; + contributors_url: string; + subscribers_url: string; + subscription_url: string; + commits_url: string; + git_commits_url: string; + comments_url: string; + issue_comment_url: string; + contents_url: string; + compare_url: string; + merges_url: string; + archive_url: string; + downloads_url: string; + issues_url: string; + pulls_url: string; + milestones_url: string; + notifications_url: string; + labels_url: string; + releases_url: string; + deployments_url: string; +} + +export interface WorkflowRun { + id: number; + node_id: string; + head_branch: string; + head_sha: string; + run_number: number; + event: string; + status: string; + conclusion: string; + workflow_id: number; + url: string; + html_url: string; + pull_requests: any[]; + created_at: Date; + updated_at: Date; + jobs_url: string; + logs_url: string; + check_suite_url: string; + artifacts_url: string; + cancel_url: string; + rerun_url: string; + workflow_url: string; + head_commit: HeadCommit; + repository: Repository; + head_repository: HeadRepository; +} diff --git a/plugins/github-actions/src/components/BuildDetailsPage/BuildDetailsPage.tsx b/plugins/github-actions/src/components/BuildDetailsPage/BuildDetailsPage.tsx index bb07e0d6aa..84e9332837 100644 --- a/plugins/github-actions/src/components/BuildDetailsPage/BuildDetailsPage.tsx +++ b/plugins/github-actions/src/components/BuildDetailsPage/BuildDetailsPage.tsx @@ -32,8 +32,9 @@ import { import React from 'react'; import { useParams } from 'react-router-dom'; import { useAsync } from 'react-use'; -import { BuildsClient } from '../../apis/builds'; import { BuildStatusIndicator } from '../BuildStatusIndicator'; +import { useApi, githubAuthApiRef } from '@backstage/core-api'; +import { githubActionsApiRef } from '../../api'; const useStyles = makeStyles(theme => ({ root: { @@ -48,12 +49,14 @@ const useStyles = makeStyles(theme => ({ }, })); -const client = BuildsClient.create(); - export const BuildDetailsPage = () => { + const api = useApi(githubActionsApiRef); + const githubApi = useApi(githubAuthApiRef); + const token = githubApi.getAccessToken('repo'); + const classes = useStyles(); const { buildUri } = useParams(); - const status = useAsync(() => client.getBuild(buildUri), [buildUri]); + const status = useAsync(() => api.getBuild(buildUri, token), [buildUri]); if (status.loading) { return ; diff --git a/plugins/github-actions/src/components/BuildInfoCard/BuildInfoCard.tsx b/plugins/github-actions/src/components/BuildInfoCard/BuildInfoCard.tsx index a04189debc..2e4cbb03bd 100644 --- a/plugins/github-actions/src/components/BuildInfoCard/BuildInfoCard.tsx +++ b/plugins/github-actions/src/components/BuildInfoCard/BuildInfoCard.tsx @@ -27,10 +27,9 @@ import { } from '@material-ui/core'; import React from 'react'; import { useAsync } from 'react-use'; -import { BuildsClient } from '../../apis/builds'; import { BuildStatusIndicator } from '../BuildStatusIndicator'; - -const client = BuildsClient.create(); +import { githubActionsApiRef } from '../../api'; +import { useApi } from '@backstage/core-api'; const useStyles = makeStyles(theme => ({ root: { @@ -43,7 +42,8 @@ const useStyles = makeStyles(theme => ({ export const BuildInfoCard = () => { const classes = useStyles(); - const status = useAsync(() => client.listBuilds('entity:spotify:backstage')); + const api = useApi(githubActionsApiRef); + const status = useAsync(() => api.listBuilds('entity:spotify:backstage')); let content: JSX.Element; diff --git a/plugins/github-actions/src/components/BuildListPage/BuildListPage.tsx b/plugins/github-actions/src/components/BuildListPage/BuildListPage.tsx index fc784108d4..ae979d0cc0 100644 --- a/plugins/github-actions/src/components/BuildListPage/BuildListPage.tsx +++ b/plugins/github-actions/src/components/BuildListPage/BuildListPage.tsx @@ -29,12 +29,12 @@ import { Tooltip, Typography, } from '@material-ui/core'; -import React from 'react'; +import React, { FC } from 'react'; import { useAsync } from 'react-use'; -import { BuildsClient } from '../../apis/builds'; import { BuildStatusIndicator } from '../BuildStatusIndicator'; - -const client = BuildsClient.create(); +import { githubActionsApiRef } from '../../api'; +import { useApi, githubAuthApiRef } from '@backstage/core-api'; +import { Entity } from '@backstage/catalog-model'; const LongText = ({ text, max }: { text: string; max: number }) => { if (text.length < max) { @@ -56,9 +56,13 @@ const useStyles = makeStyles(theme => ({ }, })); -const PageContents = () => { +const PageContents: FC<{ entity: Entity }> = ({ entity }) => { + const api = useApi(githubActionsApiRef); + const githubApi = useApi(githubAuthApiRef); + const token = githubApi.getAccessToken('repo'); + const { loading, error, value } = useAsync(() => - client.listBuilds('entity:spotify:backstage'), + api.listBuilds(entity, token), ); if (loading) { @@ -115,14 +119,14 @@ const PageContents = () => { ); }; -export const BuildListPage = () => { +export const BuildListPage: FC<{ entity: Entity }> = ({ entity }) => { const classes = useStyles(); return (
CI/CD Builds - +
); }; diff --git a/plugins/github-actions/src/components/BuildStatusIndicator/BuildStatusIndicator.tsx b/plugins/github-actions/src/components/BuildStatusIndicator/BuildStatusIndicator.tsx index 332a03d67a..1a198f4df2 100644 --- a/plugins/github-actions/src/components/BuildStatusIndicator/BuildStatusIndicator.tsx +++ b/plugins/github-actions/src/components/BuildStatusIndicator/BuildStatusIndicator.tsx @@ -21,7 +21,7 @@ import SuccessIcon from '@material-ui/icons/CheckCircle'; import FailureIcon from '@material-ui/icons/Error'; import UnknownIcon from '@material-ui/icons/Help'; import React from 'react'; -import { BuildStatus } from '../../apis/builds'; +import { BuildStatus } from '../../api/types'; type Props = { status?: BuildStatus; diff --git a/plugins/github-actions/src/index.ts b/plugins/github-actions/src/index.ts index 3a0a0fe2d3..d67bc6a864 100644 --- a/plugins/github-actions/src/index.ts +++ b/plugins/github-actions/src/index.ts @@ -15,3 +15,4 @@ */ export { plugin } from './plugin'; +export * from './api'; From 2fd5d2ffa50e606f8beaba5e51dfaf5db73b697f Mon Sep 17 00:00:00 2001 From: Nikita Nek Dudnik Date: Fri, 10 Jul 2020 16:58:59 +0200 Subject: [PATCH 3/4] feat: make it work Co-authored-by: Ivan Shmidt --- packages/app/src/apis.ts | 4 +- .../src/api/GithubActionsApi.ts | 12 ++- .../src/api/GithubActionsClient.ts | 73 +++++---------- .../src/api/MockGithubActionsClient.ts | 40 -------- plugins/github-actions/src/api/index.test.ts | 44 --------- .../BuildDetailsPage/BuildDetailsPage.tsx | 19 ++-- .../BuildInfoCard/BuildInfoCard.tsx | 91 ++++++++++--------- .../BuildListPage/BuildListPage.tsx | 29 +++--- plugins/github-actions/src/plugin.ts | 2 +- 9 files changed, 110 insertions(+), 204 deletions(-) delete mode 100644 plugins/github-actions/src/api/MockGithubActionsClient.ts delete mode 100644 plugins/github-actions/src/api/index.test.ts diff --git a/packages/app/src/apis.ts b/packages/app/src/apis.ts index df17886216..e80f031bf3 100644 --- a/packages/app/src/apis.ts +++ b/packages/app/src/apis.ts @@ -59,7 +59,7 @@ import { scaffolderApiRef, ScaffolderApi } from '@backstage/plugin-scaffolder'; import { rollbarApiRef, RollbarClient } from '@backstage/plugin-rollbar'; import { - MockGithubActionsClient, + GithubActionsClient, githubActionsApiRef, } from '@backstage/plugin-github-actions'; @@ -79,7 +79,7 @@ export const apis = (config: ConfigApi) => { builder.add(storageApiRef, WebStorage.create({ errorApi })); builder.add(circleCIApiRef, new CircleCIApi()); - builder.add(githubActionsApiRef, new MockGithubActionsClient()); + builder.add(githubActionsApiRef, new GithubActionsClient()); builder.add(featureFlagsApiRef, new FeatureFlags()); builder.add(lighthouseApiRef, new LighthouseRestApi('http://localhost:3003')); diff --git a/plugins/github-actions/src/api/GithubActionsApi.ts b/plugins/github-actions/src/api/GithubActionsApi.ts index c47cff7eda..dd75f34bf7 100644 --- a/plugins/github-actions/src/api/GithubActionsApi.ts +++ b/plugins/github-actions/src/api/GithubActionsApi.ts @@ -16,8 +16,6 @@ import { createApiRef } from '@backstage/core'; import { Build, BuildDetails } from './types'; -import { Entity } from '@backstage/catalog-model'; - export const githubActionsApiRef = createApiRef({ id: 'plugin.githubactions.service', @@ -25,6 +23,14 @@ export const githubActionsApiRef = createApiRef({ }); export type GithubActionsApi = { - listBuilds: (entity: Entity, token: Promise) => Promise; + listBuilds: ({ + owner, + repo, + token, + }: { + owner: string; + repo: string; + token: string; + }) => Promise; getBuild: (buildUri: string, token: Promise) => Promise; }; diff --git a/plugins/github-actions/src/api/GithubActionsClient.ts b/plugins/github-actions/src/api/GithubActionsClient.ts index 0c9a98e57c..93ace7fa38 100644 --- a/plugins/github-actions/src/api/GithubActionsClient.ts +++ b/plugins/github-actions/src/api/GithubActionsClient.ts @@ -16,26 +16,34 @@ import { GithubActionsApi } from './GithubActionsApi'; import { Build, BuildDetails, BuildStatus, WorkflowRun } from './types'; -import { Entity } from '@backstage/catalog-model'; + +const statusToBuildStatus: { [status: string]: BuildStatus } = { + success: BuildStatus.Success, + failure: BuildStatus.Failure, + pending: BuildStatus.Pending, + running: BuildStatus.Running, + in_progress: BuildStatus.Running, + completed: BuildStatus.Success, +}; + +const conclusionToStatus = (conslusion: string): BuildStatus => + statusToBuildStatus[conslusion] ?? BuildStatus.Null; export class GithubActionsClient implements GithubActionsApi { - async listBuilds(entity: Entity, token: Promise): Promise { - // ### Feedback request ### - // I asumed the following: (maybe not the best. Ideally this should come from the link to the component.yaml file) - // entity.metadata.namespace => org name - // entity.metadata.name => repo name - // entityUri -> entity:spotify:backstage - - let url: string; - if (entity.metadata.name !== '') { - url = `https://api.github.com/repos/${entity.metadata.namespace}/${entity.metadata.name}/runs`; - } else { - url = 'https://api.github.com/repos/spotify/backstage/actions/runs'; - } + async listBuilds({ + owner, + repo, + token, + }: { + owner: string; + repo: string; + token: string; + }): Promise { + const url = `https://api.github.com/repos/${owner}/${repo}/actions/runs`; const response = await fetch(url, { headers: new Headers({ - Authorization: `Bearer ${await token}`, + Authorization: `Bearer ${token}`, }), }); @@ -67,24 +75,7 @@ export class GithubActionsClient implements GithubActionsApi { }; transData.commitId = String(element.head_commit.id); transData.branch = element.head_branch; - - // ### Feedback request ### - // TODO: I am not sure about this part. Looks ugly. Maybe there is a better way of doing this. - if (element.conclusion === 'success') { - transData.status = BuildStatus.Success; - } else if (element.conclusion === 'failure') { - transData.status = BuildStatus.Failure; - } else if (element.conclusion === 'pending') { - transData.status = BuildStatus.Pending; - } else if (element.conclusion === 'running') { - transData.status = BuildStatus.Running; - } else { - if (element.status === 'in_progress') { - transData.status = BuildStatus.Running; - } else { - transData.status = BuildStatus.Null; - } - } + transData.status = conclusionToStatus(element.conclusion); transData.message = element.head_commit.message; transData.uri = element.url; endData[index] = transData; @@ -130,21 +121,7 @@ export class GithubActionsClient implements GithubActionsApi { dataBlank.build.branch = newData.head_branch; dataBlank.build.commitId = newData.head_commit.id; dataBlank.build.message = newData.head_commit.message; - - // ### Feedback request ### - // TODO: I am not sure about this part. Look ugly. Maybe there is a better way of doing this. - if (newData.status === 'completed') { - dataBlank.build.status = BuildStatus.Success; - } else if (newData.status === 'in_progress') { - dataBlank.build.status = BuildStatus.Running; - } else if (newData.status === 'pending') { - dataBlank.build.status = BuildStatus.Pending; - } else if (newData.status === 'failure') { - dataBlank.build.status = BuildStatus.Failure; - } else { - dataBlank.build.status = BuildStatus.Null; - } - + dataBlank.build.status = conclusionToStatus(newData.status); dataBlank.build.uri = newData.url; dataBlank.logUrl = newData.logs_url; dataBlank.overviewUrl = newData.html_url; diff --git a/plugins/github-actions/src/api/MockGithubActionsClient.ts b/plugins/github-actions/src/api/MockGithubActionsClient.ts deleted file mode 100644 index 89ecad3931..0000000000 --- a/plugins/github-actions/src/api/MockGithubActionsClient.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * 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 { GithubActionsApi } from './GithubActionsApi'; -import { Build, BuildDetails, BuildStatus } from './types'; - -export class MockGithubActionsClient implements GithubActionsApi { - async listBuilds(): Promise { - return []; - } - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - async getBuild(): Promise { - return { - build: { - commitId: 'TODO', - branch: 'TODO', - uri: 'TODO', - status: BuildStatus.Running, - message: 'TODO', - }, - author: 'TODO', - logUrl: 'TODO', - overviewUrl: 'TODO', - }; - } -} diff --git a/plugins/github-actions/src/api/index.test.ts b/plugins/github-actions/src/api/index.test.ts deleted file mode 100644 index feff353115..0000000000 --- a/plugins/github-actions/src/api/index.test.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2020 Spotify AB - * - * 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 { GithubActionsClient } from './GithubActionsClient'; -import { BuildStatus } from './types'; - -describe('Github Actions API', () => { - let client: GithubActionsClient; - beforeEach(() => { - client = new GithubActionsClient(); - }); - describe('Mock client', () => { - it('gets a list of builds by a project id', async () => { - await expect(client.listBuilds()).resolves.toEqual([]); - }); - it('gets a build info by its id', async () => { - await expect(client.getBuild()).resolves.toEqual({ - build: { - commitId: 'TODO', - branch: 'TODO', - uri: 'TODO', - status: BuildStatus.Running, - message: 'TODO', - }, - author: 'TODO', - logUrl: 'TODO', - overviewUrl: 'TODO', - }); - }); - }); -}); diff --git a/plugins/github-actions/src/components/BuildDetailsPage/BuildDetailsPage.tsx b/plugins/github-actions/src/components/BuildDetailsPage/BuildDetailsPage.tsx index 84e9332837..707c670f40 100644 --- a/plugins/github-actions/src/components/BuildDetailsPage/BuildDetailsPage.tsx +++ b/plugins/github-actions/src/components/BuildDetailsPage/BuildDetailsPage.tsx @@ -14,7 +14,6 @@ * limitations under the License. */ -import { Link } from '@backstage/core'; import { Button, ButtonGroup, @@ -30,10 +29,10 @@ import { Typography, } from '@material-ui/core'; import React from 'react'; -import { useParams } from 'react-router-dom'; +import { useLocation } from 'react-router-dom'; import { useAsync } from 'react-use'; import { BuildStatusIndicator } from '../BuildStatusIndicator'; -import { useApi, githubAuthApiRef } from '@backstage/core-api'; +import { Link, useApi, githubAuthApiRef } from '@backstage/core'; import { githubActionsApiRef } from '../../api'; const useStyles = makeStyles(theme => ({ @@ -55,8 +54,12 @@ export const BuildDetailsPage = () => { const token = githubApi.getAccessToken('repo'); const classes = useStyles(); - const { buildUri } = useParams(); - const status = useAsync(() => api.getBuild(buildUri, token), [buildUri]); + const location = useLocation(); + const status = useAsync( + () => + api.getBuild(decodeURIComponent(location.search.split('uri=')[1]), token), + [location.search], + ); if (status.loading) { return ; @@ -73,7 +76,7 @@ export const BuildDetailsPage = () => { return (
- + < @@ -127,12 +130,12 @@ export const BuildDetailsPage = () => { > {details?.overviewUrl && ( )} {details?.logUrl && ( )} diff --git a/plugins/github-actions/src/components/BuildInfoCard/BuildInfoCard.tsx b/plugins/github-actions/src/components/BuildInfoCard/BuildInfoCard.tsx index 2e4cbb03bd..cbbc1da339 100644 --- a/plugins/github-actions/src/components/BuildInfoCard/BuildInfoCard.tsx +++ b/plugins/github-actions/src/components/BuildInfoCard/BuildInfoCard.tsx @@ -14,7 +14,6 @@ * limitations under the License. */ -import { Link } from '@backstage/core'; import { LinearProgress, makeStyles, @@ -29,7 +28,7 @@ import React from 'react'; import { useAsync } from 'react-use'; import { BuildStatusIndicator } from '../BuildStatusIndicator'; import { githubActionsApiRef } from '../../api'; -import { useApi } from '@backstage/core-api'; +import { Link, useApi, githubAuthApiRef } from '@backstage/core'; const useStyles = makeStyles(theme => ({ root: { @@ -40,63 +39,69 @@ const useStyles = makeStyles(theme => ({ }, })); -export const BuildInfoCard = () => { - const classes = useStyles(); +const BuildInfoCardContent = () => { const api = useApi(githubActionsApiRef); - const status = useAsync(() => api.listBuilds('entity:spotify:backstage')); + const githubApi = useApi(githubAuthApiRef); - let content: JSX.Element; + const status = useAsync(async () => { + const token = await githubApi.getAccessToken('repo'); + return api.listBuilds({ owner: 'spotify', repo: 'backstage', token }); + }); if (status.loading) { - content = ; + return ; } else if (status.error) { - content = ( + return ( Failed to load builds, {status.error.message} ); - } else { - const [build] = - status.value?.filter(({ branch }) => branch === 'master') ?? []; - - content = ( - - - - - Message - - - - {build?.message} - - - - - - Commit ID - - {build?.commitId} - - - - Status - - - - - - -
- ); } + const [build] = + status.value?.filter(({ branch }) => branch === 'master') ?? []; + + return ( + + + + + Message + + + + {build?.message} + + + + + + Commit ID + + {build?.commitId} + + + + Status + + + + + + +
+ ); +}; + +export const BuildInfoCard = () => { + const classes = useStyles(); + return (
Master Build - {content} +
); }; diff --git a/plugins/github-actions/src/components/BuildListPage/BuildListPage.tsx b/plugins/github-actions/src/components/BuildListPage/BuildListPage.tsx index 85568c8c07..236bc182ef 100644 --- a/plugins/github-actions/src/components/BuildListPage/BuildListPage.tsx +++ b/plugins/github-actions/src/components/BuildListPage/BuildListPage.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Link } from '@backstage/core'; +import { Link, useApi, githubAuthApiRef } from '@backstage/core'; import { LinearProgress, makeStyles, @@ -29,13 +29,10 @@ import { Tooltip, Typography, } from '@material-ui/core'; -import React, { FC } from 'react'; +import React from 'react'; import { useAsync } from 'react-use'; import { BuildStatusIndicator } from '../BuildStatusIndicator'; -import { githubActionsApiRef } from '../../api'; -import { useApi, githubAuthApiRef } from '@backstage/core-api'; -import { Entity } from '@backstage/catalog-model'; - +import { githubActionsApiRef, Build } from '../../api'; const LongText = ({ text, max }: { text: string; max: number }) => { if (text.length < max) { @@ -57,14 +54,15 @@ const useStyles = makeStyles(theme => ({ }, })); -const PageContents: FC<{ entity: Entity }> = ({ entity }) => { +const PageContents = ({ owner, repo }: { owner: string; repo: string }) => { const api = useApi(githubActionsApiRef); const githubApi = useApi(githubAuthApiRef); - const token = githubApi.getAccessToken('repo'); - const { loading, error, value } = useAsync(() => - api.listBuilds(entity, token), - ); + const { loading, error, value } = useAsync(async () => { + const token = await githubApi.getAccessToken('repo'); + + return api.listBuilds({ owner, repo, token }); + }, [githubApi, owner, repo]); if (loading) { return ; @@ -90,7 +88,7 @@ const PageContents: FC<{ entity: Entity }> = ({ entity }) => { - {value!.map(build => ( + {value?.map((build: Build) => ( @@ -101,7 +99,7 @@ const PageContents: FC<{ entity: Entity }> = ({ entity }) => {
- + @@ -120,14 +118,15 @@ const PageContents: FC<{ entity: Entity }> = ({ entity }) => { ); }; -export const BuildListPage: FC<{ entity: Entity }> = ({ entity }) => { +export const BuildListPage = () => { const classes = useStyles(); + return (
CI/CD Builds - +
); }; diff --git a/plugins/github-actions/src/plugin.ts b/plugins/github-actions/src/plugin.ts index 638c8d2c8c..8897fe53db 100644 --- a/plugins/github-actions/src/plugin.ts +++ b/plugins/github-actions/src/plugin.ts @@ -24,7 +24,7 @@ export const rootRouteRef = createRouteRef({ title: 'GitHub Actions', }); export const buildRouteRef = createRouteRef({ - path: '/github-actions/builds/:buildUri', + path: '/github-actions/builds', title: 'GitHub Actions Build', }); From 423ff518f978ea60187be8f181ba343aa8b57efd Mon Sep 17 00:00:00 2001 From: Nikita Nek Dudnik Date: Mon, 13 Jul 2020 10:29:35 +0200 Subject: [PATCH 4/4] fix: correct response status usage --- plugins/github-actions/src/api/GithubActionsClient.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/github-actions/src/api/GithubActionsClient.ts b/plugins/github-actions/src/api/GithubActionsClient.ts index 93ace7fa38..58d7280c1f 100644 --- a/plugins/github-actions/src/api/GithubActionsClient.ts +++ b/plugins/github-actions/src/api/GithubActionsClient.ts @@ -47,11 +47,11 @@ export class GithubActionsClient implements GithubActionsApi { }), }); - if (response.status > 200) { + if (!response.ok) { return [ { commitId: 'Error', - message: 'ResponseCode > 200', + message: 'Response status is not OK', branch: 'Error', status: BuildStatus.Failure, uri: 'Error', @@ -109,7 +109,7 @@ export class GithubActionsClient implements GithubActionsApi { overviewUrl: '', }; - if (response.status > 200) { + if (!response.ok) { return dataBlank; }