+ + Git + + : The source control system where releases reside in a practical sense. Read more about + + + Git releases + + . +
++ + Release Candidate + + : A Git + + prerelease + + intended primarily for internal testing +
++ + Release Version + + : A Git release intended for end users +
++ Select an owner (org or user) +
, ++ Custom queries can be made via the query param + + + owner + +
, + ] + `); + }); + + it('should handle errors', async () => { + (mockApiClient.getOwners as jest.Mock).mockImplementationOnce(async () => { + throw new Error('Kaboom'); + }); + + const { getByTestId } = render(+ Encountered an error ( + Kaboom + ) +
+ `); + }); +}); diff --git a/plugins/git-release-manager/src/features/RepoDetailsForm/Owner.tsx b/plugins/git-release-manager/src/features/RepoDetailsForm/Owner.tsx new file mode 100644 index 0000000000..5d6ea4f75d --- /dev/null +++ b/plugins/git-release-manager/src/features/RepoDetailsForm/Owner.tsx @@ -0,0 +1,125 @@ +/* + * Copyright 2021 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 React from 'react'; +import { useNavigate } from 'react-router'; +import { useAsync } from 'react-use'; +import { + FormControl, + FormHelperText, + InputLabel, + MenuItem, + Select, + Box, +} from '@material-ui/core'; +import { Progress, useApi } from '@backstage/core'; + +import { gitReleaseManagerApiRef } from '../../api/serviceApiRef'; +import { TEST_IDS } from '../../test-helpers/test-ids'; +import { useFormClasses } from './styles'; +import { useProjectContext } from '../../contexts/ProjectContext'; +import { useQueryHandler } from '../../hooks/useQueryHandler'; +import { useUserContext } from '../../contexts/UserContext'; + +export function Owner() { + const pluginApiClient = useApi(gitReleaseManagerApiRef); + const { project } = useProjectContext(); + const { user } = useUserContext(); + const formClasses = useFormClasses(); + const navigate = useNavigate(); + const { getQueryParamsWithUpdates } = useQueryHandler(); + + const { loading, error, value } = useAsync(() => pluginApiClient.getOwners()); + const owners = value?.owners ?? []; + const customOwnerFromUrl = !owners + .concat(['', user.username]) + .includes(project.owner); + + return ( ++ Select a repository +
, ++ Custom queries can be made via the query param + + + repo + +
, + ] + `); + }); + + it('should handle errors', async () => { + (mockApiClient.getRepositories as jest.Mock).mockImplementationOnce( + async () => { + throw new Error('Kaboom'); + }, + ); + + const { getByTestId } = render(+ Encountered an error ( + Kaboom + ") +
+ `); + }); +}); diff --git a/plugins/git-release-manager/src/features/RepoDetailsForm/Repo.tsx b/plugins/git-release-manager/src/features/RepoDetailsForm/Repo.tsx new file mode 100644 index 0000000000..bc713709b1 --- /dev/null +++ b/plugins/git-release-manager/src/features/RepoDetailsForm/Repo.tsx @@ -0,0 +1,122 @@ +/* + * Copyright 2021 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 React from 'react'; +import { useAsync } from 'react-use'; +import { useNavigate } from 'react-router'; +import { + FormControl, + FormHelperText, + InputLabel, + MenuItem, + Select, + Box, +} from '@material-ui/core'; +import { Progress, useApi } from '@backstage/core'; + +import { gitReleaseManagerApiRef } from '../../api/serviceApiRef'; +import { TEST_IDS } from '../../test-helpers/test-ids'; +import { useFormClasses } from './styles'; +import { useProjectContext } from '../../contexts/ProjectContext'; +import { useQueryHandler } from '../../hooks/useQueryHandler'; + +export function Repo() { + const pluginApiClient = useApi(gitReleaseManagerApiRef); + const { project } = useProjectContext(); + const navigate = useNavigate(); + const formClasses = useFormClasses(); + const { getQueryParamsWithUpdates } = useQueryHandler(); + + const { loading, error, value } = useAsync( + async () => pluginApiClient.getRepositories({ owner: project.owner }), + [project.owner], + ); + + if (project.owner.length === 0) { + return null; + } + + const repositories = value?.repositories ?? []; + const customRepoFromUrl = !repositories.concat(['']).includes(project.repo); + + return ( +