import { FormLabel } from '@automattic/components'; import { Button, ExternalLink } from '@wordpress/components'; import { createInterpolateElement } from '@wordpress/element'; import { useI18n } from '@wordpress/react-i18n'; import { useEffect } from 'react'; import { useDispatch } from 'react-redux'; import { recordTracksEvent } from 'calypso/state/analytics/actions'; import { GitHubRepositoryData } from '../../use-github-repositories-query'; import { CodeHighlighter } from '../code-highlighter'; import { useDeploymentStyleContext } from './context'; import { Workflow } from './use-deployment-workflows-query'; import { useWorkflowValidations } from './use-workflow-validations'; import { WorkflowValidation } from './workflow-validation'; interface WorkflowValidationWizardProps { repository: Pick< GitHubRepositoryData, 'owner' | 'name' >; branchName: string; workflow: Workflow; validYamlFile: string; } export const WorkflowValidationWizard = ( { repository, branchName, workflow, validYamlFile, }: WorkflowValidationWizardProps ) => { const { __ } = useI18n(); const dispatch = useDispatch(); const validations = useWorkflowValidations( { branchName, validYamlFile } ); const { workflowCheckResult, isCheckingWorkflow, onWorkflowVerify } = useDeploymentStyleContext(); useEffect( () => { if ( ! workflowCheckResult ) { return; } else if ( workflowCheckResult.conclusion === 'error' ) { const checks: Record< string, string > = {}; workflowCheckResult.checked_items.forEach( ( check ) => { checks[ check.validation_name ] = check.status; } ); dispatch( recordTracksEvent( 'calypso_hosting_github_workflow_invalid', checks ) ); } else { dispatch( recordTracksEvent( 'calypso_hosting_github_workflow_valid' ) ); } }, [ workflowCheckResult, dispatch ] ); const getWorkflowCheckDescription = () => { if ( ! workflowCheckResult ) { return; } const workflowPath = `https://github.com/${ repository.owner }/${ repository.name }/blob/${ branchName }/${ workflow.workflow_path }`; const description = workflowCheckResult.conclusion === 'error' ? createInterpolateElement( __( 'Your workflow is good to go!' ), { filename: { workflow.file_name }, } ) : createInterpolateElement( __( 'Please edit and fix the problems we found.' ), { filename: { workflow.file_name }, } ); return

{ description }

; }; return (
{ __( 'Workflow check' ) } { getWorkflowCheckDescription() } { workflowCheckResult?.checked_items.map( ( workflowCheck ) => { const validation = validations[ workflowCheck.validation_name ]; if ( ! validation ) { return null; } return (

{ validation.description }

); } ) }
); };