Skip to content

Commit

Permalink
add comments to and rename stripWhitespaces helper func
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel-Ladzaretti committed Nov 2, 2022
1 parent f5945c4 commit ef865fa
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/workers/repository/config-migration/branch/rebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export async function rebaseMigrationBranch(
const configFileName = migratedConfigData.filename;
let contents = migratedConfigData.content;
const existingContents = await getFile(configFileName, branchName);
if (stripWhitespaces(contents) === stripWhitespaces(existingContents)) {
if (
jsonStripWhitespaces(contents) === jsonStripWhitespaces(existingContents)
) {
logger.debug('Migration branch is up to date');
return null;
}
Expand Down Expand Up @@ -61,9 +63,20 @@ export async function rebaseMigrationBranch(
});
}

function stripWhitespaces(str: string | null): string | null {
if (!str) {
/**
* @param json a JSON string
* @return a minimal json string. i.e. does not contain any formatting/whitespaces
*/
function jsonStripWhitespaces(json: string | null): string | null {
if (!json) {
return null;
}
return quickStringify(JSON.parse(str));
/**
* JSON.stringify(value, replacer, space):
* If "space" is anything other than a string or number —
* for example, is null or not provided — no white space is used.
*
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#parameters
*/
return quickStringify(JSON.parse(json));
}

0 comments on commit ef865fa

Please sign in to comment.