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

Concatenate multiple releases notes for all versions past the sent version #5

Merged
merged 1 commit into from Jan 19, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -3,7 +3,7 @@ let Joi = require('joi')
let common = require('../common')
let _ = require('underscore')

// valid platform identifiers
// Valid platform identifiers
exports.platforms = ['winx64', 'osx']

let commonValidator = {
@@ -13,14 +13,14 @@ let commonValidator = {
}
}

// modify the release to be returned to the client
// Modify the release to be returned to the client
let responseFormatter = (release) => {
let response = _.clone(release)
delete response.comparable_version
return response
}

// build a usage object is query parameters passed in
// Build a usage object if query parameters passed in
let buildUsage = (request) => {
if (request.query.daily) {
return {
@@ -33,6 +33,11 @@ let buildUsage = (request) => {
}
}

// Build release notes from multiple versions greater than the passed in version number
let buildReleaseNotes = (potentials) => {
return potentials.map((release) => release.notes).join('\n\n')
}

exports.setup = (runtime, releases) => {
/*
@@ -47,36 +52,38 @@ exports.setup = (runtime, releases) => {
*/

// find the latest release for this platform AFTER the version passed to this handler
// Find the latest release for this platform AFTER the version passed to this handler
let get = {
method: 'GET',
path: '/1/releases/{platform}/{version}',
config: {
handler: function (request, reply) {
// integer version for comparison
// Integer version for comparison
let cv = common.comparableVersion(request.params.version)

console.log(cv)

// build the usage record (for Mongo)
// Build the usage record (for Mongo)
let usage = buildUsage(request)

// potential releases
// Potential releases
let potentials = _.filter(
releases[request.params.platform],
(rel) => rel.comparable_version > cv
)

let targetRelease = null
if (!_.isEmpty(potentials)) {
// most current release
targetRelease = _.max(
// Most current release
targetRelease = _.clone(_.max(
potentials,
(rel) => rel.comparable_version
)
))
// Concatenate the release notes for all potential updates
targetRelease.notes = buildReleaseNotes(potentials)
}

// insert usage record if not null
// Insert usage record if not null
runtime.mongo.models.insertUsage(usage, (err, results) => {
assert.equal(err, null)
request.log([], 'get')
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.