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
{ description }
; }; return ({ validation.description }