@@ -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',
|
||||
});
|
||||
|
||||
@@ -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) =>
|
||||
|
||||
Reference in New Issue
Block a user