Skip to content

Commit

Permalink
Merge tag '1.12.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
manginav committed Jul 17, 2024
2 parents 3f0993f + 54603c9 commit baec855
Show file tree
Hide file tree
Showing 8 changed files with 469 additions and 55 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ The script to create a new version: `npm run-script ans -- --version=x.xx.x crea

After running this, if you've created a new major or minor version, you'll need to update line 19 in this file so that the validate endpoint will work: `lib/validator.js`.

Make sure to also add a test file here: `tests/fixtures/schema/`. You can copy over the previous test file (`schema-tests-xx.js`) and rename it with your version number. When people open PRs for new schema changes, they can add tests to that file.
Make sure to also add a test file here: `tests/fixtures/schema/`. You can copy over the previous test file (`schema-tests-xx.js`) and rename it with your version number. When people open PRs for new schema changes, they can add tests to that file.
8 changes: 8 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# ANS Release Notes
### 1.12.2

* [PPA-825](https://arcpublishing.atlassian.net/browse/PPA-825) - fix a minor issue in previous 1.12.1

### 1.12.1

* [PPA-825](https://arcpublishing.atlassian.net/browse/PPA-825) - Fix version checking of unwanted types while upverting


### 1.12.0 2023/1/17

Expand Down
6 changes: 4 additions & 2 deletions lib/transform_utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

var _ = require('lodash');
var Version = require('./version')

var top_level_types = ["story", "video", "image", "gallery", "results", "audio", "redirect"];
var top_level_types = [ "audio", "collection", "content", "gallery", "image", "redirect", "results", "story", "video", "author", "section", "site"];
var recursion_keys = [ 'promo_items', 'related_content', 'content_elements' ];

// Given a version number, generates a function that sets input.version to that version number
Expand Down Expand Up @@ -32,8 +33,9 @@ var version_incrementer = function(new_version) {
});
}
});


if (_.has(ans, 'version') ||
if (_.has(ans, 'version') && Version.is_semantic_version(ans.version) &&
_.indexOf(top_level_types, _.get(ans, 'type')) > -1) {
return _.set(ans, 'version', new_version);
}
Expand Down
11 changes: 9 additions & 2 deletions lib/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ var doUpvert = function doUpvert(ans, version_to) {
return ans;
}

if(!version.is_semantic_version(version_from.str()) || !version.is_semantic_version(version_to.str())){
return ans
}

if (!version_from.lt(version_to)) {
throw new Error("Cannot upvert from " + version_from.str() +
" because it is not less than " + version_to.str());
Expand Down Expand Up @@ -101,15 +105,18 @@ var doSync = function doSync(document, version_to) {
!_.isNil(document.type)) {

//console.log("------This is a sub-document-----");
if(!version.is_semantic_version(version_to.str()) || !version.is_semantic_version(document.version)){
return document
}

var sub_doc_version = new Version(version.parse_version(document.version));

if (sub_doc_version.lt(version_to)) {
if (sub_doc_version.lt(version_to) && top_level_types.includes(document.type)) {
//console.log ("------Found lower version sub-doc, change requested version ------");
document = doSync(document, sub_doc_version);

//console.log("-----Upverting document to " + version_to.str() + "------");
document = doUpvert(document, version_to);
//console.log(JSON.stringify(document));

return document;
}
Expand Down
17 changes: 17 additions & 0 deletions lib/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ var parse_version = function parse_version(str) {
return version;
};

var is_semantic_version = function is_semantic_version(version_string) {
try {
var version = parse_version(version_string);
if (version &&
version.major !== null && version.major !== undefined && !isNaN(version.major) &&
version.minor !== null && version.minor !== undefined && !isNaN(version.minor) &&
version.patch !== null && version.patch !== undefined && !isNaN(version.patch)) {
return true;
}
} catch (err) {
return false;
}
return false;
};



var prev_version = function prev_version(version) {
var prev = null;
Expand Down Expand Up @@ -97,5 +113,6 @@ _module.parse_version = parse_version;
_module.prev_version = prev_version;
_module.Version = Version;
_module.indexOf = indexOf;
_module.is_semantic_version = is_semantic_version;

module.exports = _module;
Loading

0 comments on commit baec855

Please sign in to comment.