Skip to content

Commit

Permalink
Sanitize branch name to be used in path or filename
Browse files Browse the repository at this point in the history
  • Loading branch information
WunderBart committed Mar 15, 2023
1 parent 5b336fa commit 2509edd
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions bin/plugin/commands/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
const fs = require( 'fs' );
const path = require( 'path' );
const { mapValues, kebabCase } = require( 'lodash' );
const { mapValues } = require( 'lodash' );
const SimpleGit = require( 'simple-git' );

/**
Expand Down Expand Up @@ -83,6 +83,17 @@ const config = require( '../config' );
* @property {number=} maxListViewOpen Max time to open list view.
*/

/**
* Sanitizes branch name to be used in a path or a filename.
*
* @param {string} branch
*
* @return {string} Sanitized branch name.
*/
function sanitizeBranchName( branch ) {
return branch.replace( /[^a-zA-Z0-9-]/g, '-' );
}

/**
* Computes the average number from an array numbers.
*
Expand Down Expand Up @@ -299,8 +310,8 @@ async function runPerformanceTests( branches, options ) {
const branchDirectories = {};
for ( const branch of branches ) {
log( ` >> Branch: ${ branch }` );
const environmentDirectory =
rootDirectory + '/envs/' + kebabCase( branch );
const sanitizedBranch = sanitizeBranchName( branch );
const environmentDirectory = rootDirectory + '/envs/' + sanitizedBranch;
// @ts-ignore
branchDirectories[ branch ] = environmentDirectory;
const buildPath = `${ environmentDirectory }/plugin`;
Expand Down Expand Up @@ -401,7 +412,8 @@ async function runPerformanceTests( branches, options ) {
for ( let i = 0; i < TEST_ROUNDS; i++ ) {
rawResults[ i ] = {};
for ( const branch of branches ) {
const runKey = `${ branch }_${ testSuite }_run-${ i }`;
const sanitizedBranch = sanitizeBranchName( branch );
const runKey = `${ sanitizedBranch }_${ testSuite }_run-${ i }`;
// @ts-ignore
const environmentDirectory = branchDirectories[ branch ];
log( ` >> Branch: ${ branch }, Suite: ${ testSuite }` );
Expand Down

0 comments on commit 2509edd

Please sign in to comment.