From 2f25f54a4e9e113aa8389a455436a23b4cd61009 Mon Sep 17 00:00:00 2001 From: Rajiv Ranjan Singh Date: Mon, 7 Sep 2020 12:08:31 +0530 Subject: [PATCH 01/11] renamed the components --- .../{CircleProgress.tsx => CircleGauge.tsx} | 2 +- .../ProgressBars/{ProgressCard.tsx => GaugeCard.tsx} | 4 ++-- .../ProgressBars/HorizontalProgress.stories.tsx | 12 ++++++------ .../{HorizontalProgress.tsx => LinearGauge.tsx} | 4 ++-- .../components/ProgressBars/ProgressCard.stories.tsx | 2 +- packages/core/src/components/ProgressBars/index.ts | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) rename packages/core/src/components/ProgressBars/{CircleProgress.tsx => CircleGauge.tsx} (98%) rename packages/core/src/components/ProgressBars/{ProgressCard.tsx => GaugeCard.tsx} (93%) rename packages/core/src/components/ProgressBars/{HorizontalProgress.tsx => LinearGauge.tsx} (92%) diff --git a/packages/core/src/components/ProgressBars/CircleProgress.tsx b/packages/core/src/components/ProgressBars/CircleGauge.tsx similarity index 98% rename from packages/core/src/components/ProgressBars/CircleProgress.tsx rename to packages/core/src/components/ProgressBars/CircleGauge.tsx index 79a451b14e..eae65bbf57 100644 --- a/packages/core/src/components/ProgressBars/CircleProgress.tsx +++ b/packages/core/src/components/ProgressBars/CircleGauge.tsx @@ -77,7 +77,7 @@ export function getProgressColor( return palette.status.ok; } -export const CircleProgress: FC = props => { +export const CircleGauge: FC = props => { const classes = useStyles(props); const theme = useTheme(); const { value, fractional, inverse, unit, max } = { diff --git a/packages/core/src/components/ProgressBars/ProgressCard.tsx b/packages/core/src/components/ProgressBars/GaugeCard.tsx similarity index 93% rename from packages/core/src/components/ProgressBars/ProgressCard.tsx rename to packages/core/src/components/ProgressBars/GaugeCard.tsx index eef6312600..c9c623be40 100644 --- a/packages/core/src/components/ProgressBars/ProgressCard.tsx +++ b/packages/core/src/components/ProgressBars/GaugeCard.tsx @@ -18,7 +18,7 @@ import React, { FC } from 'react'; import { makeStyles } from '@material-ui/core'; import { InfoCard } from '../../layout/InfoCard'; import { BottomLinkProps } from '../../layout/BottomLink'; -import { CircleProgress } from './CircleProgress'; +import { CircleProgress } from './CircleGauge'; type Props = { title: string; @@ -36,7 +36,7 @@ const useStyles = makeStyles({ }, }); -export const ProgressCard: FC = props => { +export const GaugeCard: FC = props => { const classes = useStyles(props); const { title, subheader, progress, deepLink, variant } = props; diff --git a/packages/core/src/components/ProgressBars/HorizontalProgress.stories.tsx b/packages/core/src/components/ProgressBars/HorizontalProgress.stories.tsx index 6e8f4ed7fd..c4492986b6 100644 --- a/packages/core/src/components/ProgressBars/HorizontalProgress.stories.tsx +++ b/packages/core/src/components/ProgressBars/HorizontalProgress.stories.tsx @@ -15,29 +15,29 @@ */ import React from 'react'; -import { HorizontalProgress } from './HorizontalProgress'; +import { LinearGauge } from './LinearGauge'; const containerStyle = { width: 300 }; export default { - title: 'HorizontalProgress', - component: HorizontalProgress, + title: 'LinearGauge', + component: LinearGauge, }; export const Default = () => (
- +
); export const MediumProgress = () => (
- +
); export const LowProgress = () => (
- +
); diff --git a/packages/core/src/components/ProgressBars/HorizontalProgress.tsx b/packages/core/src/components/ProgressBars/LinearGauge.tsx similarity index 92% rename from packages/core/src/components/ProgressBars/HorizontalProgress.tsx rename to packages/core/src/components/ProgressBars/LinearGauge.tsx index 72bf1f34c3..5ea15fcbe4 100644 --- a/packages/core/src/components/ProgressBars/HorizontalProgress.tsx +++ b/packages/core/src/components/ProgressBars/LinearGauge.tsx @@ -19,7 +19,7 @@ import { Tooltip, useTheme } from '@material-ui/core'; // @ts-ignore import { Line } from 'rc-progress'; import { BackstageTheme } from '@backstage/theme'; -import { getProgressColor } from './CircleProgress'; +import { getProgressColor } from './CircleGauge'; type Props = { /** @@ -28,7 +28,7 @@ type Props = { value: number; }; -export const HorizontalProgress: FC = ({ value }) => { +export const LinearGauge: FC = ({ value }) => { const theme = useTheme(); if (isNaN(value)) { return null; diff --git a/packages/core/src/components/ProgressBars/ProgressCard.stories.tsx b/packages/core/src/components/ProgressBars/ProgressCard.stories.tsx index 62c9f3be6e..d39f88ac10 100644 --- a/packages/core/src/components/ProgressBars/ProgressCard.stories.tsx +++ b/packages/core/src/components/ProgressBars/ProgressCard.stories.tsx @@ -15,7 +15,7 @@ */ import React from 'react'; -import { ProgressCard } from './ProgressCard'; +import { ProgressCard } from './GaugeCard'; import { Grid } from '@material-ui/core'; const linkInfo = { title: 'Go to XYZ Location', link: '#' }; diff --git a/packages/core/src/components/ProgressBars/index.ts b/packages/core/src/components/ProgressBars/index.ts index c74e283ae6..41583704f5 100644 --- a/packages/core/src/components/ProgressBars/index.ts +++ b/packages/core/src/components/ProgressBars/index.ts @@ -14,6 +14,6 @@ * limitations under the License. */ -export { ProgressCard } from './ProgressCard'; -export { CircleProgress } from './CircleProgress'; -export { HorizontalProgress } from './HorizontalProgress'; +export { GaugeCard } from './GaugeCard'; +export { CircleGauge } from './CircleGauge'; +export { LinearGauge } from './LinearGauge'; From c95fd141aed45d42f6954fe6744a06fa9974cda7 Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Fri, 11 Sep 2020 16:59:15 +0100 Subject: [PATCH 02/11] Remove hardcoded isOrg --- .../software-templates/installation.md | 3 -- .../techdocs/creating-and-publishing.md | 5 ---- .../__mocks__/@octokit/rest/index.ts | 3 ++ .../scaffolder/stages/publish/github.test.ts | 28 +++++++++++++++++-- .../src/scaffolder/stages/publish/github.ts | 9 ++++-- plugins/scaffolder/src/api.ts | 3 +- 6 files changed, 35 insertions(+), 16 deletions(-) diff --git a/docs/features/software-templates/installation.md b/docs/features/software-templates/installation.md index 50c2fd303c..eea78e3571 100644 --- a/docs/features/software-templates/installation.md +++ b/docs/features/software-templates/installation.md @@ -177,9 +177,6 @@ docs on creating private GitHub access tokens is available Note that the need for private GitHub access tokens will be replaced with GitHub Apps integration further down the line. -> **Right now it is only possible to scaffold repositories inside GitHub -> organizations, and not under personal accounts.** - The GitHub access token is passed along using the `GITHUB_ACCESS_TOKEN` environment variable. diff --git a/docs/features/techdocs/creating-and-publishing.md b/docs/features/techdocs/creating-and-publishing.md index 0dfa40f819..9866246c5f 100644 --- a/docs/features/techdocs/creating-and-publishing.md +++ b/docs/features/techdocs/creating-and-publishing.md @@ -30,11 +30,6 @@ the documentation template. Create an entity from the documentation template and you will get the needed setup for free. -!!! warning Currently the Backstage Software Templates are limited to create -repositories inside GitHub organizations. You also need to generate an personal -access token and use as an environment variable. Read more about this -[here](../software-templates/installation.md#runtime-dependencies). - ### Manually add documentation setup to already existing repository Prerequisities: diff --git a/plugins/scaffolder-backend/src/scaffolder/__mocks__/@octokit/rest/index.ts b/plugins/scaffolder-backend/src/scaffolder/__mocks__/@octokit/rest/index.ts index 85bed3a223..a302bc5931 100644 --- a/plugins/scaffolder-backend/src/scaffolder/__mocks__/@octokit/rest/index.ts +++ b/plugins/scaffolder-backend/src/scaffolder/__mocks__/@octokit/rest/index.ts @@ -19,6 +19,9 @@ export const mockGithubClient = { createInOrg: jest.fn(), createForAuthenticatedUser: jest.fn(), }, + users: { + getByUsername: jest.fn(), + }, }; export class Octokit { diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.test.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.test.ts index 93493ab2cc..718c01438c 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.test.ts @@ -19,11 +19,18 @@ jest.mock('nodegit'); import { Octokit } from '@octokit/rest'; import * as NodeGit from 'nodegit'; -import { OctokitResponse, ReposCreateInOrgResponseData } from '@octokit/types'; +import { + OctokitResponse, + ReposCreateInOrgResponseData, + UsersGetByUsernameResponseData, +} from '@octokit/types'; import { GithubPublisher } from './github'; const { mockGithubClient } = require('@octokit/rest') as { - mockGithubClient: { repos: jest.Mocked }; + mockGithubClient: { + repos: jest.Mocked; + users: jest.Mocked; + }; }; const { @@ -59,10 +66,14 @@ describe('GitHub Publisher', () => { clone_url: 'mockclone', }, } as OctokitResponse); + mockGithubClient.users.getByUsername.mockResolvedValue({ + data: { + type: 'Organization', + }, + } as OctokitResponse); await publisher.publish({ values: { - isOrg: true, storePath: 'blam/test', owner: 'bob', }, @@ -81,6 +92,11 @@ describe('GitHub Publisher', () => { clone_url: 'mockclone', }, } as OctokitResponse); + mockGithubClient.users.getByUsername.mockResolvedValue({ + data: { + type: 'User', + }, + } as OctokitResponse); await publisher.publish({ values: { @@ -112,6 +128,12 @@ describe('GitHub Publisher', () => { clone_url: 'mockclone', }, } as OctokitResponse); + mockGithubClient.users.getByUsername.mockResolvedValue({ + data: { + type: 'Organization', + }, + } as OctokitResponse); + it('should call init on the repo with the directory', async () => { await publisher.publish({ values, diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts index 5fd64d69fc..f3306e3662 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts @@ -45,9 +45,12 @@ export class GithubPublisher implements PublisherBase { ) { const [owner, name] = values.storePath.split('/'); - const repoCreationPromise = values.isOrg - ? this.client.repos.createInOrg({ name, org: owner }) - : this.client.repos.createForAuthenticatedUser({ name }); + const user = await this.client.users.getByUsername({ username: owner }); + + const repoCreationPromise = + user.data.type === 'Organization' + ? this.client.repos.createInOrg({ name, org: owner }) + : this.client.repos.createForAuthenticatedUser({ name }); const { data } = await repoCreationPromise; diff --git a/plugins/scaffolder/src/api.ts b/plugins/scaffolder/src/api.ts index cc69ed7627..f58c8e68d1 100644 --- a/plugins/scaffolder/src/api.ts +++ b/plugins/scaffolder/src/api.ts @@ -46,8 +46,7 @@ export class ScaffolderApi { headers: { 'Content-Type': 'application/json', }, - // TODO(shmidt-i): when repo picker is implemented, take isOrg from it - body: JSON.stringify({ template, values: { ...values, isOrg: true } }), + body: JSON.stringify({ template, values: { ...values } }), }); if (response.status !== 201) { From 57ae0825d80c1688630abd61b7a070e99f2ce8bd Mon Sep 17 00:00:00 2001 From: David Tuite Date: Tue, 15 Sep 2020 14:00:23 +0100 Subject: [PATCH 03/11] Fix scaffolder catalog link (#2471) This was incorrectly linking to a relative path which ended up being something like `/create/docs-template/Component/my-component`. --- .../scaffolder/src/components/JobStatusModal/JobStatusModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/scaffolder/src/components/JobStatusModal/JobStatusModal.tsx b/plugins/scaffolder/src/components/JobStatusModal/JobStatusModal.tsx index 102e93f91d..87b70a9553 100644 --- a/plugins/scaffolder/src/components/JobStatusModal/JobStatusModal.tsx +++ b/plugins/scaffolder/src/components/JobStatusModal/JobStatusModal.tsx @@ -72,7 +72,7 @@ export const JobStatusModal = ({ {entity && (