From 22022c45d05b87ae65a077665486749e6ad3c528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Fri, 19 Aug 2022 15:08:13 +0200 Subject: [PATCH] github-actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- plugins/github-actions/api-report.md | 48 +++++-------------- .../src/api/GithubActionsApi.ts | 1 + plugins/github-actions/src/api/types.ts | 4 ++ .../src/components/Cards/Cards.tsx | 2 + .../Cards/RecentWorkflowRunsCard.test.tsx | 3 +- .../Cards/RecentWorkflowRunsCard.tsx | 16 +++---- .../src/components/Cards/index.ts | 1 + .../github-actions/src/components/Router.tsx | 3 ++ .../components/getProjectNameFromEntity.ts | 2 + scripts/api-extractor.ts | 1 - 10 files changed, 34 insertions(+), 47 deletions(-) diff --git a/plugins/github-actions/api-report.md b/plugins/github-actions/api-report.md index 8cf70eabcc..b1628996e0 100644 --- a/plugins/github-actions/api-report.md +++ b/plugins/github-actions/api-report.md @@ -14,8 +14,6 @@ import { OAuthApi } from '@backstage/core-plugin-api'; import { RestEndpointMethodTypes } from '@octokit/rest'; import { RouteRef } from '@backstage/core-plugin-api'; -// Warning: (ae-missing-release-tag) "BuildStatus" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public (undocumented) export enum BuildStatus { // (undocumented) @@ -43,18 +41,14 @@ export const EntityLatestGithubActionsForBranchCard: (props: { variant?: InfoCardVariants | undefined; }) => JSX.Element; -// Warning: (ae-forgotten-export) The symbol "Props" needs to be exported by the entry point index.d.ts -// // @public (undocumented) -export const EntityRecentGithubActionsRunsCard: ({ - branch, - dense, - limit, - variant, -}: Props) => JSX.Element; +export const EntityRecentGithubActionsRunsCard: (props: { + branch?: string | undefined; + dense?: boolean | undefined; + limit?: number | undefined; + variant?: InfoCardVariants | undefined; +}) => JSX.Element; -// Warning: (ae-missing-release-tag) "GITHUB_ACTIONS_ANNOTATION" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public (undocumented) export const GITHUB_ACTIONS_ANNOTATION = 'github.com/project-slug'; @@ -112,8 +106,6 @@ export type GithubActionsApi = { >; }; -// Warning: (ae-missing-release-tag) "githubActionsApiRef" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public (undocumented) export const githubActionsApiRef: ApiRef; @@ -189,15 +181,11 @@ const githubActionsPlugin: BackstagePlugin< export { githubActionsPlugin }; export { githubActionsPlugin as plugin }; -// Warning: (ae-missing-release-tag) "isGithubActionsAvailable" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public (undocumented) const isGithubActionsAvailable: (entity: Entity) => boolean; export { isGithubActionsAvailable }; export { isGithubActionsAvailable as isPluginApplicableToEntity }; -// Warning: (ae-missing-release-tag) "Job" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public (undocumented) export type Job = { html_url?: string; @@ -210,47 +198,35 @@ export type Job = { steps?: Step[]; }; -// Warning: (ae-missing-release-tag) "Jobs" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public (undocumented) export type Jobs = { total_count: number; jobs: Job[]; }; -// Warning: (ae-missing-release-tag) "LatestWorkflowRunCard" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public (undocumented) export const LatestWorkflowRunCard: (props: { branch: string; variant?: InfoCardVariants; }) => JSX.Element; -// Warning: (ae-missing-release-tag) "LatestWorkflowsForBranchCard" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public (undocumented) export const LatestWorkflowsForBranchCard: (props: { branch: string; variant?: InfoCardVariants; }) => JSX.Element; -// Warning: (ae-missing-release-tag) "RecentWorkflowRunsCard" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public (undocumented) -export const RecentWorkflowRunsCard: ({ - branch, - dense, - limit, - variant, -}: Props) => JSX.Element; +export const RecentWorkflowRunsCard: (props: { + branch?: string; + dense?: boolean; + limit?: number; + variant?: InfoCardVariants; +}) => JSX.Element; -// Warning: (ae-missing-release-tag) "Router" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public (undocumented) export const Router: () => JSX.Element; -// Warning: (ae-missing-release-tag) "Step" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public (undocumented) export type Step = { name: string; diff --git a/plugins/github-actions/src/api/GithubActionsApi.ts b/plugins/github-actions/src/api/GithubActionsApi.ts index 25bbf0b809..14dbc3210e 100644 --- a/plugins/github-actions/src/api/GithubActionsApi.ts +++ b/plugins/github-actions/src/api/GithubActionsApi.ts @@ -17,6 +17,7 @@ import { RestEndpointMethodTypes } from '@octokit/rest'; import { createApiRef } from '@backstage/core-plugin-api'; +/** @public */ export const githubActionsApiRef = createApiRef({ id: 'plugin.githubactions.service', }); diff --git a/plugins/github-actions/src/api/types.ts b/plugins/github-actions/src/api/types.ts index db926d9c03..2e997d9bf7 100644 --- a/plugins/github-actions/src/api/types.ts +++ b/plugins/github-actions/src/api/types.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +/** @public */ export type Step = { name: string; status: string; @@ -23,6 +24,7 @@ export type Step = { completed_at?: string; }; +/** @public */ export type Job = { html_url?: string; status: string; @@ -34,11 +36,13 @@ export type Job = { steps?: Step[]; }; +/** @public */ export type Jobs = { total_count: number; jobs: Job[]; }; +/** @public */ export enum BuildStatus { 'success', 'failure', diff --git a/plugins/github-actions/src/components/Cards/Cards.tsx b/plugins/github-actions/src/components/Cards/Cards.tsx index 5e53096ba4..79777ed8c3 100644 --- a/plugins/github-actions/src/components/Cards/Cards.tsx +++ b/plugins/github-actions/src/components/Cards/Cards.tsx @@ -78,6 +78,7 @@ const WidgetContent = (props: { ); }; +/** @public */ export const LatestWorkflowRunCard = (props: { branch: string; variant?: InfoCardVariants; @@ -118,6 +119,7 @@ export const LatestWorkflowRunCard = (props: { ); }; +/** @public */ export const LatestWorkflowsForBranchCard = (props: { branch: string; variant?: InfoCardVariants; diff --git a/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.test.tsx b/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.test.tsx index a987a8569f..7a20501072 100644 --- a/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.test.tsx +++ b/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.test.tsx @@ -21,7 +21,6 @@ import { render } from '@testing-library/react'; import React from 'react'; import { MemoryRouter } from 'react-router'; import { useWorkflowRuns } from '../useWorkflowRuns'; -import type { Props as RecentWorkflowRunsCardProps } from './RecentWorkflowRunsCard'; import { RecentWorkflowRunsCard } from './RecentWorkflowRunsCard'; import { ConfigReader } from '@backstage/core-app-api'; @@ -75,7 +74,7 @@ describe('', () => { jest.resetAllMocks(); }); - const renderSubject = (props: RecentWorkflowRunsCardProps = {}) => + const renderSubject = (props: any = {}) => render( diff --git a/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.tsx b/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.tsx index 3eba4981e7..fcd0f194a3 100644 --- a/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.tsx +++ b/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.tsx @@ -32,29 +32,28 @@ import { const firstLine = (message: string): string => message.split('\n')[0]; -export type Props = { +/** @public */ +export const RecentWorkflowRunsCard = (props: { branch?: string; dense?: boolean; limit?: number; variant?: InfoCardVariants; -}; +}) => { + const { branch, dense = false, limit = 5, variant } = props; -export const RecentWorkflowRunsCard = ({ - branch, - dense = false, - limit = 5, - variant, -}: Props) => { const { entity } = useEntity(); const config = useApi(configApiRef); const errorApi = useApi(errorApiRef); + // TODO: Get github hostname from metadata annotation const hostname = readGitHubIntegrationConfigs( config.getOptionalConfigArray('integrations.github') ?? [], )[0].host; + const [owner, repo] = ( entity?.metadata.annotations?.[GITHUB_ACTIONS_ANNOTATION] ?? '/' ).split('/'); + const [{ runs = [], loading, error }] = useWorkflowRuns({ hostname, owner, @@ -62,6 +61,7 @@ export const RecentWorkflowRunsCard = ({ branch, initialPageSize: limit, }); + useEffect(() => { if (error) { errorApi.post(error); diff --git a/plugins/github-actions/src/components/Cards/index.ts b/plugins/github-actions/src/components/Cards/index.ts index 1457b9c86f..335c0c42da 100644 --- a/plugins/github-actions/src/components/Cards/index.ts +++ b/plugins/github-actions/src/components/Cards/index.ts @@ -13,5 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + export { LatestWorkflowRunCard, LatestWorkflowsForBranchCard } from './Cards'; export { RecentWorkflowRunsCard } from './RecentWorkflowRunsCard'; diff --git a/plugins/github-actions/src/components/Router.tsx b/plugins/github-actions/src/components/Router.tsx index 793293cce8..d8b8a87d38 100644 --- a/plugins/github-actions/src/components/Router.tsx +++ b/plugins/github-actions/src/components/Router.tsx @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import React from 'react'; import { Entity } from '@backstage/catalog-model'; import { useEntity } from '@backstage/plugin-catalog-react'; @@ -23,9 +24,11 @@ import { WorkflowRunsTable } from './WorkflowRunsTable'; import { GITHUB_ACTIONS_ANNOTATION } from './getProjectNameFromEntity'; import { MissingAnnotationEmptyState } from '@backstage/core-components'; +/** @public */ export const isGithubActionsAvailable = (entity: Entity) => Boolean(entity.metadata.annotations?.[GITHUB_ACTIONS_ANNOTATION]); +/** @public */ export const Router = () => { const { entity } = useEntity(); diff --git a/plugins/github-actions/src/components/getProjectNameFromEntity.ts b/plugins/github-actions/src/components/getProjectNameFromEntity.ts index 13e0a2bdd5..24e546754e 100644 --- a/plugins/github-actions/src/components/getProjectNameFromEntity.ts +++ b/plugins/github-actions/src/components/getProjectNameFromEntity.ts @@ -13,8 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { Entity } from '@backstage/catalog-model'; +/** @public */ export const GITHUB_ACTIONS_ANNOTATION = 'github.com/project-slug'; export const getProjectNameFromEntity = (entity: Entity) => diff --git a/scripts/api-extractor.ts b/scripts/api-extractor.ts index a00427579d..6368414951 100644 --- a/scripts/api-extractor.ts +++ b/scripts/api-extractor.ts @@ -203,7 +203,6 @@ const ALLOW_WARNINGS = [ 'plugins/catalog-import', 'plugins/cost-insights', 'plugins/git-release-manager', - 'plugins/github-actions', 'plugins/github-deployments', 'plugins/github-pull-requests-board', 'plugins/jenkins',