Skip to content

Commit

Permalink
change regex for latest patch to match whole jsons parts of download …
Browse files Browse the repository at this point in the history
…page per version
  • Loading branch information
psavidis committed Oct 11, 2024
1 parent c4d6a61 commit 9ac5a59
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
31 changes: 25 additions & 6 deletions common/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163780,6 +163780,7 @@ module.exports = async function () {

const getVersionLabels = async function (potentialLabels, latestMinorVersion) {
const promises = potentialLabels.map(async potentialLabel => {

const minorVersion = getMinorFromPotentialLabel(potentialLabel);

if (minorVersion === latestMinorVersion) {
Expand All @@ -163796,10 +163797,10 @@ module.exports = async function () {
if (!latestPatchVersion) {
const calculatedVersionLabel = getVersionLabelFromPotential(potentialLabel); // fallback if GitHub is down, pom version is wrong, error at parsing
console.log(`No latest patch version found for potential label: ${potentialLabel}, returning calculated version ${calculatedVersionLabel}`);
return calculatedVersionLabel;
return getNextPatchVersion(calculatedVersionLabel);
}

return latestPatchVersion;
return getNextPatchVersion(calculatedVersionLabel);;
});

// Wait for all promises to settle and filter out null values
Expand Down Expand Up @@ -163859,6 +163860,12 @@ module.exports = async function () {
return match ? match[1] : null;
}

const getNextPatchVersion = function (currentVersion) {
const versionParts = currentVersion.split('.');
versionParts[2] = parseInt(versionParts[2]) + 1;
return versionParts.join('.');
}

const getLatestPatchVersion = async function (potentialLabel) {
console.log(`Get latest patch version for issue: #${issueNumber} for potential label:`, potentialLabel);
try {
Expand All @@ -163871,11 +163878,24 @@ module.exports = async function () {
console.log(`Minor version found: ${minorVersion}`);
}

const patchVersionRegex = new RegExp(`camDownloads\\.branches\\['${minorVersion}'\\]\\s*=\\s*\\[\\s*\\{\\s*number:\\s*'(\\d+\\.\\d+\\.\\d+)'`);
const match = downloadPage.match(patchVersionRegex);
const patchVersionRegex = new RegExp(`(camDownloads\\.branches\\['${minorVersion}'\\]\\s*=\\s*)(\\[[\\s\\S]*?\\])(\\s*;)`);
const matchJson = downloadPage.match(patchVersionRegex);

// Return the version if found, otherwise return null
return match ? match[1] : null;
let versionsJsonString = matchJson ? matchJson[2] : null;

if (versionsJsonString == null) {
console.log(`No patch version could be extracted for potential label: ${potentialLabel}. Returning null.`);
return null;
}

console.log(`Patch Versions to fetch first element:`, versionsJsonString);
const extractFirstPatchVersionFromJson = new RegExp(`(\\"number\\":\\")(.*)(\\"\\,)`);
const matchFirstPatch = downloadPage.match(extractFirstPatchVersionFromJson);
let firstPatchVersion = matchFirstPatch ? matchFirstPatch[1] : null;

console.log(`The latest version is: ${firstPatchVersion}`);
return firstPatchVersion;
} catch (error) {
console.error("Error fetching the XML document:", error);
return null;
Expand Down Expand Up @@ -163959,7 +163979,6 @@ module.exports = async function () {
console.log(`Latest minor version: ${latestVersion}`);

const versionLabels = await getVersionLabels(potentialLabels, latestVersion);
console.log(versionLabels);

await setLabels(owner, repoName, issueNumber, versionLabels);
await removeLabels(owner, repoName, issueNumber, potentialLabels);
Expand Down
31 changes: 25 additions & 6 deletions common/src/set-version-labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = async function () {

const getVersionLabels = async function (potentialLabels, latestMinorVersion) {
const promises = potentialLabels.map(async potentialLabel => {

const minorVersion = getMinorFromPotentialLabel(potentialLabel);

if (minorVersion === latestMinorVersion) {
Expand All @@ -24,10 +25,10 @@ module.exports = async function () {
if (!latestPatchVersion) {
const calculatedVersionLabel = getVersionLabelFromPotential(potentialLabel); // fallback if GitHub is down, pom version is wrong, error at parsing
console.log(`No latest patch version found for potential label: ${potentialLabel}, returning calculated version ${calculatedVersionLabel}`);
return calculatedVersionLabel;
return getNextPatchVersion(calculatedVersionLabel);
}

return latestPatchVersion;
return getNextPatchVersion(calculatedVersionLabel);;
});

// Wait for all promises to settle and filter out null values
Expand Down Expand Up @@ -87,6 +88,12 @@ module.exports = async function () {
return match ? match[1] : null;
}

const getNextPatchVersion = function (currentVersion) {
const versionParts = currentVersion.split('.');
versionParts[2] = parseInt(versionParts[2]) + 1;
return versionParts.join('.');
}

const getLatestPatchVersion = async function (potentialLabel) {
console.log(`Get latest patch version for issue: #${issueNumber} for potential label:`, potentialLabel);
try {
Expand All @@ -99,11 +106,24 @@ module.exports = async function () {
console.log(`Minor version found: ${minorVersion}`);
}

const patchVersionRegex = new RegExp(`camDownloads\\.branches\\['${minorVersion}'\\]\\s*=\\s*\\[\\s*\\{\\s*number:\\s*'(\\d+\\.\\d+\\.\\d+)'`);
const match = downloadPage.match(patchVersionRegex);
const patchVersionRegex = new RegExp(`(camDownloads\\.branches\\['${minorVersion}'\\]\\s*=\\s*)(\\[[\\s\\S]*?\\])(\\s*;)`);
const matchJson = downloadPage.match(patchVersionRegex);

// Return the version if found, otherwise return null
return match ? match[1] : null;
let versionsJsonString = matchJson ? matchJson[2] : null;

if (versionsJsonString == null) {
console.log(`No patch version could be extracted for potential label: ${potentialLabel}. Returning null.`);
return null;
}

console.log(`Patch Versions to fetch first element:`, versionsJsonString);
const extractFirstPatchVersionFromJson = new RegExp(`(\\"number\\":\\")(.*)(\\"\\,)`);
const matchFirstPatch = downloadPage.match(extractFirstPatchVersionFromJson);
let firstPatchVersion = matchFirstPatch ? matchFirstPatch[1] : null;

console.log(`The latest version is: ${firstPatchVersion}`);
return firstPatchVersion;
} catch (error) {
console.error("Error fetching the XML document:", error);
return null;
Expand Down Expand Up @@ -187,7 +207,6 @@ module.exports = async function () {
console.log(`Latest minor version: ${latestVersion}`);

const versionLabels = await getVersionLabels(potentialLabels, latestVersion);
console.log(versionLabels);

await setLabels(owner, repoName, issueNumber, versionLabels);
await removeLabels(owner, repoName, issueNumber, potentialLabels);
Expand Down

0 comments on commit 9ac5a59

Please sign in to comment.