Skip to content

Commit a460c67

Browse files
authored
Merge pull request #284 from washingtonpost/PPA-825-rebase
PPA-825: fix ans-schema version for fixing upvert failures
2 parents 5cc2c78 + c635a86 commit a460c67

8 files changed

+383
-55
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,4 @@ The script to create a new version: `npm run-script ans -- --version=x.xx.x crea
167167

168168
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`.
169169

170-
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.
170+
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.

RELEASE_NOTES.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# ANS Release Notes
2+
### 1.12.1
3+
4+
* [PPA-825](https://arcpublishing.atlassian.net/browse/PPA-825) - Fix version checking of unwanted types while upverting
5+
26

37
### 1.12.0 2023/1/17
48

lib/transform_utils.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
22

33
var _ = require('lodash');
4+
var Version = require('./version')
45

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

89
// Given a version number, generates a function that sets input.version to that version number
@@ -32,8 +33,9 @@ var version_incrementer = function(new_version) {
3233
});
3334
}
3435
});
36+
3537

36-
if (_.has(ans, 'version') ||
38+
if (_.has(ans, 'version') && Version.is_semantic_version(ans.version) &&
3739
_.indexOf(top_level_types, _.get(ans, 'type')) > -1) {
3840
return _.set(ans, 'version', new_version);
3941
}

lib/transforms.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ var doUpvert = function doUpvert(ans, version_to) {
4141
return ans;
4242
}
4343

44+
if(!version.is_semantic_version(version_from.str()) || !version.is_semantic_version(version_to.str())){
45+
return ans
46+
}
47+
4448
if (!version_from.lt(version_to)) {
4549
throw new Error("Cannot upvert from " + version_from.str() +
4650
" because it is not less than " + version_to.str());
@@ -102,14 +106,16 @@ var doSync = function doSync(document, version_to) {
102106

103107
//console.log("------This is a sub-document-----");
104108
var sub_doc_version = new Version(version.parse_version(document.version));
109+
if(!version.is_semantic_version(version_to.str()) || !version.is_semantic_version(document.version)){
110+
return document
111+
}
105112

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

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

114120
return document;
115121
}

lib/version.js

+17
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ var parse_version = function parse_version(str) {
6666
return version;
6767
};
6868

69+
var is_semantic_version = function is_semantic_version(version_string) {
70+
try {
71+
var version = parse_version(version_string);
72+
if (version &&
73+
version.major !== null && version.major !== undefined && !isNaN(version.major) &&
74+
version.minor !== null && version.minor !== undefined && !isNaN(version.minor) &&
75+
version.patch !== null && version.patch !== undefined && !isNaN(version.patch)) {
76+
return true;
77+
}
78+
} catch (err) {
79+
return false;
80+
}
81+
return false;
82+
};
83+
84+
6985

7086
var prev_version = function prev_version(version) {
7187
var prev = null;
@@ -97,5 +113,6 @@ _module.parse_version = parse_version;
97113
_module.prev_version = prev_version;
98114
_module.Version = Version;
99115
_module.indexOf = indexOf;
116+
_module.is_semantic_version = is_semantic_version;
100117

101118
module.exports = _module;

0 commit comments

Comments
 (0)