<commit_before>/** @jsx React.DOM */
var ReposContainer = React.createClass({
  getInitialState: function() {
    return {
      repos: [],
      reposLoaded: false,
      tableView: false,
      filters: {
        freshness: "all",
        issues: "all",
        pullRequests: "all"
      },
      organization: {
        name: ""
      },
      defaultOrganizationUsername: "firebase",
      gitHubPublicAccessToken: "<KEY>"
    };
  },

  getQueryStringParameterByName: function(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
    var results = regex.exec(location.search);
    return (results === null) ? "" : decodeURIComponent(results[1].replace(/\+/g, " ").replace(/\//, ""));
  },

  componentWillMount: function() {
    var organization = this.getQueryStringParameterByName("org") || this.state.defaultOrganizationUsername;
    this.getOrganizationNameAndIssues(organization);
  },

  getOrganizationNameAndIssues: function(organization) {
    if (organization !== "") {
      var _this = this;
      $.getJSON("https://api.github.com/orgs/" + organization, {
        access_token: this.state.gitHubPublicAccessToken
      }, function(organizationData) {
        _this.setState({
          organization: {
            name: organizationData.name
          }
        });

        _this.getIssuesForOrganization(organization);
      });
    }
  },

  getIssuesForOrganization: function(organization) {
    var _this = this;
    $.getJSON("https://api.github.com/orgs/" + organization + "/repos", {
      access_token: this.state.gitHubPublicAccessToken,
      per_page: 100
    }, function(repos) {
      // TODO: add pagination (https://developer.github.com/guides/traversing-with-pagination/)
      if (repos.length === 100) {
        alert("GitHub only returns 100 repos per page and this organization has over 100 repos so some will be missing. Pagination must be implemented.");
      }

      // Sort the repos alphabetically
      repos.sort(function(a, b) {
        if (a.name.toLowerCase() > b.name.toLowerCase()) {
          return 1;
        } else {
          return -1;
        }
      });

      _this.setState({
        repos: repos,
        reposLoaded: true
      });
    });
  },

  updateFreshnessFilter: function(event) {
    var updatedFilters = this.state.filters;
    updatedFilters.freshness = event.target.value;
    this.setState({
      filters: updatedFilters
    });
  },

  updateNumIssuesFilter: function(event) {
    var updatedFilters = this.state.filters;
    updatedFilters.issues = event.target.value;
    this.setState({
      filters: updatedFilters
    });
  },

  updateNumPullRequestsFilter: function(event) {
    var updatedFilters = this.state.value;
    updatedFilters.pullRequests = event.target.value;
    this.setState({<commit_msg>Fixed bug when filtering pull requests<commit_after>/** @jsx React.DOM */
var ReposContainer = React.createClass({
  getInitialState: function() {
    return {
      repos: [],
      reposLoaded: false,
      tableView: false,
      filters: {
        freshness: "all",
        issues: "all",
        pullRequests: "all"
      },
      organization: {
        name: ""
      },
      defaultOrganizationUsername: "firebase",
      gitHubPublicAccessToken: "<KEY>"
    };
  },

  getQueryStringParameterByName: function(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
    var results = regex.exec(location.search);
    return (results === null) ? "" : decodeURIComponent(results[1].replace(/\+/g, " ").replace(/\//, ""));
  },

  componentWillMount: function() {
    var organization = this.getQueryStringParameterByName("org") || this.state.defaultOrganizationUsername;
    this.getOrganizationNameAndIssues(organization);
  },

  getOrganizationNameAndIssues: function(organization) {
    if (organization !== "") {
      var _this = this;
      $.getJSON("https://api.github.com/orgs/" + organization, {
        access_token: this.state.gitHubPublicAccessToken
      }, function(organizationData) {
        _this.setState({
          organization: {
            name: organizationData.name
          }
        });

        _this.getIssuesForOrganization(organization);
      });
    }
  },

  getIssuesForOrganization: function(organization) {
    var _this = this;
    $.getJSON("https://api.github.com/orgs/" + organization + "/repos", {
      access_token: this.state.gitHubPublicAccessToken,
      per_page: 100
    }, function(repos) {
      // TODO: add pagination (https://developer.github.com/guides/traversing-with-pagination/)
      if (repos.length === 100) {
        alert("GitHub only returns 100 repos per page and this organization has over 100 repos so some will be missing. Pagination must be implemented.");
      }

      // Sort the repos alphabetically
      repos.sort(function(a, b) {
        if (a.name.toLowerCase() > b.name.toLowerCase()) {
          return 1;
        } else {
          return -1;
        }
      });

      _this.setState({
        repos: repos,
        reposLoaded: true
      });
    });
  },

  updateFreshnessFilter: function(event) {
    var updatedFilters = this.state.filters;
    updatedFilters.freshness = event.target.value;
    this.setState({
      filters: updatedFilters
    });
  },

  updateNumIssuesFilter: function(event) {
    var updatedFilters = this.state.filters;
    updatedFilters.issues = event.target.value;
    this.setState({
      filters: updatedFilters
    });
  },

  updateNumPullRequestsFilter: function(event) {
    var updatedFilters = this.state.filters;
    updatedFilters.pullRequests = event.target.value;
    this.setState({
{'fraction_non_alphanumeric': 0.14298108623980565, 'fraction_numerical': 0.0052056220718375845, 'mean_word_length': 2.638888888888889, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 6, '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': '211268', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1687, 'n_words': 322}