mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-24 13:39:27 +08:00
add clean function (#211)
This commit is contained in:
@@ -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] || ''
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user