<commit_before>'use strict';

var app = angular.module('licker', ['ngRoute'])
    .config(function ($routeProvider) {
      $routeProvider
          .when('/', {
            templateUrl: 'views/table.html',
            controller: 'MainCtrl'
          })
          .otherwise('/');
    });

app.controller('mainCtrl', ['$scope', '$q', 'githubApiConnector', function ($scope, $q, githubApiConnector) {
  $scope.githubHandle = '';
  $scope.errorMessage = '';
  $scope.repositories = [];
  $scope.fetched_repositories = [];

  $scope.fetchRepos = function (apiPage, repositories) {
    var defaultResultLength = 30;
    var page = apiPage || 1;
    var repositories = repositories || [];

    githubApiConnector.fetchReposForUser($scope.githubHandle, page).
        success(function (data) {
          if (data.length > 0) {
            repositories = repositories.concat(data);
          }
          if (data.length == defaultResultLength) {
            $scope.fetchRepos(++page, repositories);
          } else{
            $scope.updateFetchedRepositories(repositories);
          }
        }).
        error(function (data, status) {
          if (status == 403) {
            $scope.errorMessage = 'Not able to get complete information: Github just allows you to make up to 60 requests per hour.';
          }
        });
  };

  $scope.checkLicenses = function () {
    $scope.fetched_repositories = [];
    $scope.repositories = [];
    $scope.fetchRepos();
  };

  $scope.updateFetchedRepositories = function (repositories) {
    $scope.fetched_repositories = repositories;
  };

  $scope.updateRepositories = function (repositories) {
    $scope.repositories = repositories;
  };

  $scope.$watch('fetched_repositories', function () {
    var repositories = [];
    angular.forEach($scope.fetched_repositories, function (repository) {
      githubApiConnector.getLicenseForRepo(repository).
          success(function (data) {
            repositories.push(data);
          }).
          error(function () {
            alert('error.')
          });
    });
    $scope.updateRepositories(repositories);
  });
}]);


app.factory('githubApiConnector', ['$http', function ($http) {
  var api = 'https://api.github.com';
  var page_parameter = '?page=';

  return {
    fetchReposForUser: function (githubHandle, page) {
      var user_repo_endpoint = api + '/users/' + githubHandle + '/repos' + page_parameter + page;
      var request = {
        method: 'GET',
        url: user_repo_endpoint,
        headers: {
          'Authorization': 'token <PASSWORD>'
        }
      };
      return $http(request);
    },
    fetchReposForOrganisation: function (githubHandle, page) {
      var organisation_repo_endpoint = api + '/orgs/' + githubHandle + '/repos' + page_parameter + page;
      var request = {
        method: 'GET',
        url: organisation_repo_endpoint,
        headers: {
          'Authorization': 'token <PASSWORD>'
        }
      };
      return $http(request);
    },
    getLicenseForRepo: function (repo) {
      var license_endpoint = api + '/repos/' + repo['full_name']
      var request = {
        method: 'GET',
        url: license_endpoint,
        headers: {
          'Accept': 'application/vnd.github.drax-preview+json',
          'Authorization': 'token <PASSWORD>'
        }<commit_msg>remove dead code.<commit_after>'use strict';

var app = angular.module('licker', ['ngRoute'])
    .config(function ($routeProvider) {
      $routeProvider
          .when('/', {
            templateUrl: 'views/table.html',
            controller: 'MainCtrl'
          })
          .otherwise('/');
    });

app.controller('mainCtrl', ['$scope', '$q', 'githubApiConnector', function ($scope, $q, githubApiConnector) {
  $scope.githubHandle = '';
  $scope.errorMessage = '';
  $scope.repositories = [];
  $scope.fetched_repositories = [];

  $scope.fetchRepos = function (apiPage, repositories) {
    var defaultResultLength = 30;
    var page = apiPage || 1;
    var repositories = repositories || [];

    githubApiConnector.fetchReposForUser($scope.githubHandle, page).
        success(function (data) {
          if (data.length > 0) {
            repositories = repositories.concat(data);
          }
          if (data.length == defaultResultLength) {
            $scope.fetchRepos(++page, repositories);
          } else{
            $scope.updateFetchedRepositories(repositories);
          }
        }).
        error(function (data, status) {
          if (status == 403) {
            $scope.errorMessage = 'Not able to get complete information: Github just allows you to make up to 60 requests per hour.';
          }
        });
  };

  $scope.checkLicenses = function () {
    $scope.fetched_repositories = [];
    $scope.repositories = [];
    $scope.fetchRepos();
  };

  $scope.updateFetchedRepositories = function (repositories) {
    $scope.fetched_repositories = repositories;
  };

  $scope.updateRepositories = function (repositories) {
    $scope.repositories = repositories;
  };

  $scope.$watch('fetched_repositories', function () {
    var repositories = [];
    angular.forEach($scope.fetched_repositories, function (repository) {
      githubApiConnector.getLicenseForRepo(repository).
          success(function (data) {
            repositories.push(data);
          }).
          error(function () {
            alert('error.')
          });
    });
    $scope.updateRepositories(repositories);
  });
}]);


app.factory('githubApiConnector', ['$http', function ($http) {
  var api = 'https://api.github.com';
  var page_parameter = '?page=';

  return {
    fetchReposForUser: function (githubHandle, page) {
      var user_repo_endpoint = api + '/users/' + githubHandle + '/repos' + page_parameter + page;
      var request = {
        method: 'GET',
        url: user_repo_endpoint
      };
      return $http(request);
    },
    getLicenseForRepo: function (repo) {
      var license_endpoint = api + '/repos/' + repo['full_name']
      var request = {
        method: 'GET',
        url: license_endpoint,
        headers: {
          'Accept': 'application/vnd.github.drax-preview+json'
        }
{'fraction_non_alphanumeric': 0.1414649991879162, 'fraction_numerical': 0.002923501705375995, 'mean_word_length': 2.5088319088319087, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 2, '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': '1811794', 'n_tokens_mistral': 1854, 'n_tokens_neox': 1743, 'n_words': 351}