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

dynamically resolves comments path #683

Merged
Merged
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
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
jonathansampson marked this conversation as resolved.
Show resolved Hide resolved
},
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
Loading