<commit_before>// Gimme a Github object! Please.
function github() {
  return new Github({
    token: $.cookie('oauth-token'),
    auth: "oauth"
  });
}

// Authentication
// -------

function authenticate() {
  if ($.cookie("oauth-token")) return window.authenticated = true;
  var match = window.location.href.match(/\?code=(.*)/);

  // Handle Code
  if (match) {
    var code = match[1];
    $.getJSON('{{site.gatekeeper_url}}/authenticate/'+match[1], function(data) {
      $.cookie('oauth-token', data.token);
      window.authenticated = true;
      window.location.href = window.location.href.replace(/\?code=(.*)/, '');
    });
  }
}


function logout() {
  window.authenticated = false;
  $.cookie("oauth-token", null);
}

// Load Application
// -------
// 
// Load everything that's needed for the app + header


function loadApplication(cb) {

  if (window.authenticated) {
    $.ajax({
      type: "GET",
      url: 'https://api.github.com/user',
      dataType: 'json',
      contentType: 'application/x-www-form-urlencoded',
      success: function(res) { 
        $.cookie("avatar", res.avatar_url);
        app.username = res.login;
        var user = github().getUser(app.username);
        var owners = {};

        user.repos(function(err, repos) {
          _.each(repos, function(r) {
            owners[r.owner.login] = owners[r.owner.login] ? owners[r.owner.login].concat([r])
                                                          : [r];
          });
          cb(null, { "available_repos": repos, "owners": owners });<commit_msg>Parameterize Github wrapper with the username, so commits are attributed by the user explicitly. Closes #60.<commit_after>// Gimme a Github object! Please.
function github() {
  return new Github({
    token: $.cookie('oauth-token'),
    username: $.cookie('username'),
    auth: "oauth"
  });
}

// Authentication
// -------

function authenticate() {
  if ($.cookie("oauth-token")) return window.authenticated = true;
  var match = window.location.href.match(/\?code=(.*)/);

  // Handle Code
  if (match) {
    var code = match[1];
    $.getJSON('{{site.gatekeeper_url}}/authenticate/'+match[1], function(data) {
      $.cookie('oauth-token', data.token);
      window.authenticated = true;
      window.location.href = window.location.href.replace(/\?code=(.*)/, '');
    });
  }
}


function logout() {
  window.authenticated = false;
  $.cookie("oauth-token", null);
}

// Load Application
// -------
// 
// Load everything that's needed for the app + header


function loadApplication(cb) {

  if (window.authenticated) {
    $.ajax({
      type: "GET",
      url: 'https://api.github.com/user',
      dataType: 'json',
      contentType: 'application/x-www-form-urlencoded',
      success: function(res) { 
        $.cookie("avatar", res.avatar_url);
        $.cookie("username", res.login);
        app.username = res.login;

        var user = github().getUser(app.username);
        var owners = {};

        user.repos(function(err, repos) {
          _.each(repos, function(r) {
            owners[r.owner.login] = owners[r.owner.login] ? owners[r.owner.login].concat([r])
                                                          : [r];
          });
          cb(null, { "available_repos": repos, "owners": owners });
{'fraction_non_alphanumeric': 0.18079611060467943, 'fraction_numerical': 0.0018231540565177757, 'mean_word_length': 2.372950819672131, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5171854', 'n_tokens_mistral': 1047, 'n_tokens_neox': 993, 'n_words': 209}