From 65e6c45410bf31cfbad470e398c1bb7a244f13da Mon Sep 17 00:00:00 2001 From: jrusso1020 Date: Sat, 15 May 2021 10:21:34 -0600 Subject: [PATCH] Remove circular dependencies In reference to issue #5563 this does the initial work to remove all the circular dependencies that we have encountered while building backstage using bazel. The next step will be to implement a method to catch these circular dependencies before they get merged in Signed-off-by: jrusso1020 --- .changeset/little-birds-smile.md | 15 +++++ packages/backend-common/api-report.md | 8 +-- .../src/reading/AzureUrlReader.ts | 4 +- .../src/reading/BitbucketUrlReader.ts | 4 +- .../src/reading/GithubUrlReader.ts | 4 +- .../src/reading/GitlabUrlReader.ts | 4 +- .../reading/tree/ReadTreeResponseFactory.ts | 21 ++---- packages/backend-common/src/reading/types.ts | 21 +++++- .../src/apis/definitions/OAuthRequestApi.ts | 2 +- .../AlertApi/AlertApiForwarder.ts | 2 +- .../AppThemeApi/AppThemeSelector.ts | 2 +- .../ErrorApi/ErrorApiForwarder.ts | 2 +- .../OAuthRequestApi/OAuthPendingRequests.ts | 2 +- .../OAuthRequestApi/OAuthRequestManager.ts | 2 +- packages/core-api/src/app/types.ts | 7 +- .../lib/AuthConnector/DefaultAuthConnector.ts | 2 +- .../AuthSessionManager/SessionStateTracker.ts | 2 +- .../src/lib/AuthSessionManager/types.ts | 2 +- packages/core-api/src/routing/RouteRef.ts | 2 +- packages/core-api/src/routing/types.ts | 2 +- .../SimpleStepper/SimpleStepperFooter.tsx | 2 +- .../SimpleStepper/SimpleStepperStep.tsx | 25 +------ .../src/components/SimpleStepper/types.ts | 41 ++++++++++++ .../components/TabbedLayout/RoutedTabs.tsx | 3 +- packages/integration/src/ScmIntegrations.ts | 7 +- packages/integration/src/index.ts | 7 +- packages/integration/src/registry.ts | 67 +++++++++++++++++++ packages/integration/src/types.ts | 50 -------------- .../src/stages/prepare/preparers.ts | 4 +- plugins/api-docs/src/config.ts | 2 +- .../src/lib/oauth/OAuthAdapter.ts | 2 +- .../src/providers/google/provider.ts | 2 +- .../src/providers/saml/provider.ts | 2 +- plugins/auth-backend/src/providers/types.ts | 2 +- .../cloudbuild/src/components/Cards/Cards.tsx | 4 +- plugins/cloudbuild/src/components/Router.tsx | 2 +- .../WorkflowRunsTable/WorkflowRunsTable.tsx | 16 +---- .../src/components/WorkflowRunsTable/index.ts | 1 - .../src/components/useWorkflowRuns.ts | 17 ++++- plugins/cloudbuild/src/plugin.ts | 12 +--- plugins/cloudbuild/src/routes.ts | 26 +++++++ .../src/components/Cards/Cards.tsx | 4 +- .../github-actions/src/components/Router.tsx | 2 +- .../useWorkflowRunsDetails.ts | 2 +- .../WorkflowRunsTable/WorkflowRunsTable.tsx | 22 +----- .../src/components/WorkflowRunsTable/index.ts | 1 - .../src/components/useWorkflowRuns.ts | 19 +++++- plugins/github-actions/src/plugin.ts | 14 +--- plugins/github-actions/src/routes.ts | 29 ++++++++ .../src/scaffolder/stages/index.ts | 2 - plugins/techdocs/src/Router.tsx | 2 +- .../src/home/components/DocsCardGrid.tsx | 2 +- .../src/home/components/DocsTable.tsx | 2 +- plugins/techdocs/src/plugin.ts | 21 ++---- .../techdocs/src/reader/components/Reader.tsx | 3 +- .../components/TechDocsPageHeader.test.tsx | 2 +- .../reader/components/TechDocsPageHeader.tsx | 2 +- .../src/reader/transformers/addBaseUrl.ts | 2 +- .../transformers/addLinkClickListener.ts | 2 +- .../src/reader/transformers/index.test.ts | 2 +- .../techdocs/src/reader/transformers/index.ts | 28 +------- .../src/reader/transformers/injectCss.ts | 2 +- .../src/reader/transformers/onCssReady.ts | 2 +- .../reader/transformers/removeMkdocsHeader.ts | 2 +- .../reader/transformers/rewriteDocLinks.ts | 2 +- .../reader/transformers/sanitizeDOM/index.ts | 2 +- .../transformers/simplifyMkdocsFooter.ts | 2 +- .../src/reader/transformers/transformer.ts | 38 +++++++++++ plugins/techdocs/src/routes.ts | 32 +++++++++ plugins/techdocs/src/test-utils/shadowDom.ts | 2 +- 70 files changed, 384 insertions(+), 267 deletions(-) create mode 100644 .changeset/little-birds-smile.md create mode 100644 packages/core/src/components/SimpleStepper/types.ts create mode 100644 packages/integration/src/registry.ts create mode 100644 plugins/cloudbuild/src/routes.ts create mode 100644 plugins/github-actions/src/routes.ts create mode 100644 plugins/techdocs/src/reader/transformers/transformer.ts create mode 100644 plugins/techdocs/src/routes.ts diff --git a/.changeset/little-birds-smile.md b/.changeset/little-birds-smile.md new file mode 100644 index 0000000000..cce9efe450 --- /dev/null +++ b/.changeset/little-birds-smile.md @@ -0,0 +1,15 @@ +--- +'@backstage/backend-common': patch +'@backstage/core': patch +'@backstage/core-api': patch +'@backstage/integration': patch +'@backstage/techdocs-common': patch +'@backstage/plugin-api-docs': patch +'@backstage/plugin-auth-backend': patch +'@backstage/plugin-cloudbuild': patch +'@backstage/plugin-github-actions': patch +'@backstage/plugin-scaffolder-backend': patch +'@backstage/plugin-techdocs': patch +--- + +Remove circular dependencies diff --git a/packages/backend-common/api-report.md b/packages/backend-common/api-report.md index 23e22fe34b..1b9b232605 100644 --- a/packages/backend-common/api-report.md +++ b/packages/backend-common/api-report.md @@ -32,7 +32,7 @@ import { Writable } from 'stream'; // @public (undocumented) export class AzureUrlReader implements UrlReader { constructor(integration: AzureIntegration, deps: { - treeResponseFactory: ReadTreeResponseFactory; + treeResponseFactory: IReadTreeResponseFactory; }); // (undocumented) static factory: ReaderFactory; @@ -49,7 +49,7 @@ export class AzureUrlReader implements UrlReader { // @public export class BitbucketUrlReader implements UrlReader { constructor(integration: BitbucketIntegration, deps: { - treeResponseFactory: ReadTreeResponseFactory; + treeResponseFactory: IReadTreeResponseFactory; }); // (undocumented) static factory: ReaderFactory; @@ -214,7 +214,7 @@ export class Git { // @public export class GithubUrlReader implements UrlReader { constructor(integration: GitHubIntegration, deps: { - treeResponseFactory: ReadTreeResponseFactory; + treeResponseFactory: IReadTreeResponseFactory; credentialsProvider: GithubCredentialsProvider; }); // (undocumented) @@ -232,7 +232,7 @@ export class GithubUrlReader implements UrlReader { // @public (undocumented) export class GitlabUrlReader implements UrlReader { constructor(integration: GitLabIntegration, deps: { - treeResponseFactory: ReadTreeResponseFactory; + treeResponseFactory: IReadTreeResponseFactory; }); // (undocumented) static factory: ReaderFactory; diff --git a/packages/backend-common/src/reading/AzureUrlReader.ts b/packages/backend-common/src/reading/AzureUrlReader.ts index 16e7628ec8..0f7e3e8bd9 100644 --- a/packages/backend-common/src/reading/AzureUrlReader.ts +++ b/packages/backend-common/src/reading/AzureUrlReader.ts @@ -27,9 +27,9 @@ import parseGitUrl from 'git-url-parse'; import { Minimatch } from 'minimatch'; import { Readable } from 'stream'; import { NotFoundError, NotModifiedError } from '@backstage/errors'; -import { ReadTreeResponseFactory } from './tree'; import { stripFirstDirectoryFromPath } from './tree/util'; import { + IReadTreeResponseFactory, ReaderFactory, ReadTreeOptions, ReadTreeResponse, @@ -50,7 +50,7 @@ export class AzureUrlReader implements UrlReader { constructor( private readonly integration: AzureIntegration, - private readonly deps: { treeResponseFactory: ReadTreeResponseFactory }, + private readonly deps: { treeResponseFactory: IReadTreeResponseFactory }, ) {} async read(url: string): Promise { diff --git a/packages/backend-common/src/reading/BitbucketUrlReader.ts b/packages/backend-common/src/reading/BitbucketUrlReader.ts index f102be7283..452a7bf778 100644 --- a/packages/backend-common/src/reading/BitbucketUrlReader.ts +++ b/packages/backend-common/src/reading/BitbucketUrlReader.ts @@ -27,9 +27,9 @@ import parseGitUrl from 'git-url-parse'; import { Minimatch } from 'minimatch'; import { Readable } from 'stream'; import { NotFoundError, NotModifiedError } from '@backstage/errors'; -import { ReadTreeResponseFactory } from './tree'; import { stripFirstDirectoryFromPath } from './tree/util'; import { + IReadTreeResponseFactory, ReaderFactory, ReadTreeOptions, ReadTreeResponse, @@ -56,7 +56,7 @@ export class BitbucketUrlReader implements UrlReader { constructor( private readonly integration: BitbucketIntegration, - private readonly deps: { treeResponseFactory: ReadTreeResponseFactory }, + private readonly deps: { treeResponseFactory: IReadTreeResponseFactory }, ) { const { host, diff --git a/packages/backend-common/src/reading/GithubUrlReader.ts b/packages/backend-common/src/reading/GithubUrlReader.ts index 77e33cbd54..0544ec335b 100644 --- a/packages/backend-common/src/reading/GithubUrlReader.ts +++ b/packages/backend-common/src/reading/GithubUrlReader.ts @@ -26,8 +26,8 @@ import parseGitUrl from 'git-url-parse'; import { Minimatch } from 'minimatch'; import { Readable } from 'stream'; import { NotFoundError, NotModifiedError } from '@backstage/errors'; -import { ReadTreeResponseFactory } from './tree'; import { + IReadTreeResponseFactory, ReaderFactory, ReadTreeOptions, ReadTreeResponse, @@ -65,7 +65,7 @@ export class GithubUrlReader implements UrlReader { constructor( private readonly integration: GitHubIntegration, private readonly deps: { - treeResponseFactory: ReadTreeResponseFactory; + treeResponseFactory: IReadTreeResponseFactory; credentialsProvider: GithubCredentialsProvider; }, ) { diff --git a/packages/backend-common/src/reading/GitlabUrlReader.ts b/packages/backend-common/src/reading/GitlabUrlReader.ts index c93103b2da..1a34893880 100644 --- a/packages/backend-common/src/reading/GitlabUrlReader.ts +++ b/packages/backend-common/src/reading/GitlabUrlReader.ts @@ -25,9 +25,9 @@ import parseGitUrl from 'git-url-parse'; import { Minimatch } from 'minimatch'; import { Readable } from 'stream'; import { NotFoundError, NotModifiedError } from '@backstage/errors'; -import { ReadTreeResponseFactory } from './tree'; import { stripFirstDirectoryFromPath } from './tree/util'; import { + IReadTreeResponseFactory, ReaderFactory, ReadTreeOptions, ReadTreeResponse, @@ -50,7 +50,7 @@ export class GitlabUrlReader implements UrlReader { constructor( private readonly integration: GitLabIntegration, - private readonly deps: { treeResponseFactory: ReadTreeResponseFactory }, + private readonly deps: { treeResponseFactory: IReadTreeResponseFactory }, ) {} async read(url: string): Promise { diff --git a/packages/backend-common/src/reading/tree/ReadTreeResponseFactory.ts b/packages/backend-common/src/reading/tree/ReadTreeResponseFactory.ts index 05ecdb0fc3..5fe54c965b 100644 --- a/packages/backend-common/src/reading/tree/ReadTreeResponseFactory.ts +++ b/packages/backend-common/src/reading/tree/ReadTreeResponseFactory.ts @@ -15,25 +15,16 @@ */ import os from 'os'; -import { Readable } from 'stream'; import { Config } from '@backstage/config'; -import { ReadTreeResponse } from '../types'; +import { + ReadTreeResponse, + FromArchiveOptions, + IReadTreeResponseFactory, +} from '../types'; import { TarArchiveResponse } from './TarArchiveResponse'; import { ZipArchiveResponse } from './ZipArchiveResponse'; -type FromArchiveOptions = { - // A binary stream of a tar archive. - stream: Readable; - // If unset, the files at the root of the tree will be read. - // subpath must not contain the name of the top level directory. - subpath?: string; - // etag of the blob - etag: string; - // Filter passed on from the ReadTreeOptions - filter?: (path: string) => boolean; -}; - -export class ReadTreeResponseFactory { +export class ReadTreeResponseFactory implements IReadTreeResponseFactory { static create(options: { config: Config }): ReadTreeResponseFactory { return new ReadTreeResponseFactory( options.config.getOptionalString('backend.workingDirectory') ?? diff --git a/packages/backend-common/src/reading/types.ts b/packages/backend-common/src/reading/types.ts index 4caa76841a..779f56dc32 100644 --- a/packages/backend-common/src/reading/types.ts +++ b/packages/backend-common/src/reading/types.ts @@ -14,9 +14,9 @@ * limitations under the License. */ +import { Readable } from 'stream'; import { Logger } from 'winston'; import { Config } from '@backstage/config'; -import { ReadTreeResponseFactory } from './tree'; /** * A generic interface for fetching plain data from URLs. @@ -39,7 +39,7 @@ export type UrlReaderPredicateTuple = { export type ReaderFactory = (options: { config: Config; logger: Logger; - treeResponseFactory: ReadTreeResponseFactory; + treeResponseFactory: IReadTreeResponseFactory; }) => UrlReaderPredicateTuple[]; /** @@ -105,6 +105,23 @@ export type ReadTreeResponseFile = { content(): Promise; }; +export type FromArchiveOptions = { + // A binary stream of a tar archive. + stream: Readable; + // If unset, the files at the root of the tree will be read. + // subpath must not contain the name of the top level directory. + subpath?: string; + // etag of the blob + etag: string; + // Filter passed on from the ReadTreeOptions + filter?: (path: string) => boolean; +}; + +export interface IReadTreeResponseFactory { + fromTarArchive(options: FromArchiveOptions): Promise; + fromZipArchive(options: FromArchiveOptions): Promise; +} + /** * An options object for search operations. */ diff --git a/packages/core-api/src/apis/definitions/OAuthRequestApi.ts b/packages/core-api/src/apis/definitions/OAuthRequestApi.ts index b9776ed037..fc4f1ef166 100644 --- a/packages/core-api/src/apis/definitions/OAuthRequestApi.ts +++ b/packages/core-api/src/apis/definitions/OAuthRequestApi.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { IconComponent } from '../../icons'; +import { IconComponent } from '../../icons/types'; import { Observable } from '../../types'; import { ApiRef, createApiRef } from '../system'; diff --git a/packages/core-api/src/apis/implementations/AlertApi/AlertApiForwarder.ts b/packages/core-api/src/apis/implementations/AlertApi/AlertApiForwarder.ts index 19da7a3765..f18829d99c 100644 --- a/packages/core-api/src/apis/implementations/AlertApi/AlertApiForwarder.ts +++ b/packages/core-api/src/apis/implementations/AlertApi/AlertApiForwarder.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { PublishSubject } from '../../../lib'; +import { PublishSubject } from '../../../lib/subjects'; import { Observable } from '../../../types'; import { AlertApi, AlertMessage } from '../../definitions'; diff --git a/packages/core-api/src/apis/implementations/AppThemeApi/AppThemeSelector.ts b/packages/core-api/src/apis/implementations/AppThemeApi/AppThemeSelector.ts index 43b52a254b..837c5f54db 100644 --- a/packages/core-api/src/apis/implementations/AppThemeApi/AppThemeSelector.ts +++ b/packages/core-api/src/apis/implementations/AppThemeApi/AppThemeSelector.ts @@ -15,7 +15,7 @@ */ import { AppThemeApi, AppTheme } from '../../definitions'; -import { BehaviorSubject } from '../../../lib'; +import { BehaviorSubject } from '../../../lib/subjects'; import { Observable } from '../../../types'; const STORAGE_KEY = 'theme'; diff --git a/packages/core-api/src/apis/implementations/ErrorApi/ErrorApiForwarder.ts b/packages/core-api/src/apis/implementations/ErrorApi/ErrorApiForwarder.ts index 51548708d0..5993ede367 100644 --- a/packages/core-api/src/apis/implementations/ErrorApi/ErrorApiForwarder.ts +++ b/packages/core-api/src/apis/implementations/ErrorApi/ErrorApiForwarder.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { PublishSubject } from '../../../lib'; +import { PublishSubject } from '../../../lib/subjects'; import { Observable } from '../../../types'; import { ErrorApi, ErrorContext } from '../../definitions'; diff --git a/packages/core-api/src/apis/implementations/OAuthRequestApi/OAuthPendingRequests.ts b/packages/core-api/src/apis/implementations/OAuthRequestApi/OAuthPendingRequests.ts index e616ece5ae..f0710cb466 100644 --- a/packages/core-api/src/apis/implementations/OAuthRequestApi/OAuthPendingRequests.ts +++ b/packages/core-api/src/apis/implementations/OAuthRequestApi/OAuthPendingRequests.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { BehaviorSubject } from '../../../lib'; +import { BehaviorSubject } from '../../../lib/subjects'; import { Observable } from '../../../types'; type RequestQueueEntry = { diff --git a/packages/core-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.ts b/packages/core-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.ts index 23e9e1ddc4..a0a01d1bc9 100644 --- a/packages/core-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.ts +++ b/packages/core-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.ts @@ -21,7 +21,7 @@ import { AuthRequesterOptions, } from '../../definitions'; import { OAuthPendingRequests, PendingRequest } from './OAuthPendingRequests'; -import { BehaviorSubject } from '../../../lib'; +import { BehaviorSubject } from '../../../lib/subjects'; import { Observable } from '../../../types'; /** diff --git a/packages/core-api/src/app/types.ts b/packages/core-api/src/app/types.ts index cf3aaac931..df0f65f33f 100644 --- a/packages/core-api/src/app/types.ts +++ b/packages/core-api/src/app/types.ts @@ -15,13 +15,12 @@ */ import { ComponentType } from 'react'; -import { IconComponent, IconComponentMap, IconKey } from '../icons'; +import { IconComponent, IconComponentMap, IconKey } from '../icons/types'; import { AnyExternalRoutes, BackstagePlugin } from '../plugin/types'; -import { ExternalRouteRef, RouteRef } from '../routing'; -import { AnyApiFactory } from '../apis'; +import { ExternalRouteRef, RouteRef, SubRouteRef } from '../routing/types'; +import { AnyApiFactory } from '../apis/system'; import { AppTheme, ProfileInfo } from '../apis/definitions'; import { AppConfig } from '@backstage/config'; -import { SubRouteRef } from '../routing/types'; export type BootErrorPageProps = { step: 'load-config' | 'load-chunk'; diff --git a/packages/core-api/src/lib/AuthConnector/DefaultAuthConnector.ts b/packages/core-api/src/lib/AuthConnector/DefaultAuthConnector.ts index 1c7e92daa8..1a1bab0eb9 100644 --- a/packages/core-api/src/lib/AuthConnector/DefaultAuthConnector.ts +++ b/packages/core-api/src/lib/AuthConnector/DefaultAuthConnector.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import { AuthRequester } from '../../apis'; import { + AuthRequester, OAuthRequestApi, AuthProvider, DiscoveryApi, diff --git a/packages/core-api/src/lib/AuthSessionManager/SessionStateTracker.ts b/packages/core-api/src/lib/AuthSessionManager/SessionStateTracker.ts index 6cc9cf5237..af3d8bc9b6 100644 --- a/packages/core-api/src/lib/AuthSessionManager/SessionStateTracker.ts +++ b/packages/core-api/src/lib/AuthSessionManager/SessionStateTracker.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { SessionState } from '../../apis'; +import { SessionState } from '../../apis/definitions'; import { Observable } from '../../types'; import { BehaviorSubject } from '../subjects'; diff --git a/packages/core-api/src/lib/AuthSessionManager/types.ts b/packages/core-api/src/lib/AuthSessionManager/types.ts index f57afd6760..332824e438 100644 --- a/packages/core-api/src/lib/AuthSessionManager/types.ts +++ b/packages/core-api/src/lib/AuthSessionManager/types.ts @@ -15,7 +15,7 @@ */ import { Observable } from '../../types'; -import { SessionState } from '../../apis'; +import { SessionState } from '../../apis/definitions'; export type GetSessionOptions = { optional?: boolean; diff --git a/packages/core-api/src/routing/RouteRef.ts b/packages/core-api/src/routing/RouteRef.ts index 7ce2b2afbd..4603b03a30 100644 --- a/packages/core-api/src/routing/RouteRef.ts +++ b/packages/core-api/src/routing/RouteRef.ts @@ -23,7 +23,7 @@ import { ParamKeys, OptionalParams, } from './types'; -import { IconComponent } from '../icons'; +import { IconComponent } from '../icons/types'; // TODO(Rugvip): Remove this in the next breaking release, it's exported but unused export type RouteRefConfig = { diff --git a/packages/core-api/src/routing/types.ts b/packages/core-api/src/routing/types.ts index 1fabd39cc4..0089e29e4b 100644 --- a/packages/core-api/src/routing/types.ts +++ b/packages/core-api/src/routing/types.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { IconComponent } from '../icons'; +import { IconComponent } from '../icons/types'; import { getOrCreateGlobalSingleton } from '../lib/globalObject'; export type AnyParams = { [param in string]: string } | undefined; diff --git a/packages/core/src/components/SimpleStepper/SimpleStepperFooter.tsx b/packages/core/src/components/SimpleStepper/SimpleStepperFooter.tsx index a49e20913c..750ee55c10 100644 --- a/packages/core/src/components/SimpleStepper/SimpleStepperFooter.tsx +++ b/packages/core/src/components/SimpleStepper/SimpleStepperFooter.tsx @@ -15,7 +15,7 @@ */ import React, { useContext, ReactNode, PropsWithChildren } from 'react'; import { Button, makeStyles } from '@material-ui/core'; -import { StepActions } from './SimpleStepperStep'; +import { StepActions } from './types'; import { VerticalStepperContext } from './SimpleStepper'; const useStyles = makeStyles(theme => ({ diff --git a/packages/core/src/components/SimpleStepper/SimpleStepperStep.tsx b/packages/core/src/components/SimpleStepper/SimpleStepperStep.tsx index da467a5981..bdf3e8c59d 100644 --- a/packages/core/src/components/SimpleStepper/SimpleStepperStep.tsx +++ b/packages/core/src/components/SimpleStepper/SimpleStepperStep.tsx @@ -22,6 +22,7 @@ import { makeStyles, } from '@material-ui/core'; import { SimpleStepperFooter } from './SimpleStepperFooter'; +import { StepProps } from './types'; const useStyles = makeStyles(theme => ({ end: { @@ -29,30 +30,6 @@ const useStyles = makeStyles(theme => ({ }, })); -export type StepActions = { - showNext?: boolean; - canNext?: () => boolean; - onNext?: () => void; - nextStep?: (current: number, last: number) => number; - nextText?: string; - - showBack?: boolean; - backText?: string; - onBack?: () => void; - - showRestart?: boolean; - canRestart?: () => boolean; - onRestart?: () => void; - restartText?: string; -}; - -export type StepProps = { - title: string; - children: React.ReactElement; - end?: boolean; - actions?: StepActions; -}; - export const SimpleStepperStep = ({ title, children, diff --git a/packages/core/src/components/SimpleStepper/types.ts b/packages/core/src/components/SimpleStepper/types.ts new file mode 100644 index 0000000000..0a488ff356 --- /dev/null +++ b/packages/core/src/components/SimpleStepper/types.ts @@ -0,0 +1,41 @@ +/* + * 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 React from 'react'; + +export type StepActions = { + showNext?: boolean; + canNext?: () => boolean; + onNext?: () => void; + nextStep?: (current: number, last: number) => number; + nextText?: string; + + showBack?: boolean; + backText?: string; + onBack?: () => void; + + showRestart?: boolean; + canRestart?: () => boolean; + onRestart?: () => void; + restartText?: string; +}; + +export type StepProps = { + title: string; + children: React.ReactElement; + end?: boolean; + actions?: StepActions; +}; diff --git a/packages/core/src/components/TabbedLayout/RoutedTabs.tsx b/packages/core/src/components/TabbedLayout/RoutedTabs.tsx index 6b7b39329b..8d32e63688 100644 --- a/packages/core/src/components/TabbedLayout/RoutedTabs.tsx +++ b/packages/core/src/components/TabbedLayout/RoutedTabs.tsx @@ -16,7 +16,8 @@ import React, { useMemo } from 'react'; import { Helmet } from 'react-helmet'; import { matchRoutes, useNavigate, useParams, useRoutes } from 'react-router'; -import { Content, HeaderTabs } from '../../layout'; +import { Content } from '../../layout/Content'; +import { HeaderTabs } from '../../layout/HeaderTabs'; import { SubRoute } from './types'; export function useSelectedSubRoute( diff --git a/packages/integration/src/ScmIntegrations.ts b/packages/integration/src/ScmIntegrations.ts index 0cba8e17c9..0f44958ab6 100644 --- a/packages/integration/src/ScmIntegrations.ts +++ b/packages/integration/src/ScmIntegrations.ts @@ -20,11 +20,8 @@ import { BitbucketIntegration } from './bitbucket/BitbucketIntegration'; import { GitHubIntegration } from './github/GitHubIntegration'; import { GitLabIntegration } from './gitlab/GitLabIntegration'; import { defaultScmResolveUrl } from './helpers'; -import { - ScmIntegration, - ScmIntegrationRegistry, - ScmIntegrationsGroup, -} from './types'; +import { ScmIntegration, ScmIntegrationsGroup } from './types'; +import { ScmIntegrationRegistry } from './registry'; type IntegrationsByType = { azure: ScmIntegrationsGroup; diff --git a/packages/integration/src/index.ts b/packages/integration/src/index.ts index d15eea0832..8742114008 100644 --- a/packages/integration/src/index.ts +++ b/packages/integration/src/index.ts @@ -21,8 +21,5 @@ export * from './gitlab'; export * from './googleGcs'; export { defaultScmResolveUrl } from './helpers'; export { ScmIntegrations } from './ScmIntegrations'; -export type { - ScmIntegration, - ScmIntegrationRegistry, - ScmIntegrationsGroup, -} from './types'; +export type { ScmIntegration, ScmIntegrationsGroup } from './types'; +export type { ScmIntegrationRegistry } from './registry'; diff --git a/packages/integration/src/registry.ts b/packages/integration/src/registry.ts new file mode 100644 index 0000000000..8f38bb8d5b --- /dev/null +++ b/packages/integration/src/registry.ts @@ -0,0 +1,67 @@ +/* + * 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 { ScmIntegration, ScmIntegrationsGroup } from './types'; +import { AzureIntegration } from './azure/AzureIntegration'; +import { BitbucketIntegration } from './bitbucket/BitbucketIntegration'; +import { GitHubIntegration } from './github/GitHubIntegration'; +import { GitLabIntegration } from './gitlab/GitLabIntegration'; + +/** + * Holds all registered SCM integrations, of all types. + */ +export interface ScmIntegrationRegistry + extends ScmIntegrationsGroup { + azure: ScmIntegrationsGroup; + bitbucket: ScmIntegrationsGroup; + github: ScmIntegrationsGroup; + gitlab: ScmIntegrationsGroup; + + /** + * Resolves an absolute or relative URL in relation to a base URL. + * + * This method is adapted for use within SCM systems, so relative URLs are + * within the context of the root of the hierarchy pointed to by the base + * URL. + * + * For example, if the base URL is `/folder/a.yaml`, i.e. + * within the file tree of a certain repo, an absolute path of `/b.yaml` does + * not resolve to `https://hostname/b.yaml` but rather to + * `/b.yaml` inside the file tree of that same repo. + * + * @param options.url The (absolute or relative) URL or path to resolve + * @param options.base The base URL onto which this resolution happens + * @param options.lineNumber The line number in the target file to link to, starting with 1. Only applicable when linking to files. + */ + resolveUrl(options: { + url: string; + base: string; + lineNumber?: number; + }): string; + + /** + * Resolves the edit URL for a file within the SCM system. + * + * Most SCM systems have a web interface that allows viewing and editing files + * in the repository. The returned URL directly jumps into the edit mode for + * the file. + * If this is not possible, the integration can fall back to a URL to view + * the file in the web interface. + * + * @param url The absolute URL to the file that should be edited. + */ + resolveEditUrl(url: string): string; +} diff --git a/packages/integration/src/types.ts b/packages/integration/src/types.ts index f06bda285a..30c298c57f 100644 --- a/packages/integration/src/types.ts +++ b/packages/integration/src/types.ts @@ -15,10 +15,6 @@ */ import { Config } from '@backstage/config'; -import { AzureIntegration } from './azure/AzureIntegration'; -import { BitbucketIntegration } from './bitbucket/BitbucketIntegration'; -import { GitHubIntegration } from './github/GitHubIntegration'; -import { GitLabIntegration } from './gitlab/GitLabIntegration'; /** * Encapsulates a single SCM integration. @@ -95,52 +91,6 @@ export interface ScmIntegrationsGroup { byHost(host: string): T | undefined; } -/** - * Holds all registered SCM integrations, of all types. - */ -export interface ScmIntegrationRegistry - extends ScmIntegrationsGroup { - azure: ScmIntegrationsGroup; - bitbucket: ScmIntegrationsGroup; - github: ScmIntegrationsGroup; - gitlab: ScmIntegrationsGroup; - - /** - * Resolves an absolute or relative URL in relation to a base URL. - * - * This method is adapted for use within SCM systems, so relative URLs are - * within the context of the root of the hierarchy pointed to by the base - * URL. - * - * For example, if the base URL is `/folder/a.yaml`, i.e. - * within the file tree of a certain repo, an absolute path of `/b.yaml` does - * not resolve to `https://hostname/b.yaml` but rather to - * `/b.yaml` inside the file tree of that same repo. - * - * @param options.url The (absolute or relative) URL or path to resolve - * @param options.base The base URL onto which this resolution happens - * @param options.lineNumber The line number in the target file to link to, starting with 1. Only applicable when linking to files. - */ - resolveUrl(options: { - url: string; - base: string; - lineNumber?: number; - }): string; - - /** - * Resolves the edit URL for a file within the SCM system. - * - * Most SCM systems have a web interface that allows viewing and editing files - * in the repository. The returned URL directly jumps into the edit mode for - * the file. - * If this is not possible, the integration can fall back to a URL to view - * the file in the web interface. - * - * @param url The absolute URL to the file that should be edited. - */ - resolveEditUrl(url: string): string; -} - export type ScmIntegrationsFactory = (options: { config: Config; }) => ScmIntegrationsGroup; diff --git a/packages/techdocs-common/src/stages/prepare/preparers.ts b/packages/techdocs-common/src/stages/prepare/preparers.ts index 4c6325f305..91cfcc72ff 100644 --- a/packages/techdocs-common/src/stages/prepare/preparers.ts +++ b/packages/techdocs-common/src/stages/prepare/preparers.ts @@ -18,7 +18,9 @@ import { Entity } from '@backstage/catalog-model'; import { Config } from '@backstage/config'; import { Logger } from 'winston'; import { parseReferenceAnnotation } from '../../helpers'; -import { CommonGitPreparer, DirectoryPreparer, UrlPreparer } from '../prepare'; +import { DirectoryPreparer } from './dir'; +import { CommonGitPreparer } from './commonGit'; +import { UrlPreparer } from './url'; import { PreparerBase, PreparerBuilder, RemoteProtocol } from './types'; type factoryOptions = { diff --git a/plugins/api-docs/src/config.ts b/plugins/api-docs/src/config.ts index a90189a037..c2a806d8b2 100644 --- a/plugins/api-docs/src/config.ts +++ b/plugins/api-docs/src/config.ts @@ -16,7 +16,7 @@ import { ApiEntity } from '@backstage/catalog-model'; import { createApiRef } from '@backstage/core'; -import { ApiDefinitionWidget } from './components'; +import { ApiDefinitionWidget } from './components/ApiDefinitionCard/ApiDefinitionWidget'; export const apiDocsConfigRef = createApiRef({ id: 'plugin.api-docs.config', diff --git a/plugins/auth-backend/src/lib/oauth/OAuthAdapter.ts b/plugins/auth-backend/src/lib/oauth/OAuthAdapter.ts index 6cf6a94964..5648ca5965 100644 --- a/plugins/auth-backend/src/lib/oauth/OAuthAdapter.ts +++ b/plugins/auth-backend/src/lib/oauth/OAuthAdapter.ts @@ -23,7 +23,7 @@ import { AuthProviderConfig, } from '../../providers/types'; import { InputError } from '@backstage/errors'; -import { TokenIssuer } from '../../identity'; +import { TokenIssuer } from '../../identity/types'; import { verifyNonce } from './helpers'; import { postMessageResponse, ensuresXRequestedWith } from '../flow'; import { OAuthHandlers, OAuthStartRequest, OAuthRefreshRequest } from './types'; diff --git a/plugins/auth-backend/src/providers/google/provider.ts b/plugins/auth-backend/src/providers/google/provider.ts index a00644a90d..a714674447 100644 --- a/plugins/auth-backend/src/providers/google/provider.ts +++ b/plugins/auth-backend/src/providers/google/provider.ts @@ -39,7 +39,7 @@ import { PassportDoneCallback, } from '../../lib/passport'; import { AuthProviderFactory, RedirectInfo } from '../types'; -import { TokenIssuer } from '../../identity'; +import { TokenIssuer } from '../../identity/types'; type PrivateInfo = { refreshToken: string; diff --git a/plugins/auth-backend/src/providers/saml/provider.ts b/plugins/auth-backend/src/providers/saml/provider.ts index c3a91b3b77..979380da9e 100644 --- a/plugins/auth-backend/src/providers/saml/provider.ts +++ b/plugins/auth-backend/src/providers/saml/provider.ts @@ -28,7 +28,7 @@ import { } from '../../lib/passport'; import { AuthProviderRouteHandlers, AuthProviderFactory } from '../types'; import { postMessageResponse } from '../../lib/flow'; -import { TokenIssuer } from '../../identity'; +import { TokenIssuer } from '../../identity/types'; type SamlInfo = { fullProfile: any; diff --git a/plugins/auth-backend/src/providers/types.ts b/plugins/auth-backend/src/providers/types.ts index 1a4e7b118a..700af3ebef 100644 --- a/plugins/auth-backend/src/providers/types.ts +++ b/plugins/auth-backend/src/providers/types.ts @@ -19,7 +19,7 @@ import { CatalogApi } from '@backstage/catalog-client'; import { Config } from '@backstage/config'; import express from 'express'; import { Logger } from 'winston'; -import { TokenIssuer } from '../identity'; +import { TokenIssuer } from '../identity/types'; export type AuthProviderConfig = { /** diff --git a/plugins/cloudbuild/src/components/Cards/Cards.tsx b/plugins/cloudbuild/src/components/Cards/Cards.tsx index 75ae33027e..e7b3d54de1 100644 --- a/plugins/cloudbuild/src/components/Cards/Cards.tsx +++ b/plugins/cloudbuild/src/components/Cards/Cards.tsx @@ -14,8 +14,8 @@ * limitations under the License. */ import React, { useEffect } from 'react'; -import { useWorkflowRuns } from '../useWorkflowRuns'; -import { WorkflowRun, WorkflowRunsTable } from '../WorkflowRunsTable'; +import { useWorkflowRuns, WorkflowRun } from '../useWorkflowRuns'; +import { WorkflowRunsTable } from '../WorkflowRunsTable'; import { Entity } from '@backstage/catalog-model'; import { useEntity } from '@backstage/plugin-catalog-react'; import { WorkflowRunStatus } from '../WorkflowRunStatus'; diff --git a/plugins/cloudbuild/src/components/Router.tsx b/plugins/cloudbuild/src/components/Router.tsx index 0f71efcf86..bd2299f8e9 100644 --- a/plugins/cloudbuild/src/components/Router.tsx +++ b/plugins/cloudbuild/src/components/Router.tsx @@ -17,7 +17,7 @@ import React from 'react'; import { Entity } from '@backstage/catalog-model'; import { useEntity } from '@backstage/plugin-catalog-react'; import { Routes, Route } from 'react-router'; -import { rootRouteRef, buildRouteRef } from '../plugin'; +import { rootRouteRef, buildRouteRef } from '../routes'; import { WorkflowRunDetails } from './WorkflowRunDetails'; import { WorkflowRunsTable } from './WorkflowRunsTable'; import { CLOUDBUILD_ANNOTATION } from './useProjectName'; diff --git a/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx b/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx index 43cbbefe24..886d772dd5 100644 --- a/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx +++ b/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx @@ -19,26 +19,14 @@ import RetryIcon from '@material-ui/icons/Replay'; import GoogleIcon from '@material-ui/icons/CloudCircle'; import { Link as RouterLink, generatePath } from 'react-router-dom'; import { Table, TableColumn } from '@backstage/core'; -import { useWorkflowRuns } from '../useWorkflowRuns'; +import { useWorkflowRuns, WorkflowRun } from '../useWorkflowRuns'; import { WorkflowRunStatus } from '../WorkflowRunStatus'; import SyncIcon from '@material-ui/icons/Sync'; import { useProjectName } from '../useProjectName'; import { Entity } from '@backstage/catalog-model'; -import { Substitutions } from '../../api/types'; -import { buildRouteRef } from '../../plugin'; +import { buildRouteRef } from '../../routes'; import moment from 'moment'; -export type WorkflowRun = { - id: string; - message: string; - url?: string; - googleUrl?: string; - status: string; - substitutions: Substitutions; - createTime: string; - rerun: () => void; -}; - const generatedColumns: TableColumn[] = [ { title: 'Status', diff --git a/plugins/cloudbuild/src/components/WorkflowRunsTable/index.ts b/plugins/cloudbuild/src/components/WorkflowRunsTable/index.ts index 4e21cc67c2..e190aa55bc 100644 --- a/plugins/cloudbuild/src/components/WorkflowRunsTable/index.ts +++ b/plugins/cloudbuild/src/components/WorkflowRunsTable/index.ts @@ -14,4 +14,3 @@ * limitations under the License. */ export { WorkflowRunsTable, WorkflowRunsTableView } from './WorkflowRunsTable'; -export type { WorkflowRun } from './WorkflowRunsTable'; diff --git a/plugins/cloudbuild/src/components/useWorkflowRuns.ts b/plugins/cloudbuild/src/components/useWorkflowRuns.ts index b6d6c2c620..ac7400cbf3 100644 --- a/plugins/cloudbuild/src/components/useWorkflowRuns.ts +++ b/plugins/cloudbuild/src/components/useWorkflowRuns.ts @@ -15,10 +15,23 @@ */ import { useState } from 'react'; import { useAsyncRetry } from 'react-use'; -import { WorkflowRun } from './WorkflowRunsTable/WorkflowRunsTable'; import { cloudbuildApiRef } from '../api/CloudbuildApi'; import { useApi, errorApiRef } from '@backstage/core'; -import { ActionsListWorkflowRunsForRepoResponseData } from '../api/types'; +import { + ActionsListWorkflowRunsForRepoResponseData, + Substitutions, +} from '../api/types'; + +export type WorkflowRun = { + id: string; + message: string; + url?: string; + googleUrl?: string; + status: string; + substitutions: Substitutions; + createTime: string; + rerun: () => void; +}; export function useWorkflowRuns({ projectId }: { projectId: string }) { const api = useApi(cloudbuildApiRef); diff --git a/plugins/cloudbuild/src/plugin.ts b/plugins/cloudbuild/src/plugin.ts index f5aaf4696a..f0db5702e6 100644 --- a/plugins/cloudbuild/src/plugin.ts +++ b/plugins/cloudbuild/src/plugin.ts @@ -15,23 +15,13 @@ */ import { createPlugin, - createRouteRef, createApiFactory, googleAuthApiRef, createRoutableExtension, createComponentExtension, } from '@backstage/core'; import { cloudbuildApiRef, CloudbuildClient } from './api'; - -export const rootRouteRef = createRouteRef({ - path: '', - title: 'Google Cloudbuild', -}); - -export const buildRouteRef = createRouteRef({ - path: ':id', - title: 'Cloudbuild Run', -}); +import { rootRouteRef } from './routes'; export const cloudbuildPlugin = createPlugin({ id: 'cloudbuild', diff --git a/plugins/cloudbuild/src/routes.ts b/plugins/cloudbuild/src/routes.ts new file mode 100644 index 0000000000..610d708b44 --- /dev/null +++ b/plugins/cloudbuild/src/routes.ts @@ -0,0 +1,26 @@ +/* + * 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 { createRouteRef } from '@backstage/core'; + +export const rootRouteRef = createRouteRef({ + path: '', + title: 'Google Cloudbuild', +}); + +export const buildRouteRef = createRouteRef({ + path: ':id', + title: 'Cloudbuild Run', +}); diff --git a/plugins/github-actions/src/components/Cards/Cards.tsx b/plugins/github-actions/src/components/Cards/Cards.tsx index 4ce667eb93..c2eaaf885e 100644 --- a/plugins/github-actions/src/components/Cards/Cards.tsx +++ b/plugins/github-actions/src/components/Cards/Cards.tsx @@ -34,8 +34,8 @@ import { import ExternalLinkIcon from '@material-ui/icons/Launch'; import React, { useEffect } from 'react'; import { GITHUB_ACTIONS_ANNOTATION } from '../useProjectName'; -import { useWorkflowRuns } from '../useWorkflowRuns'; -import { WorkflowRun, WorkflowRunsTable } from '../WorkflowRunsTable'; +import { useWorkflowRuns, WorkflowRun } from '../useWorkflowRuns'; +import { WorkflowRunsTable } from '../WorkflowRunsTable'; import { WorkflowRunStatus } from '../WorkflowRunStatus'; const useStyles = makeStyles({ diff --git a/plugins/github-actions/src/components/Router.tsx b/plugins/github-actions/src/components/Router.tsx index 834fcae43c..52cd66375f 100644 --- a/plugins/github-actions/src/components/Router.tsx +++ b/plugins/github-actions/src/components/Router.tsx @@ -17,7 +17,7 @@ import React from 'react'; import { Entity } from '@backstage/catalog-model'; import { useEntity } from '@backstage/plugin-catalog-react'; import { Routes, Route } from 'react-router'; -import { rootRouteRef, buildRouteRef } from '../plugin'; +import { rootRouteRef, buildRouteRef } from '../routes'; import { WorkflowRunDetails } from './WorkflowRunDetails'; import { WorkflowRunsTable } from './WorkflowRunsTable'; import { GITHUB_ACTIONS_ANNOTATION } from './useProjectName'; diff --git a/plugins/github-actions/src/components/WorkflowRunDetails/useWorkflowRunsDetails.ts b/plugins/github-actions/src/components/WorkflowRunDetails/useWorkflowRunsDetails.ts index 3e2a5c4382..124b8e8a87 100644 --- a/plugins/github-actions/src/components/WorkflowRunDetails/useWorkflowRunsDetails.ts +++ b/plugins/github-actions/src/components/WorkflowRunDetails/useWorkflowRunsDetails.ts @@ -16,7 +16,7 @@ import { useApi, useRouteRefParams } from '@backstage/core'; import { useAsync } from 'react-use'; import { githubActionsApiRef } from '../../api'; -import { buildRouteRef } from '../../plugin'; +import { buildRouteRef } from '../../routes'; export const useWorkflowRunsDetails = ({ hostname, diff --git a/plugins/github-actions/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx b/plugins/github-actions/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx index f04ec90323..bec2503562 100644 --- a/plugins/github-actions/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx +++ b/plugins/github-actions/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx @@ -32,32 +32,14 @@ import { configApiRef, useApi, } from '@backstage/core'; -import { useWorkflowRuns } from '../useWorkflowRuns'; +import { useWorkflowRuns, WorkflowRun } from '../useWorkflowRuns'; import { WorkflowRunStatus } from '../WorkflowRunStatus'; import SyncIcon from '@material-ui/icons/Sync'; -import { buildRouteRef } from '../../plugin'; +import { buildRouteRef } from '../../routes'; import { useProjectName } from '../useProjectName'; import { Entity } from '@backstage/catalog-model'; import { readGitHubIntegrationConfigs } from '@backstage/integration'; -export type WorkflowRun = { - workflowName: string; - id: string; - message: string; - url?: string; - githubUrl?: string; - source: { - branchName: string; - commit: { - hash: string; - url?: string; - }; - }; - status: string; - conclusion: string; - onReRunClick: () => void; -}; - const generatedColumns: TableColumn[] = [ { title: 'ID', diff --git a/plugins/github-actions/src/components/WorkflowRunsTable/index.ts b/plugins/github-actions/src/components/WorkflowRunsTable/index.ts index 4e21cc67c2..e190aa55bc 100644 --- a/plugins/github-actions/src/components/WorkflowRunsTable/index.ts +++ b/plugins/github-actions/src/components/WorkflowRunsTable/index.ts @@ -14,4 +14,3 @@ * limitations under the License. */ export { WorkflowRunsTable, WorkflowRunsTableView } from './WorkflowRunsTable'; -export type { WorkflowRun } from './WorkflowRunsTable'; diff --git a/plugins/github-actions/src/components/useWorkflowRuns.ts b/plugins/github-actions/src/components/useWorkflowRuns.ts index 0690632a7b..f62b03f506 100644 --- a/plugins/github-actions/src/components/useWorkflowRuns.ts +++ b/plugins/github-actions/src/components/useWorkflowRuns.ts @@ -15,10 +15,27 @@ */ import { useState } from 'react'; import { useAsyncRetry } from 'react-use'; -import { WorkflowRun } from './WorkflowRunsTable/WorkflowRunsTable'; import { githubActionsApiRef } from '../api/GithubActionsApi'; import { useApi, errorApiRef } from '@backstage/core'; +export type WorkflowRun = { + workflowName: string; + id: string; + message: string; + url?: string; + githubUrl?: string; + source: { + branchName: string; + commit: { + hash: string; + url?: string; + }; + }; + status: string; + conclusion: string; + onReRunClick: () => void; +}; + export function useWorkflowRuns({ hostname, owner, diff --git a/plugins/github-actions/src/plugin.ts b/plugins/github-actions/src/plugin.ts index f66e96a981..a34428e18c 100644 --- a/plugins/github-actions/src/plugin.ts +++ b/plugins/github-actions/src/plugin.ts @@ -17,25 +17,13 @@ import { configApiRef, createPlugin, - createRouteRef, createApiFactory, githubAuthApiRef, createRoutableExtension, createComponentExtension, } from '@backstage/core'; import { githubActionsApiRef, GithubActionsClient } from './api'; - -// TODO(freben): This is just a demo route for now -export const rootRouteRef = createRouteRef({ - path: '', - title: 'GitHub Actions', -}); - -export const buildRouteRef = createRouteRef({ - path: ':id', - params: ['id'], - title: 'GitHub Actions Workflow Run', -}); +import { rootRouteRef } from './routes'; export const githubActionsPlugin = createPlugin({ id: 'github-actions', diff --git a/plugins/github-actions/src/routes.ts b/plugins/github-actions/src/routes.ts new file mode 100644 index 0000000000..e576379d6c --- /dev/null +++ b/plugins/github-actions/src/routes.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 { createRouteRef } from '@backstage/core'; + +// TODO(freben): This is just a demo route for now +export const rootRouteRef = createRouteRef({ + path: '', + title: 'GitHub Actions', +}); + +export const buildRouteRef = createRouteRef({ + path: ':id', + params: ['id'], + title: 'GitHub Actions Workflow Run', +}); diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/index.ts b/plugins/scaffolder-backend/src/scaffolder/stages/index.ts index ef23af1b3e..dfe49a8aa5 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/index.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/index.ts @@ -17,5 +17,3 @@ export * from './prepare'; export * from './publish'; export * from './templater'; export * from './helpers'; - -export { createLegacyActions } from './legacy'; diff --git a/plugins/techdocs/src/Router.tsx b/plugins/techdocs/src/Router.tsx index 752ce33eec..f834af14dc 100644 --- a/plugins/techdocs/src/Router.tsx +++ b/plugins/techdocs/src/Router.tsx @@ -23,7 +23,7 @@ import { rootRouteRef, rootDocsRouteRef, rootCatalogDocsRouteRef, -} from './plugin'; +} from './routes'; import { TechDocsHome } from './home/components/TechDocsHome'; import { TechDocsPage } from './reader/components/TechDocsPage'; import { EntityPageDocs } from './EntityPageDocs'; diff --git a/plugins/techdocs/src/home/components/DocsCardGrid.tsx b/plugins/techdocs/src/home/components/DocsCardGrid.tsx index 47f747442c..3b561967e6 100644 --- a/plugins/techdocs/src/home/components/DocsCardGrid.tsx +++ b/plugins/techdocs/src/home/components/DocsCardGrid.tsx @@ -21,7 +21,7 @@ import { Entity } from '@backstage/catalog-model'; import { Button, ItemCardGrid, ItemCardHeader } from '@backstage/core'; import { Card, CardActions, CardContent, CardMedia } from '@material-ui/core'; -import { rootDocsRouteRef } from '../../plugin'; +import { rootDocsRouteRef } from '../../routes'; export const DocsCardGrid = ({ entities, diff --git a/plugins/techdocs/src/home/components/DocsTable.tsx b/plugins/techdocs/src/home/components/DocsTable.tsx index 5b4a337dea..e62435fbe9 100644 --- a/plugins/techdocs/src/home/components/DocsTable.tsx +++ b/plugins/techdocs/src/home/components/DocsTable.tsx @@ -22,7 +22,7 @@ import { IconButton, Tooltip } from '@material-ui/core'; import ShareIcon from '@material-ui/icons/Share'; import { Table, EmptyState, Button, SubvalueCell, Link } from '@backstage/core'; import { Entity } from '@backstage/catalog-model'; -import { rootDocsRouteRef } from '../../plugin'; +import { rootDocsRouteRef } from '../../routes'; export const DocsTable = ({ entities, diff --git a/plugins/techdocs/src/plugin.ts b/plugins/techdocs/src/plugin.ts index e25f245fb4..f974fbe2de 100644 --- a/plugins/techdocs/src/plugin.ts +++ b/plugins/techdocs/src/plugin.ts @@ -20,27 +20,16 @@ import { createComponentExtension, createPlugin, createRoutableExtension, - createRouteRef, discoveryApiRef, identityApiRef, } from '@backstage/core'; import { techdocsApiRef, techdocsStorageApiRef } from './api'; import { TechDocsClient, TechDocsStorageClient } from './client'; - -export const rootRouteRef = createRouteRef({ - path: '', - title: 'TechDocs Landing Page', -}); - -export const rootDocsRouteRef = createRouteRef({ - path: ':namespace/:kind/:name/*', - title: 'Docs', -}); - -export const rootCatalogDocsRouteRef = createRouteRef({ - path: '*', - title: 'Docs', -}); +import { + rootDocsRouteRef, + rootRouteRef, + rootCatalogDocsRouteRef, +} from './routes'; export const techdocsPlugin = createPlugin({ id: 'techdocs', diff --git a/plugins/techdocs/src/reader/components/Reader.tsx b/plugins/techdocs/src/reader/components/Reader.tsx index a67443e40f..4deb371917 100644 --- a/plugins/techdocs/src/reader/components/Reader.tsx +++ b/plugins/techdocs/src/reader/components/Reader.tsx @@ -23,7 +23,7 @@ import React, { useEffect, useRef, useState } from 'react'; import { useNavigate, useParams } from 'react-router-dom'; import { useAsync } from 'react-use'; import { techdocsStorageApiRef } from '../../api'; -import transformer, { +import { addBaseUrl, addGitFeedbackLink, addLinkClickListener, @@ -33,6 +33,7 @@ import transformer, { rewriteDocLinks, sanitizeDOM, simplifyMkdocsFooter, + transform as transformer, } from '../transformers'; import { TechDocsNotFound } from './TechDocsNotFound'; import TechDocsProgressBar from './TechDocsProgressBar'; diff --git a/plugins/techdocs/src/reader/components/TechDocsPageHeader.test.tsx b/plugins/techdocs/src/reader/components/TechDocsPageHeader.test.tsx index 082caeeb09..14c5b64aa0 100644 --- a/plugins/techdocs/src/reader/components/TechDocsPageHeader.test.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsPageHeader.test.tsx @@ -18,7 +18,7 @@ import { TechDocsPageHeader } from './TechDocsPageHeader'; import { act } from '@testing-library/react'; import { renderInTestApp } from '@backstage/test-utils'; import { entityRouteRef } from '@backstage/plugin-catalog-react'; -import { rootRouteRef } from '../../plugin'; +import { rootRouteRef } from '../../routes'; describe('', () => { it('should render a techdocs page header', async () => { diff --git a/plugins/techdocs/src/reader/components/TechDocsPageHeader.tsx b/plugins/techdocs/src/reader/components/TechDocsPageHeader.tsx index 10df7bff78..11529a24fe 100644 --- a/plugins/techdocs/src/reader/components/TechDocsPageHeader.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsPageHeader.tsx @@ -24,7 +24,7 @@ import { import CodeIcon from '@material-ui/icons/Code'; import React from 'react'; import { AsyncState } from 'react-use/lib/useAsync'; -import { rootRouteRef } from '../../plugin'; +import { rootRouteRef } from '../../routes'; import { TechDocsMetadata } from '../../types'; type TechDocsPageHeaderProps = { diff --git a/plugins/techdocs/src/reader/transformers/addBaseUrl.ts b/plugins/techdocs/src/reader/transformers/addBaseUrl.ts index 17070dcfe0..9cd11f0903 100644 --- a/plugins/techdocs/src/reader/transformers/addBaseUrl.ts +++ b/plugins/techdocs/src/reader/transformers/addBaseUrl.ts @@ -14,7 +14,7 @@ * limitations under the License. */ import { EntityName } from '@backstage/catalog-model'; -import type { Transformer } from './index'; +import type { Transformer } from './transformer'; import { TechDocsStorageApi } from '../../api'; type AddBaseUrlOptions = { diff --git a/plugins/techdocs/src/reader/transformers/addLinkClickListener.ts b/plugins/techdocs/src/reader/transformers/addLinkClickListener.ts index 7c5fd4d9f4..4f9ba62392 100644 --- a/plugins/techdocs/src/reader/transformers/addLinkClickListener.ts +++ b/plugins/techdocs/src/reader/transformers/addLinkClickListener.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import type { Transformer } from './index'; +import type { Transformer } from './transformer'; type AddLinkClickListenerOptions = { baseUrl: string; diff --git a/plugins/techdocs/src/reader/transformers/index.test.ts b/plugins/techdocs/src/reader/transformers/index.test.ts index 48dfd451cd..93f84d5ffa 100644 --- a/plugins/techdocs/src/reader/transformers/index.test.ts +++ b/plugins/techdocs/src/reader/transformers/index.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import transform, { Transformer } from './index'; +import { Transformer, transform } from './transformer'; describe('transform', () => { it('calls the transformers', () => { diff --git a/plugins/techdocs/src/reader/transformers/index.ts b/plugins/techdocs/src/reader/transformers/index.ts index a005ad470b..60a80c04c0 100644 --- a/plugins/techdocs/src/reader/transformers/index.ts +++ b/plugins/techdocs/src/reader/transformers/index.ts @@ -23,30 +23,4 @@ export * from './simplifyMkdocsFooter'; export * from './onCssReady'; export * from './sanitizeDOM'; export * from './injectCss'; - -// TODO(freben): move all of this out of index - -export type Transformer = (dom: Element) => Element; - -function transform( - html: string | Element, - transformers: Transformer[], -): Element { - let dom: Element; - - if (typeof html === 'string') { - dom = new DOMParser().parseFromString(html, 'text/html').documentElement; - } else if (html instanceof Element) { - dom = html; - } else { - throw new Error('dom is not a recognized type'); - } - - transformers.forEach(transformer => { - dom = transformer(dom); - }); - - return dom; -} - -export default transform; +export * from './transformer'; diff --git a/plugins/techdocs/src/reader/transformers/injectCss.ts b/plugins/techdocs/src/reader/transformers/injectCss.ts index 2f6aa46bb6..2c0236a29d 100644 --- a/plugins/techdocs/src/reader/transformers/injectCss.ts +++ b/plugins/techdocs/src/reader/transformers/injectCss.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import type { Transformer } from './index'; +import type { Transformer } from './transformer'; type InjectCssOptions = { css: string; diff --git a/plugins/techdocs/src/reader/transformers/onCssReady.ts b/plugins/techdocs/src/reader/transformers/onCssReady.ts index 50dbe52cbd..2f9f7afbe7 100644 --- a/plugins/techdocs/src/reader/transformers/onCssReady.ts +++ b/plugins/techdocs/src/reader/transformers/onCssReady.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import type { Transformer } from './index'; +import type { Transformer } from './transformer'; type OnCssReadyOptions = { docStorageUrl: Promise; diff --git a/plugins/techdocs/src/reader/transformers/removeMkdocsHeader.ts b/plugins/techdocs/src/reader/transformers/removeMkdocsHeader.ts index 087574b2de..5b7c77b2b5 100644 --- a/plugins/techdocs/src/reader/transformers/removeMkdocsHeader.ts +++ b/plugins/techdocs/src/reader/transformers/removeMkdocsHeader.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import type { Transformer } from './index'; +import type { Transformer } from './transformer'; export const removeMkdocsHeader = (): Transformer => { return dom => { diff --git a/plugins/techdocs/src/reader/transformers/rewriteDocLinks.ts b/plugins/techdocs/src/reader/transformers/rewriteDocLinks.ts index 7b0c23c3e3..cc366905d5 100644 --- a/plugins/techdocs/src/reader/transformers/rewriteDocLinks.ts +++ b/plugins/techdocs/src/reader/transformers/rewriteDocLinks.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import type { Transformer } from './index'; +import type { Transformer } from './transformer'; export const rewriteDocLinks = (): Transformer => { return dom => { diff --git a/plugins/techdocs/src/reader/transformers/sanitizeDOM/index.ts b/plugins/techdocs/src/reader/transformers/sanitizeDOM/index.ts index 389e4b625a..4ab8669cc3 100644 --- a/plugins/techdocs/src/reader/transformers/sanitizeDOM/index.ts +++ b/plugins/techdocs/src/reader/transformers/sanitizeDOM/index.ts @@ -16,7 +16,7 @@ // @ts-ignore import sanitizeHtml from 'sanitize-html'; -import type { Transformer } from '../index'; +import type { Transformer } from '../transformer'; import { TECHDOCS_ALLOWED_TAGS } from './tags'; import { TECHDOCS_ALLOWED_ATTRIBUTES } from './attributes'; diff --git a/plugins/techdocs/src/reader/transformers/simplifyMkdocsFooter.ts b/plugins/techdocs/src/reader/transformers/simplifyMkdocsFooter.ts index 0d0745724d..93e315d42e 100644 --- a/plugins/techdocs/src/reader/transformers/simplifyMkdocsFooter.ts +++ b/plugins/techdocs/src/reader/transformers/simplifyMkdocsFooter.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import type { Transformer } from './index'; +import type { Transformer } from './transformer'; export const simplifyMkdocsFooter = (): Transformer => { return dom => { diff --git a/plugins/techdocs/src/reader/transformers/transformer.ts b/plugins/techdocs/src/reader/transformers/transformer.ts new file mode 100644 index 0000000000..0a554d76bf --- /dev/null +++ b/plugins/techdocs/src/reader/transformers/transformer.ts @@ -0,0 +1,38 @@ +/* + * 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 type Transformer = (dom: Element) => Element; + +export const transform = ( + html: string | Element, + transformers: Transformer[], +): Element => { + let dom: Element; + + if (typeof html === 'string') { + dom = new DOMParser().parseFromString(html, 'text/html').documentElement; + } else if (html instanceof Element) { + dom = html; + } else { + throw new Error('dom is not a recognized type'); + } + + transformers.forEach(transformer => { + dom = transformer(dom); + }); + + return dom; +}; diff --git a/plugins/techdocs/src/routes.ts b/plugins/techdocs/src/routes.ts new file mode 100644 index 0000000000..209669d64f --- /dev/null +++ b/plugins/techdocs/src/routes.ts @@ -0,0 +1,32 @@ +/* + * 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 { createRouteRef } from '@backstage/core'; + +export const rootRouteRef = createRouteRef({ + path: '', + title: 'TechDocs Landing Page', +}); + +export const rootDocsRouteRef = createRouteRef({ + path: ':namespace/:kind/:name/*', + title: 'Docs', +}); + +export const rootCatalogDocsRouteRef = createRouteRef({ + path: '*', + title: 'Docs', +}); diff --git a/plugins/techdocs/src/test-utils/shadowDom.ts b/plugins/techdocs/src/test-utils/shadowDom.ts index 556979217e..59e622c165 100644 --- a/plugins/techdocs/src/test-utils/shadowDom.ts +++ b/plugins/techdocs/src/test-utils/shadowDom.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import transformer from '../reader/transformers'; import type { Transformer } from '../reader/transformers'; +import { transform as transformer } from '../reader/transformers'; export type CreateTestShadowDomOptions = { preTransformers: Transformer[];