reaming directory to folder and added creator check for deployment templates

This commit is contained in:
Anurag Chauhan
2022-03-04 06:28:56 +00:00
committed by GitHub
parent 91ee67fb2d
commit c6cf518c75
2 changed files with 12 additions and 7 deletions
+11 -6
View File
@@ -14,6 +14,7 @@ interface WorkflowWithErrors {
interface WorkflowProperties { interface WorkflowProperties {
name: string; name: string;
description: string; description: string;
creator: string;
iconName: string; iconName: string;
categories: string[]; categories: string[];
} }
@@ -69,7 +70,7 @@ async function checkWorkflows(folders: string[], folder_category_map: object[]):
return result; return result;
} }
async function checkWorkflow(workflowPath: string, propertiesPath: string, directory_category_map: object[]): Promise<WorkflowWithErrors> { async function checkWorkflow(workflowPath: string, propertiesPath: string, folder_category_map: object[]): Promise<WorkflowWithErrors> {
let workflowErrors: WorkflowWithErrors = { let workflowErrors: WorkflowWithErrors = {
id: workflowPath, id: workflowPath,
name: null, name: null,
@@ -104,16 +105,20 @@ async function checkWorkflow(workflowPath: string, propertiesPath: string, direc
} }
} }
var directoryName = dirname(workflowPath) var folderName = dirname(workflowPath)
var directory_category = directory_category_map.find( folder_category => folder_category["name"] == directoryName)["category"] var folder_category = folder_category_map.find( folder_category => folder_category["name"] == folderName)["category"]
if (!workflowPath.endsWith("blank.yml") && ((!properties.categories || properties.categories.length == 0 )|| if (!workflowPath.endsWith("blank.yml") && ((!properties.categories || properties.categories.length == 0 )||
properties.categories[0].toLowerCase() !== directory_category.toLowerCase())) { properties.categories[0].toLowerCase() !== folder_category.toLowerCase())) {
if(!properties.categories || properties.categories.length == 0) { if(!properties.categories || properties.categories.length == 0) {
workflowErrors.errors.push(`Workflow categories cannot be null or empty`) workflowErrors.errors.push(`Workflow categories cannot be null or empty`)
} else { } else {
workflowErrors.errors.push(`The first category in properties.json categories must be "${directory_category}" for ${basename(directoryName)} directory workflow.`) workflowErrors.errors.push(`The first category in properties.json categories must be "${folder_category}" for ${basename(folderName)} folder workflow.`)
} }
} }
if(folder_category.toLowerCase() == 'deployment' && !properties.creator) {
workflowErrors.errors.push(`The "creator" in properties.json must be present.`)
}
} catch (e) { } catch (e) {
workflowErrors.errors.push(e.toString()) workflowErrors.errors.push(e.toString())
} }
@@ -124,7 +129,7 @@ async function checkWorkflow(workflowPath: string, propertiesPath: string, direc
try { try {
const settings = require("./settings.json"); const settings = require("./settings.json");
const erroredWorkflows = await checkWorkflows( const erroredWorkflows = await checkWorkflows(
settings.folders, settings.directory_category_map settings.folders, settings.folder_category_map
) )
if (erroredWorkflows.length > 0) { if (erroredWorkflows.length > 0) {
+1 -1
View File
@@ -5,7 +5,7 @@
"../../deployments", "../../deployments",
"../../code-scanning" "../../code-scanning"
], ],
"directory_category_map": [ "folder_category_map": [
{ {
"name": "../../ci", "name": "../../ci",
"category": "Continuous integration" "category": "Continuous integration"