<commit_before>"use strict";

var express = require( "express" );
var router = express.Router();
var cvr = require( "cvr" );
var mongoose = require( "mongoose" );
var uuid = require( "uuid-lib" );

var auth = require( "../lib/auth" );
var models = require( "../lib/models" );

var dbConn = process.env.DB_CONN || require( "../local-settings.json" ).dbConn;
mongoose.connect( dbConn );

var host = process.env.HOST || require( "../local-settings.json" ).host;

var db = mongoose.connection;
db.on( "error", console.error.bind( console, "connection error:" ));
db.once( "open", function ( callback ) {
  // yay!
});

var lcov_fn_match = "^FN:[0-9]\\{1,\\},([a-zA-Z0-9_]\\{1,\\})$"
var gocover_match = "^[a-zA-Z/]\\{1,\\}\\.go:[0-9]\\{1,\\}\\.[0-9]\\{1,\\},[0-9]\\{1,\\}\\.[0-9]\\{1,\\} [0-9]\\{1,\\} [0-9]\\{1,\\}$"

router.get( "/", function ( req, res, next )
{
    res.render( "index", {
        layout: "layout.html",
        title: "CVR - Code Coverage",
        authed: req.isAuthenticated() });
} );

router.get( "/:owner/:name/shield.svg", function ( req, res, next )
{
    res.type( "image/svg+xml" );

    var onRepo = function ( err, repo )
    {
        if( !repo || err )
        {
            return res.status( 404 ).end();
        }

        cvr.getShield( repo.lastLinePercent, repo.minPassingLinePercent, function ( err, svg )
        {
            if( err )
            {
                console.log( err );
                return res.status( 503 ).end();
            }

            return res.send( svg );
        });
    };

    models.Repo.findByOwnerAndName( req.params.owner, req.params.name, onRepo );
});

router.get( "/upload", function( req, res, next )
{
    res.set( "Content-Type", "text/plain" );
    res.render( "upload", {
        lcov_regex: lcov_fn_match,
        gocov_regex: gocover_match,
        proto: req.protocol,
        host: req.hostname
    } )
} );

router.get( "/repos",
    auth.ensureAuthenticated,
    function ( req, res, next )
    {
        var username = req.session.user.profile.username;

        var onActiveRepos = function ( err, user, active )<commit_msg>JS is not Python<commit_after>"use strict";

var express = require( "express" );
var router = express.Router();
var cvr = require( "cvr" );
var mongoose = require( "mongoose" );
var uuid = require( "uuid-lib" );

var auth = require( "../lib/auth" );
var models = require( "../lib/models" );

var dbConn = process.env.DB_CONN || require( "../local-settings.json" ).dbConn;
mongoose.connect( dbConn );

var host = process.env.HOST || require( "../local-settings.json" ).host;

var db = mongoose.connection;
db.on( "error", console.error.bind( console, "connection error:" ));
db.once( "open", function ( callback ) {
  // yay!
});

var lcovFnMatch = "^FN:[0-9]\\{1,\\},([a-zA-Z0-9_]\\{1,\\})$"
var gocoverMatch = "^[a-zA-Z/]\\{1,\\}\\.go:[0-9]\\{1,\\}\\.[0-9]\\{1,\\},[0-9]\\{1,\\}\\.[0-9]\\{1,\\} [0-9]\\{1,\\} [0-9]\\{1,\\}$"

router.get( "/", function ( req, res, next )
{
    res.render( "index", {
        layout: "layout.html",
        title: "CVR - Code Coverage",
        authed: req.isAuthenticated() });
} );

router.get( "/:owner/:name/shield.svg", function ( req, res, next )
{
    res.type( "image/svg+xml" );

    var onRepo = function ( err, repo )
    {
        if( !repo || err )
        {
            return res.status( 404 ).end();
        }

        cvr.getShield( repo.lastLinePercent, repo.minPassingLinePercent, function ( err, svg )
        {
            if( err )
            {
                console.log( err );
                return res.status( 503 ).end();
            }

            return res.send( svg );
        });
    };

    models.Repo.findByOwnerAndName( req.params.owner, req.params.name, onRepo );
});

router.get( "/upload", function( req, res, next )
{
    res.set( "Content-Type", "text/plain" );
    res.render( "upload", {
        lcov_regex: lcovFnMatch,
        gocov_regex: gocoverMatch,
        proto: req.protocol,
        host: req.hostname
    } )
} );

router.get( "/repos",
    auth.ensureAuthenticated,
    function ( req, res, next )
    {
        var username = req.session.user.profile.username;

        var onActiveRepos = function ( err, user, active )
{'fraction_non_alphanumeric': 0.2067660279157795, 'fraction_numerical': 0.014667612964277266, 'mean_word_length': 2.282608695652174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '1626134', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1481, 'n_words': 315}