github-actions

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-08-19 15:08:13 +02:00
parent 9053fd9ad3
commit 22022c45d0
10 changed files with 34 additions and 47 deletions
+12 -36
View File
@@ -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<GithubActionsApi>;
@@ -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;
@@ -17,6 +17,7 @@
import { RestEndpointMethodTypes } from '@octokit/rest';
import { createApiRef } from '@backstage/core-plugin-api';
/** @public */
export const githubActionsApiRef = createApiRef<GithubActionsApi>({
id: 'plugin.githubactions.service',
});
+4
View File
@@ -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',
@@ -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;
@@ -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('<RecentWorkflowRunsCard />', () => {
jest.resetAllMocks();
});
const renderSubject = (props: RecentWorkflowRunsCardProps = {}) =>
const renderSubject = (props: any = {}) =>
render(
<ThemeProvider theme={lightTheme}>
<MemoryRouter>
@@ -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);
@@ -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';
@@ -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();
@@ -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) =>