File size: 1,303 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { useI18n } from '@wordpress/react-i18n';
import { useMemo } from 'react';
import { codePushExample, uploadArtifactExample } from './workflow-yaml-examples';

interface Validation {
	label: string;
	description: string;
	content: string;
}

interface UseWorkflowValidationsParams {
	branchName: string;
	validYamlFile: string;
}

export const useWorkflowValidations = ( {
	branchName,
	validYamlFile,
}: UseWorkflowValidationsParams ) => {
	const { __ } = useI18n();

	const validations: Record< string, Validation > = useMemo( () => {
		return {
			valid_yaml_file: {
				label: __( 'The workflow file is a valid YAML' ),
				description: __(
					'Ensure that your workflow file contains a valid YAML structure. Here’s an example:'
				),
				content: validYamlFile,
			},
			triggered_on_push: {
				label: __( 'The workflow is triggered on push' ),
				description: __( 'Ensure that your workflow triggers on code push:' ),
				content: codePushExample( branchName ),
			},
			upload_artifact_with_required_name: {
				label: __( 'The uploaded artifact has the required name' ),
				description: __( "Ensure that your workflow uploads an artifact named 'wpcom'. Example:" ),
				content: uploadArtifactExample(),
			},
		};
	}, [ __, branchName, validYamlFile ] );

	return validations;
};