<commit_before>import {badRequest, notFound} from 'boom'
import Joi from 'joi'

import Project from '../models/project'
import Version from '../models/version'

let create = {
  validate: {
    params: {
      name: Joi.string().required()
    },
    payload: {
      version: Joi.string(),
      loc: Joi.number().integer().min(0),
      coverage: Joi.number().min(0),
      dependencies: {
        major: Joi.number().integer().min(0),
        minor: Joi.number().integer().min(0),
        upToDate: Joi.number().integer().min(0)
      },
      devDependencies: {
        major: Joi.number().integer().min(0),
        minor: Joi.number().integer().min(0),
        upToDate: Joi.number().integer().min(0)
      }
    }
  },
  handler: (request, reply) => {
    Project.find({ name: request.params.name }, (err, foundProject) => {
      if (err) return reply(badRequest(err))
      if (foundProject.length < 1) return reply(badRequest('Project not found.'))

      Version.find({
        name: request.params.name,
        version: request.payload.version
      }, (err, foundProjectVersion) => {
        if (err) return reply(badRequest(err))
        if (foundProjectVersion && foundProjectVersion.version === request.payload.version)
          return reply(badRequest('Details for that versions have been entered.'))

        let {coverage, dependencies, devDependencies, loc, version} = request.payload
        let toCreate = {
          name: request.params.name,
          version: version,
          loc: loc,
          coverage: coverage || 0,
          dependencies: {
            major: dependencies ? dependencies.major : 0,
            minor: dependencies ? dependencies.minor : 0,
            upToDate: dependencies ? dependencies.upToDate : 0
          },
          devDependencies: {
            major: devDependencies ? devDependencies.major : 0,
            minor: devDependencies ? devDependencies.minor : 0,
            upToDate: devDependencies ? devDependencies.upToDate : 0
          }
        }

        new Version(toCreate).save((err, newProjectVersion) => {
          if (err) return reply(badRequest(err))
          reply(newProjectVersion)
        })
      })
    })
  }
}

let del = {<commit_msg>Add version ids to project versions on version create<commit_after>import {badRequest, notFound} from 'boom'
import Joi from 'joi'

import Project from '../models/project'
import Version from '../models/version'

let create = {
  validate: {
    params: {
      name: Joi.string().required()
    },
    payload: {
      version: Joi.string(),
      loc: Joi.number().integer().min(0),
      coverage: Joi.number().min(0),
      dependencies: {
        major: Joi.number().integer().min(0),
        minor: Joi.number().integer().min(0),
        upToDate: Joi.number().integer().min(0)
      },
      devDependencies: {
        major: Joi.number().integer().min(0),
        minor: Joi.number().integer().min(0),
        upToDate: Joi.number().integer().min(0)
      }
    }
  },
  handler: (request, reply) => {
    Project.find({ name: request.params.name }, (err, foundProject) => {
      if (err) return reply(badRequest(err))
      if (foundProject.length < 1) return reply(badRequest('Project not found.'))

      Version.find({
        name: request.params.name,
        version: request.payload.version
      }, (err, foundProjectVersion) => {
        if (err) return reply(badRequest(err))
        if (foundProjectVersion && foundProjectVersion.version === request.payload.version)
          return reply(badRequest('Details for that versions have been entered.'))

        let {coverage, dependencies, devDependencies, loc, version} = request.payload
        let toCreate = {
          name: request.params.name,
          version: version,
          loc: loc,
          coverage: coverage || 0,
          dependencies: {
            major: dependencies ? dependencies.major : 0,
            minor: dependencies ? dependencies.minor : 0,
            upToDate: dependencies ? dependencies.upToDate : 0
          },
          devDependencies: {
            major: devDependencies ? devDependencies.major : 0,
            minor: devDependencies ? devDependencies.minor : 0,
            upToDate: devDependencies ? devDependencies.upToDate : 0
          }
        }

        new Version(toCreate).save((err, newProjectVersion) => {
          if (err) return reply(badRequest(err))

          Project.update(
            { name: newProjectVersion.name },
            { $push: { versions: newProjectVersion._id } }, (err) => {
              if (err) return reply(badRequest(err))
              reply(newProjectVersion)
            })
        })
      })
    })
  }
}

let del = {
{'fraction_non_alphanumeric': 0.13456632653061223, 'fraction_numerical': 0.006802721088435374, 'mean_word_length': 2.283321702721563, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1849494', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1299, 'n_words': 299}