Skip to content

Commit

Permalink
dynamically resolves comments path (#683)
Browse files Browse the repository at this point in the history
Comments may be found in either ds:8 or ds:9 paths. This approach will check for expected fields in both paths before determine which path houses the comments themselves.
  • Loading branch information
jonathansampson authored Aug 8, 2024
1 parent f1ecd18 commit 60261ad
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const MAPPINGS = {
},
recentChanges: ['ds:5', 1, 2, 144, 1, 1],
comments: {
path: ['ds:8', 0],
path: [],
isArray: true,
fun: helper.extractComments
},
Expand Down
43 changes: 40 additions & 3 deletions lib/utils/mappingHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,46 @@ function buildHistogram (container) {
* Extract the comments from google play script array
* @param {array} comments The comments array
*/
function extractComments (comments) {
if (!comments) return [];
return comments.map(R.path([4])).slice(0, 5);
function extractComments (data) {
/**
* Comments have been found to migrate between two
* paths: ds:8 and ds:9. For this reason, we'll check
* for expected fields in both paths to determine
* the correct path to use.
*/
let comments = [];

for (const path of ['ds:8', 'ds:9']) {
const authorPath = [path, 0, 0, 1, 0];
const versionPath = [path, 0, 0, 10];
const datePath = [path, 0, 0, 5, 0];

/**
* This logic could be further improved by checking
* values like `version` and `date` against expected
* patterns for these values.
*/
if (R.path(authorPath, data)) {
if (R.path(versionPath, data)) {
if (R.path(datePath, data)) {
/**
* If we have found all expected fields, then
* we will dump the original comments structure
* into the `comments` variable for further
* handling.
*/
comments = R.path([path, 0], data);
break;
}
}
}
}

if (comments.length > 0) {
comments = comments.map(R.path([4])).slice(0, 5);
}

return comments;
}

function extractFeatures (featuresArray) {
Expand Down

0 comments on commit 60261ad

Please sign in to comment.