Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare all versions from nuget.org service #22

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions CHANGELOG.md

This file was deleted.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/security-devops-azdevops-task-lib",
"version": "1.7.2",
"version": "1.8.0",
"description": "Microsoft Security DevOps for Azure DevOps task library.",
"author": "Microsoft Corporation",
"license": "MIT",
Expand Down
139 changes: 113 additions & 26 deletions src/msdo-nuget-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,50 +228,137 @@ async function _resolveVersion(
let result = await requestJson(searchQueryServiceUrlWithQuery, requestOptions);
const findPreRelease = common.isLatestPreRelease(packageVersion);

resolvedVersion = findLatestVersion(result, findPreRelease);

if (resolvedVersion == null) {
throw new Error(`Package not found: ${packageName}`);
}

return resolvedVersion;
}

/**
* Finds the latest version in a SearchQueryService response.
*
* @param result A JSON object returned from the SearchQueryService
* @param findPreRelease Whether or not to find a pre-release version
* @returns The latest version of the package
*/
function findLatestVersion(
result: object,
findPreRelease: boolean): string {
let latestVersion = null;
let latestVersionParts = null;
let latestIsPreRelease = false;
let latestPreReleaseFlag = null;

if (result == null || result['items'] == null) {
return latestVersion;
}

let currentCatalogEntry = null;
let currentVersion = null;
let currentVersionParts = null;
let currentFullVersionParts = null;
let currentVersionNumbersString = null;
let currentIsLatest = false;
let currentIsPreRelease = false;
let currentPreReleaseFlag = null;

for (let packageGroup of result['items']) {
for (let packageInfo of packageGroup['items']) {
let catalogEntry = packageInfo['catalogEntry'];
if (catalogEntry['listed'] != true) {
currentCatalogEntry = packageInfo['catalogEntry'];

if (currentCatalogEntry['listed'] != true) {
// skip delisted packages
continue;
}

if (!findPreRelease && common.isPreRelease(catalogEntry['version'])) {
currentVersion = currentCatalogEntry['version'];
currentIsPreRelease = common.isPreRelease(currentVersion);

if (!findPreRelease && currentIsPreRelease) {
// skip prerelease packages if we're looking for a stable version
continue;
}

resolvedVersion = catalogEntry['version'];
break;
}
currentFullVersionParts = currentVersion.split("-");
if (currentIsPreRelease) {
currentPreReleaseFlag = currentFullVersionParts[1];
}

if (resolvedVersion != null) {
break;
}
}

if (resolvedVersion == null) {
throw new Error(`Package not found: ${packageName}`);
}
currentVersionNumbersString = currentFullVersionParts[0];
currentVersionParts = currentVersionNumbersString.split(".");
currentIsLatest = latestVersion == null;

return resolvedVersion;
}
if (!currentIsLatest) {
// Evaluate the current version against the latest version

// Handle comparisons of separate level versions
// Some packages exclude Patch or include Revisions up to two levels (Rev1 and Rev2)
let maxVersionParts = currentVersionParts.length;
if (currentVersionParts.length < maxVersionParts) {
maxVersionParts = latestVersionParts.length;
}

function rampedDeployment(
datetime: Date,
rampMinutes: number): boolean {
let ramped = false;
for (let versionPartIndex = 0; versionPartIndex < currentVersionParts.length; versionPartIndex++) {
let versionPart = 0;
let latestVersionPart = 0;

let curDate = new Date();
let isLastVersionPart = versionPartIndex == (maxVersionParts - 1);

let diff = curDate.getTime() - datetime.getTime();
if (versionPartIndex < currentVersionParts.length) {
versionPart = parseInt(currentVersionParts[versionPartIndex]);
}

datetime.setMinutes


return Math.random() > diff;
if (versionPartIndex < latestVersionParts.length) {
latestVersionPart = parseInt(latestVersionParts[versionPartIndex]);
}

if (versionPart > latestVersionPart) {
currentIsLatest = true;
} else if (versionPart == latestVersionPart) {
currentIsLatest = isLastVersionPart
&&
(
(currentIsPreRelease && latestIsPreRelease && currentPreReleaseFlag > latestPreReleaseFlag)
||
(!currentIsPreRelease && latestIsPreRelease)
);
} else {
// Current version is less than latest found
break;
}

if (currentIsLatest) {
break;
}
}
}

if (currentIsLatest) {
latestVersion = currentVersion;
latestVersionParts = currentVersionParts;
latestIsPreRelease = currentIsPreRelease;
latestPreReleaseFlag = currentPreReleaseFlag;
}
}
}

tl.debug(`latestVersion = ${latestVersion}`);
return latestVersion;
}

// function rampedDeployment(
// datetime: Date,
// rampMinutes: number): boolean {
// let ramped = false;
// let curDate = new Date();
// let diff = curDate.getTime() - datetime.getTime();
// datetime.setMinutes
// return Math.random() > diff;
// }

/**
* Top level service call to download a package from a NuGet server.
*
Expand Down
Loading