<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var BugPuller = (function(code) {
  var _locale_code = code;
  var parent = $('#bugzilla');

  function getURL(suffix) {
    return 'https://api-dev.bugzilla.mozilla.org/1.3/' + suffix;
  }

  function getData() {
    return {
      'field0-0-0': 'component',
      'type0-0-0': 'regexp',
      'value0-0-0': '^' + _locale_code + ' / ',
      'field0-0-1': 'cf_locale',
      'type0-0-1': 'regexp',
      'value0-0-1': '^' + _locale_code + ' / ',
      'resolution': '---',
      'include_fields': 'id,last_change_time'
    };
  }

  function excuse() {
    $('.loading', parent).hide();
    $('.loaded', parent).hide();
    $('.failed', parent).show();
  }


  return {
    render: function(json) {

      json.bugs.sort(function(l, r) {
        return l.last_change_time < r.last_change_time ? 1 : -1;
      });

      function buglink(b, prop) {
        return '<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=' +
          b.id + '">' + b[prop] + '</a>';
      }

      var tbody = $('<tbody>');
      $.each(json.bugs, function(i, bug) {
        var tr = $('<tr>').addClass('treesummary');
        $('<td>')
          .append($(buglink(bug, 'id')))
          .appendTo(tr);

        $('<td>')
          .text(bug.summary)
          .appendTo(tr);

        $('<td>')
          .text(new Date(bug.last_change_time).toDateString())
          .appendTo(tr);

        $('<td>')
          .addClass('last-col')
          .text(new Date(bug.creation_time).toDateString())
          .appendTo(tr);

        tbody.append(tr);

      });

      // it's more effient to not attach this to the DOM until it's fully
      // populated
      tbody.appendTo($('table', parent));
      $('.loading', parent).hide();
      $('.table-pre-header', parent).fadeIn(300);
      $('table.recent-bugs:hidden', parent).fadeIn(300);
    },
    pre_render: function(json) {
      $('.recent-bugs', parent).hide();
      // update the count inline
      $('.bug-count', parent).text(json.bugs.length);
      $('.loaded', parent).fadeIn(300);

      if (json.bugs.length) {
        $('.loading', parent).show();

        json.bugs.sort(function(l, r) {
          return l.last_change_time < r.last_change_time ? 1 : -1;
        });

        var IDs = $.map(json.bugs.slice(0, 5), function(o) {
          return o.id;
        });

        var details = {
          'bug_id': IDs.join(','),
          'include_fields': 'id,summary,creation_time,last_change_time'
        };

        $.ajax({
           url: getURL('bug'),
          data: details,
          dataType: 'json',
          success: BugPuller.render,
          error: function(jqXHR, textStatus, errorThrown) {
            excuse();
          }
        });
      } else {
        // no bugs to fetch more details about
        // Mozilla is using bugs in Bugzilla to track
      }

    },
    pull: function() {
      $.ajax({
         url: getURL('bug'),
        data: getData(),
        dataType: 'json',<commit_msg>Fixes bug 1028709 - Migrate bugsy to the new bugzilla REST API. r=Pike<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var BugPuller = (function(code) {
  var _locale_code = code;
  var parent = $('#bugzilla');

  function getURL(suffix) {
    return 'https://bugzilla.mozilla.org/rest/' + suffix;
  }

  function getData() {
    return {
      'field0-0-0': 'component',
      'type0-0-0': 'regexp',
      'value0-0-0': '^' + _locale_code + ' / ',
      'field0-0-1': 'cf_locale',
      'type0-0-1': 'regexp',
      'value0-0-1': '^' + _locale_code + ' / ',
      'resolution': '---',
      'include_fields': 'id,last_change_time'
    };
  }

  function excuse() {
    $('.loading', parent).hide();
    $('.loaded', parent).hide();
    $('.failed', parent).show();
  }


  return {
    render: function(json) {

      json.bugs.sort(function(l, r) {
        return l.last_change_time < r.last_change_time ? 1 : -1;
      });

      function buglink(b, prop) {
        return '<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=' +
          b.id + '">' + b[prop] + '</a>';
      }

      var tbody = $('<tbody>');
      $.each(json.bugs, function(i, bug) {
        var tr = $('<tr>').addClass('treesummary');
        $('<td>')
          .append($(buglink(bug, 'id')))
          .appendTo(tr);

        $('<td>')
          .text(bug.summary)
          .appendTo(tr);

        $('<td>')
          .text(new Date(bug.last_change_time).toDateString())
          .appendTo(tr);

        $('<td>')
          .addClass('last-col')
          .text(new Date(bug.creation_time).toDateString())
          .appendTo(tr);

        tbody.append(tr);

      });

      // it's more effient to not attach this to the DOM until it's fully
      // populated
      tbody.appendTo($('table', parent));
      $('.loading', parent).hide();
      $('.table-pre-header', parent).fadeIn(300);
      $('table.recent-bugs:hidden', parent).fadeIn(300);
    },
    pre_render: function(json) {
      $('.recent-bugs', parent).hide();
      // update the count inline
      $('.bug-count', parent).text(json.bugs.length);
      $('.loaded', parent).fadeIn(300);

      if (json.bugs.length) {
        $('.loading', parent).show();

        json.bugs.sort(function(l, r) {
          return l.last_change_time < r.last_change_time ? 1 : -1;
        });

        var IDs = $.map(json.bugs.slice(0, 5), function(o) {
          return o.id;
        });

        var details = {
          'bug_id': IDs.join(','),
          'include_fields': 'id,summary,creation_time,last_change_time'
        };

        $.ajax({
          url: getURL('bug'),
          data: details,
          dataType: 'json',
          success: BugPuller.render,
          error: function(jqXHR, textStatus, errorThrown) {
            excuse();
          }
        });
      } else {
        // no bugs to fetch more details about
        // Mozilla is using bugs in Bugzilla to track
      }

    },
    pull: function() {
      $.ajax({
        url: getURL('bug'),
        data: getData(),
        dataType: 'json',
{'fraction_non_alphanumeric': 0.18377535101404055, 'fraction_numerical': 0.012948517940717628, 'mean_word_length': 2.0014044943820224, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 19, 'https://': 4, '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': '5921674', 'n_tokens_mistral': 2225, 'n_tokens_neox': 2080, 'n_words': 444}