<commit_before>var mongoose = require('mongoose');
var https    = require('https');
var Repo     = mongoose.model('Repo');
var Users    = mongoose.model('Users');
var core     = require('../core.js');
var MACRO    = require('../model/macro.js');
var Notifications = mongoose.model('Notifications');


// Get user info stored in db
exports.user = function(req, res) {
  Users.findOne({'user_name': req.params.user }, function(err, user) {
    if (user)
      return res.json(user);
    else
      return res.json({
        err: true,
        msg: "User not found."
      })
  })
};


// Get logs for repo
exports.logs = function(req, res) {
  Users.findOne({'user_name': req.params.user }, function(err, user) {
    if (!user) return res.json({err: true, msg: "User not found."})

    for (r in user.repos) {
      if (user.repos[r].name == req.params.repo) {
        // Some bug makes zero points for some repos.
        // We have to recompute score here.
        if (user.repos[r].closed_pulls != 0) {
          pullrq_value = MACRO.USER.PULL + MACRO.USER.STAR * user.repos[r].stars
          total_points = user.repos[r].closed_pulls * pullrq_value
        } else {
          total_points = user.repos[r].points
        }

        return res.json({
          'name':     req.params.repo,
          'stars':    user.repos[r].stars,
          'pulls':    user.repos[r].closed_pulls,
          'points':   total_points,
          'watchers': user.repos[r].watchers_count * MACRO.USER.WATCH,
          'forks':    user.repos[r].forks_count * MACRO.USER.FORK
        })
      }
    }

    // Repo not ready yet
    return res.json({'name': null})
  })
}


// Get repos info
exports.repos = function(req, res) {

  // Use access token if user is logged in<commit_msg>Fix crashing app<commit_after>var mongoose = require('mongoose');
var https    = require('https');
var Repo     = mongoose.model('Repo');
var Users    = mongoose.model('Users');
var core     = require('../core.js');
var MACRO    = require('../model/macro.js');
var Notifications = mongoose.model('Notifications');


// Get user info stored in db
exports.user = function(req, res) {
  Users.findOne({'user_name': req.params.user }, function(err, user) {
    if (user)
      return res.json(user);
    else
      return res.json({
        err: true,
        msg: "User not found."
      })
  })
};


// Get logs for repo
exports.logs = function(req, res) {
  Users.findOne({'user_name': req.params.user }, function(err, user) {
    if (!user) return res.json({err: true, msg: "User not found."})

    for (r in user.repos) {
      if (user.repos[r].name == req.params.repo) {
        // Some bug makes zero points for some repos.
        // We have to recompute score here.
        if (user.repos[r].closed_pulls != 0) {
          pullrq_value = MACRO.USER.PULL + MACRO.USER.STAR * user.repos[r].stars
          total_points = user.repos[r].closed_pulls * pullrq_value
        } else {
          total_points = user.repos[r].points
        }

        return res.json({
          'name':     req.params.repo,
          'stars':    user.repos[r].stars,
          'pulls':    user.repos[r].closed_pulls,
          'points':   total_points,
          'watchers': user.repos[r].watchers_count * MACRO.USER.WATCH,
          'forks':    user.repos[r].forks_count * MACRO.USER.FORK
        })
      }
    }

    // Repo not ready yet
    return res.json({'name': null})
  })
}


// Get repos info
exports.repos = function(req, res) {

  if (req.params.user == 'faq' || req.params.user == 'contact') return

  // Use access token if user is logged in
{'fraction_non_alphanumeric': 0.15320566194837634, 'fraction_numerical': 0.0005550929780738274, 'mean_word_length': 2.3277931671283474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4687637', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1177, 'n_words': 283}