<commit_before>import { Router } from 'express'
import passport from 'passport'
import { Strategy } from 'passport-github'
import config from 'app-config-chain'

import findOrCreateUser from '../findOrCreateOAuth'
import md5 from '../md5'
import * as redirect from '../redirect'

const providerName = 'github'
const dataToUser = (data) => {
  console.log(data)
  return ({
    id: md5(`${providerName}-${data.id}`),
    name: data.name,
    email: data.email,
    lastLogin: Date.now(),

    [providerName]: {
      id: String(data.id),
      accessToken: data.accessToken
    }
  })
}

// init the passport junk
const strategyConfig = {
  clientID: config[providerName].id,
  clientSecret: config[providerName].secret,
  callbackURL: `/auth/${providerName}/callback`
}
const strategy = new Strategy(strategyConfig, findOrCreateUser(dataToUser))
passport.use(strategy)

// init the router
const start = passport.authenticate(providerName)
const callback = passport.authenticate(providerName, {
  failureRedirect: '/login'
})

const router = Router({ mergeParams: true })
router.get(`/auth/${providerName}/start`, redirect.pre, start)
router.get(`/auth/${providerName}/callback`, callback, redirect.post)

export default router<commit_msg>gh login<commit_after>import { Router } from 'express'
import passport from 'passport'
import { Strategy } from 'passport-github'
import config from 'app-config-chain'

import findOrCreateUser from '../findOrCreateOAuth'
import md5 from '../md5'
import * as redirect from '../redirect'

const providerName = 'github'
const dataToUser = (data) => ({
  id: md5(`${providerName}-${data.id}`),
  name: data.name,
  email: data.email,
  lastLogin: Date.now(),

  [providerName]: {
    id: String(data.id),
    accessToken: data.accessToken
  }
})

// init the passport junk
const strategyConfig = {
  clientID: config[providerName].id,
  clientSecret: config[providerName].secret,
  callbackURL: `/auth/${providerName}/callback`
}
const strategy = new Strategy(strategyConfig, findOrCreateUser(dataToUser))
passport.use(strategy)

// init the router
const start = passport.authenticate(providerName)
const callback = passport.authenticate(providerName, {
  failureRedirect: '/login'
})

const router = Router({ mergeParams: true })
router.get(`/auth/${providerName}/start`, redirect.pre, start)
router.get(`/auth/${providerName}/callback`, callback, redirect.post)

export default router
{'fraction_non_alphanumeric': 0.14008264462809916, 'fraction_numerical': 0.0024793388429752068, 'mean_word_length': 4.890510948905109, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '521444', 'n_tokens_mistral': 741, 'n_tokens_neox': 730, 'n_words': 184}