add clean function (#211)

This commit is contained in:
Oliver King
2022-07-06 16:15:31 -04:00
committed by GitHub
parent 72a09f4051
commit 19d66d6bdb
3 changed files with 32 additions and 5 deletions
+11
View File
@@ -47,3 +47,14 @@ export function getWorkflowAnnotationKeyLabel(
.digest('hex')
return `githubWorkflow_${hashKey}`
}
/**
* Cleans label to match valid kubernetes label specification by removing invalid characters
* @param label
* @returns cleaned label
*/
export function cleanLabel(label: string): string {
const removedInvalidChars = label.replace(/[^-A-Za-z0-9_.]/gi, '')
const regex = /([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]/
return regex.exec(removedInvalidChars)[0] || ''
}