Skip to content

Commit

Permalink
clean up comparison functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaurencin committed Mar 19, 2024
1 parent 74ac6a1 commit 6a0906b
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions script/release/notes/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,24 @@ const getNotes = async (fromRef, toRef, newVersion) => {
return notes;
};

const compareVersions = (v1, v2) => {
const [split1, split2] = [v1.split('.'), v2.split('.')];

if (split1.length !== split2.length) {
throw new Error(`Expected version strings to have same number of sections: ${split1} and ${split2}`);
}
for (let i = 0; i < split1.length; i++) {
const p1 = parseInt(split1[i], 10);
const p2 = parseInt(split2[i], 10);

if (p1 > p2) return 1;
else if (p1 < p2) return -1;
// Continue checking the value if this portion is equal
}

return 0;
};

const removeSupercededStackUpdates = (commits) => {
const updateRegex = /^Updated ([a-zA-Z.]+) to v?([\d.]+)/;
const notupdates = [];
Expand All @@ -496,24 +514,10 @@ const removeSupercededStackUpdates = (commits) => {
notupdates.push(commit);
continue;
}

const [, dep, version] = match;
if (!newest[dep]) {
if (!newest[dep] || compareVersions(version, newest[dep].version) > 0) {
newest[dep] = { commit, version };
continue;
}

const newestSplit = newest[dep].version.split('.');
const replacementSplit = version.split('.');
if (newestSplit.length !== replacementSplit.length) {
throw new Error(`Expected version strings to have same number of sections: ${newest[dep].version} and ${version}`);
}
for (let i = 0; i < newestSplit.length; i++) {
if (parseInt(replacementSplit[i]) < parseInt(newestSplit[i])) {
break;
} else if (parseInt(replacementSplit[i]) > parseInt(newestSplit[i])) {
newest[dep] = { commit, version };
break;
}
}
}

Expand Down

0 comments on commit 6a0906b

Please sign in to comment.