diff --git a/plugins/circleci/src/api/index.ts b/plugins/circleci/src/api/index.ts index aadb2b144d..34eaae4b35 100644 --- a/plugins/circleci/src/api/index.ts +++ b/plugins/circleci/src/api/index.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { CircleCI, GitType, CircleCIOptions, GitInfo } from 'circleci-api'; +import { CircleCI, GitType, CircleCIOptions, GitInfo, getBuildSummaries } from 'circleci-api'; import { ApiRef } from '@backstage/core'; -import { default } from '../../../../packages/core/src/components/Status/Status.stories'; +//import { default } from '../../../../packages/core/src/components/Status/Status.stories'; const defaultVcsOptions: GitInfo = { type: GitType.GITHUB, // default: github @@ -37,16 +37,14 @@ const options: Partial = { export class CircleCIApi { api: null | CircleCI = null; + token: string = ''; constuctor() {} - async authenticate({token, owner, repo}: {token: string, owner: string, repo: string}) { + async authenticate(token: string) { try { - if (token === '' || owner === '' || repo === '') return Promise.reject(); - this.api = new CircleCI({ ...options, token, vcs: { - type: GitType.GITHUB, // default: github - owner, - repo, - }}); + if (token === '') return Promise.reject(); + this.api = new CircleCI({ ...options, token}); // await this.api.me(); + this.token = token; return Promise.resolve(); } catch (e) { this.api = null; @@ -56,9 +54,10 @@ export class CircleCIApi { async cantAuth() { return Promise.reject("Can't auth"); } - async getBuilds() { + async getBuilds({repo, owner}: {repo: string, owner: string}) { if (!this.api) return this.cantAuth(); - return this.api.builds(); + if (owner === '' || repo === '') return Promise.reject(); + return getBuildSummaries(this.token, {vcs: {...defaultVcsOptions, owner, repo}}); } } diff --git a/plugins/circleci/src/components/CITable/CITable.tsx b/plugins/circleci/src/components/CITable/CITable.tsx index 7da9709f68..a6b607a216 100644 --- a/plugins/circleci/src/components/CITable/CITable.tsx +++ b/plugins/circleci/src/components/CITable/CITable.tsx @@ -7,7 +7,6 @@ import TableCell from '@material-ui/core/TableCell'; import TableContainer from '@material-ui/core/TableContainer'; import TableHead from '@material-ui/core/TableHead'; import TableRow from '@material-ui/core/TableRow'; - const useStyles = makeStyles({ table: { minWidth: 650, diff --git a/plugins/circleci/src/components/CircleCIFetch/CirleCIFetch.tsx b/plugins/circleci/src/components/CircleCIFetch/CirleCIFetch.tsx index 50ca39b3a6..855fea6243 100644 --- a/plugins/circleci/src/components/CircleCIFetch/CirleCIFetch.tsx +++ b/plugins/circleci/src/components/CircleCIFetch/CirleCIFetch.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import React, { FC } from 'react'; +import React, { FC, useState } from 'react'; // import Alert from '@material-ui/lab/Alert'; // import { Progress } from '@backstage/core'; @@ -24,6 +24,7 @@ import { BuildSummary } from 'circleci-api'; import { CITable, CITableBuildInfo } from '../CITable'; import { circleCIApiRef } from 'api'; import { useApi } from '@backstage/core'; +import { ProjectInput } from 'components/ProjectInput/ProjectInput'; // "lifecycle" : "finished", // :queued, :scheduled, :not_run, :not_running, :running or :finished // "outcome" : "failed", // :canceled, :infrastructure_fail, :timedout, :failed, :no_tests or :success @@ -73,19 +74,24 @@ const transform = (buildsData: BuildSummary[]): CITableBuildInfo[] => { }); }; + export const CircleCIFetch: FC<{}> = () => { + const [vcsOptions, setVcsOptions] = useState({owner: '', repo: ''}); const [builds, setBuilds] = React.useState([]); const api = useApi(circleCIApiRef); React.useEffect(() => { const intervalId = setInterval(() => { if (!api.api) return; - api.getBuilds().then(setBuilds); + api.getBuilds(vcsOptions).then(setBuilds); }, 1500); return () => clearInterval(intervalId); }, []); - if (!api.api) return
Not authenticated
; const transformedBuilds = transform(builds || []); - return ; + return <> + { + setVcsOptions(info); + api.getBuilds(info).then(setBuilds)}}/> + {!api.api ?
Not authenticated
: }; }; diff --git a/plugins/circleci/src/components/LoginCard/LoginCard.tsx b/plugins/circleci/src/components/LoginCard/LoginCard.tsx index e50ca4bc0b..23ff5ee1d1 100644 --- a/plugins/circleci/src/components/LoginCard/LoginCard.tsx +++ b/plugins/circleci/src/components/LoginCard/LoginCard.tsx @@ -33,14 +33,12 @@ const useSessionStorage = (key: string): [string, (value: string) => void] => { }; export const LoginCard = () => { const [token, setToken] = useSessionStorage(circleCIApiRef.id + '_token'); - const [owner, setOwner] = useSessionStorage(circleCIApiRef.id + '_owner'); - const [repo, setRepo] = useSessionStorage(circleCIApiRef.id + '_repo'); const api = useApi(circleCIApiRef); React.useEffect(() => { if (token && token !== '') { - api.authenticate({token, owner, repo}); + api.authenticate(token); } }, []); return ( @@ -58,28 +56,12 @@ export const LoginCard = () => { onChange={e => setToken(e.target.value)} /> - - setOwner(e.target.value)} - /> - - - setRepo(e.target.value)} - /> - diff --git a/plugins/circleci/src/components/ProjectInput/ProjectInput.tsx b/plugins/circleci/src/components/ProjectInput/ProjectInput.tsx new file mode 100644 index 0000000000..79ca532f70 --- /dev/null +++ b/plugins/circleci/src/components/ProjectInput/ProjectInput.tsx @@ -0,0 +1,42 @@ +import { useState, FC } from "react"; +import { List, ListItem, TextField, Button } from "@material-ui/core"; +import React from "react"; + +export const ProjectInput:FC<{ + setGitInfo: (info: {owner: string, repo: string}) => void + }> = ({setGitInfo}) => { + + const [owner, setOwner] = useState(''); + const [repo, setRepo] = useState(''); + + return ( + + + setOwner(e.target.value)} + /> + + + setRepo(e.target.value)} + /> + + + + + + ); +}; \ No newline at end of file