<commit_before>'use strict'
const { google, facebook, github, oauthCallbacks, bitbucket, mailchimp } = require('./secrets');
const passport = require('passport');
const googleStrategy = require('passport-google-oauth20').Strategy
const gitHubStrategy = require('passport-github2').Strategy;
const bitbucketStrategy = require('passport-bitbucket-oauth20').Strategy;
const facebookStrategy = require('passport-facebook').Strategy;
const LocalStrategy = require('passport-local').Strategy;
const requestPromise = require('request-promise');

const BitbucketAPI = require('bitbucket-api-v2');
var githubAPI = require('octonode');

const userExist = require('../modules/users').userExists;
const userBuild = require('../modules/users').userBuilds;
const userUpdate = require('../modules/users').userUpdate;
const Promise = require('bluebird');

const jwt = require('jsonwebtoken');

const Mailchimp = require('mailchimp-api-v3');
const mc = new Mailchimp(mailchimp.apiKey);

const mailChimpConnect = (mail) => {
  mc.post(`/lists/${mailchimp.listId}/members`, {
    email_address : mail,
    status : 'subscribed'
  })
    .then(function(results) {
      console.log('mailchimp');
      console.log(results);
    })
    .catch(function (err) {
      console.log('mailchimp error');
      console.log(err)
    });
}

passport.serializeUser((user, done) => {
    done(null, user);
});

passport.deserializeUser((user, done) => {
  userExist(user)
    .then((user) => {
        done(null, user);
    });

});

passport.use(

    new googleStrategy({
            clientID: google.id,
            clientSecret: google.secret,
            callbackURL: oauthCallbacks.googleCallbackUrl
        },
        (accessToken, refreshToken, profile, done) => {
            process.nextTick(() => {

                const attributes = {
                    access_token: accessToken,
                    refresh_token: refreshToken
                };

                const data = {
                    provider: 'google',
                    social_id: profile.id,
                    profile: profile,
                    attribute: attributes,
                    email: profile.emails[0].value
                }

                userExist(data)
                    .then((user) => {

                        if (user){

                            userUpdate(data)
                                .then((user) => {
                                    return done(null, user);
                                }).catch((error) => {
                                    console.log("Error in passport.js configuration file");
                                    console.log(error);
                                    return done(null);
                                });

                        }else{

                            userBuild(data)
                                .then((user) => {
                                    return done(null, user);
                                }).catch((error) => {
                                    console.log("Error in passport.js configuration file");
                                    console.log(error);
                                    return done(null);
                                });
                        }

                    }).catch((error) => {
                        console.log("Error in passport.js configuration file - search users");
                        console.log(error);
                        return done(null);
                    });
            });

        })

);

passport.use(

    new facebookStrategy({
            clientID: facebook.id,
            clientSecret: facebook.secret,
            callbackURL: oauthCallbacks.facebookCallbackUrl
        },
        (accessToken, accessTokenSecret, profile, done) => {
            process.nextTick(() => {

                const attributes = {
                    access_token: accessToken,
                    access_token_secret: accessTokenSecret
                };

                const data = {
                    provider: 'facebook',
                    social_id: profile.id,
                    profile: profile,
                    attribute: attributes,
                    email: 'Checking a facebook setup'
                }

                userExist(data)
                    .then((user) => {

                        if(user){

                            userUpdate(data)
                                .then((user) => {
                                    return done(null, user);
                                }).catch((error) => {
                                    console.log("Error in passport.js configuration file");
                                    console.log(error);
                                    return done(null);
                                });

                        }else{

                            userBuild(data)
                                .then((user) => {
                                    return done(null, user);
                                }).catch((error) => {
                                    console.log("Error in passport.js configuration file");
                                    console.log(error);
                                    return done(null);
                                });
                        }

                    }).catch((error) => {
                        console.log("Error in passport.js configuration file - search users");
                        console.log(error);
                        return done(null);
                    });
            });

        })

);

