use new Error and change useProjectName to getProjectName

Signed-off-by: KaemonIsland <kaemonlovendahl@outlook.com>
This commit is contained in:
KaemonIsland
2022-02-16 11:25:24 -07:00
parent 6cc710c84c
commit 03af89706c
7 changed files with 10 additions and 10 deletions
@@ -20,7 +20,7 @@ import { Routes, Route } from 'react-router';
import { buildRouteRef } from '../routes';
import { WorkflowRunDetails } from './WorkflowRunDetails';
import { WorkflowRunsTable } from './WorkflowRunsTable';
import { GITHUB_ACTIONS_ANNOTATION } from './useProjectName';
import { GITHUB_ACTIONS_ANNOTATION } from './getProjectName';
import { MissingAnnotationEmptyState } from '@backstage/core-components';
export const isGithubActionsAvailable = (entity: Entity) =>
@@ -39,7 +39,7 @@ import ExternalLinkIcon from '@material-ui/icons/Launch';
import { DateTime } from 'luxon';
import React from 'react';
import { Job, Jobs, Step } from '../../api';
import { useProjectName } from '../useProjectName';
import { getProjectName } from '../getProjectName';
import { WorkflowRunStatus } from '../WorkflowRunStatus';
import { useWorkflowRunJobs } from './useWorkflowRunJobs';
import { useWorkflowRunsDetails } from './useWorkflowRunsDetails';
@@ -164,7 +164,7 @@ const JobsList = ({ jobs, entity }: { jobs?: Jobs; entity: Entity }) => {
export const WorkflowRunDetails = ({ entity }: { entity: Entity }) => {
const config = useApi(configApiRef);
const projectName = useProjectName(entity);
const projectName = getProjectName(entity);
// TODO: Get github hostname from metadata annotation
const hostname = readGitHubIntegrationConfigs(
@@ -37,7 +37,7 @@ export const useWorkflowRunJobs = ({
repo,
id: parseInt(id, 10),
})
: Promise.reject(Error('No repo/owner provided'));
: Promise.reject(new Error('No repo/owner provided'));
}, [repo, owner, id]);
return jobs;
};
@@ -37,7 +37,7 @@ export const useWorkflowRunsDetails = ({
repo,
id: parseInt(id, 10),
})
: Promise.reject(Error('No repo/owner provided'));
: Promise.reject(new Error('No repo/owner provided'));
}, [repo, owner, id]);
return details;
};
@@ -33,7 +33,7 @@ import {
import DescriptionIcon from '@material-ui/icons/Description';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import React from 'react';
import { useProjectName } from '../useProjectName';
import { getProjectName } from '../getProjectName';
import { useDownloadWorkflowRunLogs } from './useDownloadWorkflowRunLogs';
const useStyles = makeStyles<Theme>(theme => ({
@@ -77,7 +77,7 @@ export const WorkflowRunLogs = ({
}) => {
const config = useApi(configApiRef);
const classes = useStyles();
const projectName = useProjectName(entity);
const projectName = getProjectName(entity);
// TODO: Get github hostname from metadata annotation
const hostname = readGitHubIntegrationConfigs(
@@ -29,7 +29,7 @@ import { useWorkflowRuns, WorkflowRun } from '../useWorkflowRuns';
import { WorkflowRunStatus } from '../WorkflowRunStatus';
import SyncIcon from '@material-ui/icons/Sync';
import { buildRouteRef } from '../../routes';
import { useProjectName } from '../useProjectName';
import { getProjectName } from '../getProjectName';
import { Entity } from '@backstage/catalog-model';
import { readGitHubIntegrationConfigs } from '@backstage/integration';
@@ -157,7 +157,7 @@ export const WorkflowRunsTable = ({
branch?: string;
}) => {
const config = useApi(configApiRef);
const projectName = useProjectName(entity);
const projectName = getProjectName(entity);
// TODO: Get github hostname from metadata annotation
const hostname = readGitHubIntegrationConfigs(
config.getOptionalConfigArray('integrations.github') ?? [],
@@ -17,5 +17,5 @@ import { Entity } from '@backstage/catalog-model';
export const GITHUB_ACTIONS_ANNOTATION = 'github.com/project-slug';
export const useProjectName = (entity: Entity) =>
export const getProjectName = (entity: Entity) =>
entity?.metadata.annotations?.[GITHUB_ACTIONS_ANNOTATION] ?? '';