passport.use(

  new gitHubStrategy({
      clientID: github.id,
      clientSecret: github.secret,
      callbackURL: oauthCallbacks.githubCallbackUrl
    },
    (accessToken, accessTokenSecret, profile, done) => {
      process.nextTick(() => {

        const attributes = {
          access_token: accessToken,
          access_token_secret: accessTokenSecret
        };

        const data = {
          provider: profile.provider,
          social_id: profile.id,
          name: profile.displayName,
          username: profile.username,
          picture_url: profile.photos[0].value,
          website: profile._json.blog,
          repos: 0,
          email: profile.emails.length ? profile.emails[0].value : profile._json.email
        }

        //const client = githubAPI.client(accessToken);

        requestPromise({
          uri: `https://api.github.com/users/${profile.username}/repos`,<commit_msg>trying to fix a bug when try to create a github account<commit_after>'use strict'
const { google, facebook, github, oauthCallbacks, bitbucket, mailchimp } = require('./secrets');
const passport = require('passport');
const googleStrategy = require('passport-google-oauth20').Strategy
const gitHubStrategy = require('passport-github2').Strategy;
const bitbucketStrategy = require('passport-bitbucket-oauth20').Strategy;
const facebookStrategy = require('passport-facebook').Strategy;
const LocalStrategy = require('passport-local').Strategy;
const requestPromise = require('request-promise');

const BitbucketAPI = require('bitbucket-api-v2');
var githubAPI = require('octonode');

const userExist = require('../modules/users').userExists;
const userBuild = require('../modules/users').userBuilds;
const userUpdate = require('../modules/users').userUpdate;
const Promise = require('bluebird');

const jwt = require('jsonwebtoken');

const Mailchimp = require('mailchimp-api-v3');
const mc = new Mailchimp(mailchimp.apiKey);

const mailChimpConnect = (mail) => {
  mc.post(`/lists/${mailchimp.listId}/members`, {
    email_address : mail,
    status : 'subscribed'
  })
    .then(function(results) {
      console.log('mailchimp');
      console.log(results);
    })
    .catch(function (err) {
      console.log('mailchimp error');
      console.log(err)
    });
}

passport.serializeUser((user, done) => {
    done(null, user);
});

passport.deserializeUser((user, done) => {
  userExist(user)
    .then((user) => {
        done(null, user);
    });

});

passport.use(

    new googleStrategy({
            clientID: google.id,
            clientSecret: google.secret,
            callbackURL: oauthCallbacks.googleCallbackUrl
        },
        (accessToken, refreshToken, profile, done) => {
            process.nextTick(() => {

                const attributes = {
                    access_token: accessToken,
                    refresh_token: refreshToken
                };

                const data = {
                    provider: 'google',
                    social_id: profile.id,
                    profile: profile,
                    attribute: attributes,
                    email: profile.emails[0].value
                }

                userExist(data)
                    .then((user) => {

                        if (user){

                            userUpdate(data)
                                .then((user) => {
                                    return done(null, user);
                                }).catch((error) => {
                                    console.log("Error in passport.js configuration file");
                                    console.log(error);
                                    return done(null);
                                });

                        }else{

                            userBuild(data)
                                .then((user) => {
                                    return done(null, user);
                                }).catch((error) => {
                                    console.log("Error in passport.js configuration file");
                                    console.log(error);
                                    return done(null);
                                });
                        }

                    }).catch((error) => {
                        console.log("Error in passport.js configuration file - search users");
                        console.log(error);
                        return done(null);
                    });
            });

        })

);

passport.use(

    new facebookStrategy({
            clientID: facebook.id,
            clientSecret: facebook.secret,
            callbackURL: oauthCallbacks.facebookCallbackUrl
        },
        (accessToken, accessTokenSecret, profile, done) => {
            process.nextTick(() => {

                const attributes = {
                    access_token: accessToken,
                    access_token_secret: accessTokenSecret
                };

                const data = {
                    provider: 'facebook',
                    social_id: profile.id,
                    profile: profile,
                    attribute: attributes,
                    email: 'Checking a facebook setup'
                }

                userExist(data)
                    .then((user) => {

                        if(user){

                            userUpdate(data)
                                .then((user) => {
                                    return done(null, user);
                                }).catch((error) => {
                                    console.log("Error in passport.js configuration file");
                                    console.log(error);
                                    return done(null);
                                });

                        }else{

                            userBuild(data)
                                .then((user) => {
                                    return done(null, user);
                                }).catch((error) => {
                                    console.log("Error in passport.js configuration file");
                                    console.log(error);
                                    return done(null);
                                });
                        }

                    }).catch((error) => {
                        console.log("Error in passport.js configuration file - search users");
                        console.log(error);
                        return done(null);
                    });
            });

        })

);

passport.use(

  new gitHubStrategy({
      clientID: github.id,
      clientSecret: github.secret,
      callbackURL: oauthCallbacks.githubCallbackUrl
    },
    (accessToken, accessTokenSecret, profile, done) => {
      process.nextTick(() => {

        const attributes = {
          access_token: accessToken,
          access_token_secret: accessTokenSecret
        };

        const data = {
          provider: profile.provider,
          social_id: profile.id,
          name: profile.displayName,
          username: profile.username,
          picture_url: profile.photos[0].value,
          website: profile._json.blog,
          repos: 0,
          email: profile.emails ? profile.emails[0].value : profile._json.email
        }

        //const client = githubAPI.client(accessToken);

        requestPromise({
          uri: `https://api.github.com/users/${profile.username}/repos`,
{'fraction_non_alphanumeric': 0.10846136207291905, 'fraction_numerical': 0.0016815715050064969, 'mean_word_length': 1.2323835522948303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1502197', 'n_tokens_mistral': 3174, 'n_tokens_neox': 2936, 'n_words': 580}