<commit_before>(function() {
  var handlebarsUrl = '//cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0-alpha.4/handlebars.amd.min',
    requirejsUrl = '//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js',
    commitStreamDomId,
    instanceId,
    digestId,
    workitem,
    getAssetAndChildNumbersUrl,
    apiKey,
    errorHandler,
    commitsContainerTmpl,
    commitsListTmpl,
    autoRefreshIntervalId,
    showChildrenChecked,
    children;

  var configureCommitStreamDependencies = function() {
    require.config({
      paths: {
        handlebars: handlebarsUrl
      }
    });
  };

  var deps = ['handlebars'];

  var hasAllDeps = function() {
    if (!window.requirejs) return false;
    for (var i = 0; i < deps.length; i++) {
      if (!requirejs.defined(deps[i])) return false;
    }
    return true;
  };

  var bindShowChildrenAction = function() {
    var el = $(commitStreamDomId);
    el.find('.toggle-cs-childrenasset').bind('click', function() {
      showChildrenChecked = $(this).is(':checked');
      if (showChildrenChecked) {
        queryCommitStream(getQueryWithChildrenUrl(), queryCallback);
      } else {
        queryCommitStream(getUrlToQuery(), queryCallback);
      }
    });
  };

  var bindRefreshActions = function() {
    var el = $(commitStreamDomId);
    el.find('.cs-refresh').unbind('click');
    el.find('.cs-refresh').bind('click', queryCommitStreamRefresh);
    el.find('.toggle-cs-autorefresh').unbind('click');
    el.find('.toggle-cs-autorefresh').bind('click', autoRefreshToggle);
    if (autoRefreshIntervalId) {
      el.find('.toggle-cs-autorefresh').prop('checked', true);
    }
  };

  var renderCommitsContainer = function(model) {
    try {
      if (!commitsContainerTmpl) {
        getCompiledTemplate('commitsList.html', function(tmpl) {
          commitsListTmpl = tmpl;
          registerPartial('commitsList', tmpl, function() {
            getCompiledTemplate('commitsContainer.html', function(tmpl) {
              commitsContainerTmpl = tmpl;
              var content = tmpl(model);
              $(commitStreamDomId).html(content);
              checkIfNextPage(model);
              bindRefreshActions();
              bindShowChildrenAction();
            });
          });
        });
      } else {
        var content = commitsContainerTmpl(model);
        $(commitStreamDomId).html(content);
        checkIfNextPage(model);
        bindRefreshActions();
        bindShowChildrenAction();
      }
    } catch (ex) {
      errorHandler();
    }
  };

  var renderCommitsList = function(model) {
    try {
      if (!commitsListTmpl) {
        getCompiledTemplate('commitsList.html', function(tmpl) {
          commitsListTmpl = tmpl;
          var content = tmpl(model);
          $(commitStreamDomId).find('.side-panel-scrollable').append(content);
          checkIfNextPage(model);
        });
      } else {
        var content = commitsListTmpl(model);
        $(commitStreamDomId).find('.side-panel-scrollable').append(content);
        checkIfNextPage(model);
      }
    } catch (ex) {
      errorHandler();
    }
  };

  var compileSource = function(source, cb) {
    require(deps, function(handlebars) {
      cb(handlebars.default.compile(source));
    }, errorHandler);
  };

  var registerPartial = function(partialName, template, cb) {
    require(deps, function(handlebars) {
      handlebars.default.registerPartial(partialName, template);
      cb();
    }, errorHandler);
  };

  var getTemplate = function(template, cb) {
    var tmplUrl = '{{{resourcePath}}}' + template;
    $.get(tmplUrl).done(cb).fail(errorHandler);
  };

  var getCompiledTemplate = function(template, cb) {
    getTemplate(template, function(source) {
      compileSource(source, cb);
    });
  };

  var configureModel = function(model) {
    model.noCommits = model.commits.length < 1;
    model.protocol = '{{{protocol}}}';
    model.resourcePath = '{{{resourcePath}}}';
    model.lastPage = false;
    model.showChildrenChecked = showChildrenChecked;
    if (!model._links || !model._links.next) {
      model.lastPage = true;
    }
  };

  var checkIfNextPage = function(model) {
    if (!model._links || !model._links.next) {
      $(commitStreamDomId).find('.side-panel-scrollable').attr('next', '');
      $(commitStreamDomId).find('.side-panel-scrollable').unbind('scroll');
    } else {
      $(commitStreamDomId).find('.side-panel-scrollable').attr('next', model._links.next);
      $(commitStreamDomId).find('.side-panel-scrollable').unbind('scroll');
      bindScrollEvent();
    }
  };

  var thereAreNoCommits = function(model) {
    return (!model || !model.commits);
  };

  var isEndOfScrollbar = function(el) {
    return (el.scrollTop() + el.innerHeight() >= el[0].scrollHeight);
  };

  var bindScrollEvent = function() {
    $(commitStreamDomId).find('.side-panel-scrollable').unbind('scroll');
    $(commitStreamDomId).find('.side-panel-scrollable').on('scroll', function() {
      if (isEndOfScrollbar($(this))) {
        queryCommitStream(getUrlToQuery(), function(model) {
          if (thereAreNoCommits(model)) {
            errorHandler();
          } else {
            configureModel(model);
            renderCommitsList(model);
          }
        });
      }
    });
  };

  var autoRefreshToggle = function() {
    var toggle = $(this);
    if (toggle.is(':checked')) {
      autoRefreshEnable();
    } else {
      autoRefreshDisable();
    }
  };

  var autoRefreshEnable = function() {
    if (autoRefreshIntervalId) {
      clearInterval(autoRefreshIntervalId);
    }
    autoRefreshIntervalId = setInterval(queryCommitStreamRefresh,
      window.CommitStream.autoRefreshIntervalInSeconds * 1000);
  };

  var autoRefreshDisable = function() {
    if (autoRefreshIntervalId) {
      clearInterval(autoRefreshIntervalId);
      autoRefreshIntervalId = undefined;
    }
  };

  var setCheckboxVisibility = function(model) {
    if (digestId) {
      model.showAutoRefreshCheckbox = true;
    }
  };

  var setChildrenCheckboxVisibility = function(model) {
    if (getAssetAndChildNumbersUrl) {
      model.showChildrenCheckbox = true;
    }
  };

  var getUrlToQuery = function() {
    showChildrenChecked = false;
    if ($(commitStreamDomId).find('.side-panel-scrollable').attr('next')) {
      return $(commitStreamDomId).find('.side-panel-scrollable').attr('next');
    } else if (workitem || digestId) {
      var url = '{{{apiUrl}}}' + instanceId;
      if (digestId !== null && digestId !== undefined) {
        url += '/digests/' + digestId + '/commits';
      } else {
        url += '/commits/tags/versionone/workitems/' + workitem;
      }

      url += '?apiKey=' + apiKey;
      return url;
    } else {
      throw 'Must specify either workitem or digestId as a URL query parameter in order to query CommitStream';
    }
  };

  var getQueryWithChildrenUrl = function() {
    var url = '{{{apiUrl}}}';
    url += instanceId;
    url += '/commits/tags/versionone/workitems/';
    url += workitem;
    url += children ? ',' + children.join() : '';
    url += '?apiKey=';
    url += apiKey;
    return url;
  };

  var queryCommitStream = function(apiUrl, cb) {
    var el = $(commitStreamDomId);
    el.find('.cs-refresh').addClass('requesting');
    $.getJSON(apiUrl).done(function(model) {
      el.find('.cs-refresh').removeClass('requesting');
      cb(model);
    }).fail(errorHandler);
  };

  var queryCallback = function(model) {
    if (thereAreNoCommits(model)) {
      errorHandler();
    } else {
      configureModel(model);
      setCheckboxVisibility(model);
      setChildrenCheckboxVisibility(model);
      renderCommitsContainer(model);
    }
  };

  var queryCommitStreamRefresh = function() {
    queryCommitStream(getUrlToQuery(), queryCallback);
  };

  var getChildren = function(url) {
    return $.get(url).done(function(children) {
      return children;
    }).fail(errorHandler);
  };

  var init = function() {
    var url = getUrlToQuery();
    if (!hasAllDeps()) {
      $.getScript(requirejsUrl, function(model, status, jqxhr) {
        configureCommitStreamDependencies();
        queryCommitStream(url, queryCallback);
      }).fail(errorHandler);
    } else {
      queryCommitStream(url, queryCallback);
    }
  };

  // Put a commitStream object in the global space
  if (!window.CommitStream) {
    window.CommitStream = {
      commitsDisplay: function(csDomId,
        wi,
        eh,
        dId,
        iId,
        aKey,
        assetAndChildUrl) {

        commitStreamDomId = csDomId;
        workitem = wi;
        errorHandler = eh;
        digestId = dId;
        instanceId = iId;
        apiKey = aKey;
        getAssetAndChildNumbersUrl = assetAndChildUrl;

        try {
          getChildren(getAssetAndChildNumbersUrl)
            .then(function(c) {
              children = c.assetNumbers;
            })
            .then(init);
        } catch (ex) {
          if (console && console.log) {
            console.log(ex);
          }
        }
      }
    };
    window.CommitStream.autoRefreshIntervalInSeconds = 30;
  }
})();<commit_msg>S-54935 prevent an extra call, it was made a call for other asset besides stories or deffects<commit_after>(function() {
  var handlebarsUrl = '//cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0-alpha.4/handlebars.amd.min',
    requirejsUrl = '//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js',
    commitStreamDomId,
    instanceId,
    digestId,
    workitem,
    getAssetAndChildNumbersUrl,
    apiKey,
    errorHandler,
    commitsContainerTmpl,
    commitsListTmpl,
    autoRefreshIntervalId,
    showChildrenChecked,
    children;

  var configureCommitStreamDependencies = function() {
    require.config({
      paths: {
        handlebars: handlebarsUrl
      }
    });
  };

  var deps = ['handlebars'];

  var hasAllDeps = function() {
    if (!window.requirejs) return false;
    for (var i = 0; i < deps.length; i++) {
      if (!requirejs.defined(deps[i])) return false;
    }
    return true;
  };

  var bindShowChildrenAction = function() {
    var el = $(commitStreamDomId);
    el.find('.toggle-cs-childrenasset').bind('click', function() {
      showChildrenChecked = $(this).is(':checked');
      if (showChildrenChecked) {
        queryCommitStream(getQueryWithChildrenUrl(), queryCallback);
      } else {
        queryCommitStream(getUrlToQuery(), queryCallback);
      }
    });
  };

  var bindRefreshActions = function() {
    var el = $(commitStreamDomId);
    el.find('.cs-refresh').unbind('click');
    el.find('.cs-refresh').bind('click', queryCommitStreamRefresh);
    el.find('.toggle-cs-autorefresh').unbind('click');
    el.find('.toggle-cs-autorefresh').bind('click', autoRefreshToggle);
    if (autoRefreshIntervalId) {
      el.find('.toggle-cs-autorefresh').prop('checked', true);
    }
  };

  var renderCommitsContainer = function(model) {
    try {
      if (!commitsContainerTmpl) {
        getCompiledTemplate('commitsList.html', function(tmpl) {
          commitsListTmpl = tmpl;
          registerPartial('commitsList', tmpl, function() {
            getCompiledTemplate('commitsContainer.html', function(tmpl) {
              commitsContainerTmpl = tmpl;
              var content = tmpl(model);
              $(commitStreamDomId).html(content);
              checkIfNextPage(model);
              bindRefreshActions();
              bindShowChildrenAction();
            });
          });
        });
      } else {
        var content = commitsContainerTmpl(model);
        $(commitStreamDomId).html(content);
        checkIfNextPage(model);
        bindRefreshActions();
        bindShowChildrenAction();
      }
    } catch (ex) {
      errorHandler();
    }
  };

  var renderCommitsList = function(model) {
    try {
      if (!commitsListTmpl) {
        getCompiledTemplate('commitsList.html', function(tmpl) {
          commitsListTmpl = tmpl;
          var content = tmpl(model);
          $(commitStreamDomId).find('.side-panel-scrollable').append(content);
          checkIfNextPage(model);
        });
      } else {
        var content = commitsListTmpl(model);
        $(commitStreamDomId).find('.side-panel-scrollable').append(content);
        checkIfNextPage(model);
      }
    } catch (ex) {
      errorHandler();
    }
  };

  var compileSource = function(source, cb) {
    require(deps, function(handlebars) {
      cb(handlebars.default.compile(source));
    }, errorHandler);
  };

  var registerPartial = function(partialName, template, cb) {
    require(deps, function(handlebars) {
      handlebars.default.registerPartial(partialName, template);
      cb();
    }, errorHandler);
  };

  var getTemplate = function(template, cb) {
    var tmplUrl = '{{{resourcePath}}}' + template;
    $.get(tmplUrl).done(cb).fail(errorHandler);
  };

  var getCompiledTemplate = function(template, cb) {
    getTemplate(template, function(source) {
      compileSource(source, cb);
    });
  };

  var configureModel = function(model) {
    model.noCommits = model.commits.length < 1;
    model.protocol = '{{{protocol}}}';
    model.resourcePath = '{{{resourcePath}}}';
    model.lastPage = false;
    model.showChildrenChecked = showChildrenChecked;
    if (!model._links || !model._links.next) {
      model.lastPage = true;
    }
  };

  var checkIfNextPage = function(model) {
    if (!model._links || !model._links.next) {
      $(commitStreamDomId).find('.side-panel-scrollable').attr('next', '');
      $(commitStreamDomId).find('.side-panel-scrollable').unbind('scroll');
    } else {
      $(commitStreamDomId).find('.side-panel-scrollable').attr('next', model._links.next);
      $(commitStreamDomId).find('.side-panel-scrollable').unbind('scroll');
      bindScrollEvent();
    }
  };

  var thereAreNoCommits = function(model) {
    return (!model || !model.commits);
  };

  var isEndOfScrollbar = function(el) {
    return (el.scrollTop() + el.innerHeight() >= el[0].scrollHeight);
  };

  var bindScrollEvent = function() {
    $(commitStreamDomId).find('.side-panel-scrollable').unbind('scroll');
    $(commitStreamDomId).find('.side-panel-scrollable').on('scroll', function() {
      if (isEndOfScrollbar($(this))) {
        queryCommitStream(getUrlToQuery(), function(model) {
          if (thereAreNoCommits(model)) {
            errorHandler();
          } else {
            configureModel(model);
            renderCommitsList(model);
          }
        });
      }
    });
  };

  var autoRefreshToggle = function() {
    var toggle = $(this);
    if (toggle.is(':checked')) {
      autoRefreshEnable();
    } else {
      autoRefreshDisable();
    }
  };

  var autoRefreshEnable = function() {
    if (autoRefreshIntervalId) {
      clearInterval(autoRefreshIntervalId);
    }
    autoRefreshIntervalId = setInterval(queryCommitStreamRefresh,
      window.CommitStream.autoRefreshIntervalInSeconds * 1000);
  };

  var autoRefreshDisable = function() {
    if (autoRefreshIntervalId) {
      clearInterval(autoRefreshIntervalId);
      autoRefreshIntervalId = undefined;
    }
  };

  var setCheckboxVisibility = function(model) {
    if (digestId) {
      model.showAutoRefreshCheckbox = true;
    }
  };

  var setChildrenCheckboxVisibility = function(model) {
    if (getAssetAndChildNumbersUrl) {
      model.showChildrenCheckbox = true;
    }
  };

  var getUrlToQuery = function() {
    showChildrenChecked = false;
    if ($(commitStreamDomId).find('.side-panel-scrollable').attr('next')) {
      return $(commitStreamDomId).find('.side-panel-scrollable').attr('next');
    } else if (workitem || digestId) {
      var url = '{{{apiUrl}}}' + instanceId;
      if (digestId !== null && digestId !== undefined) {
        url += '/digests/' + digestId + '/commits';
      } else {
        url += '/commits/tags/versionone/workitems/' + workitem;
      }

      url += '?apiKey=' + apiKey;
      return url;
    } else {
      throw 'Must specify either workitem or digestId as a URL query parameter in order to query CommitStream';
    }
  };

  var getQueryWithChildrenUrl = function() {
    var url = '{{{apiUrl}}}';
    url += instanceId;
    url += '/commits/tags/versionone/workitems/';
    url += workitem;
    url += children ? ',' + children.join() : '';
    url += '?apiKey=';
    url += apiKey;
    return url;
  };

  var queryCommitStream = function(apiUrl, cb) {
    var el = $(commitStreamDomId);
    el.find('.cs-refresh').addClass('requesting');
    $.getJSON(apiUrl).done(function(model) {
      el.find('.cs-refresh').removeClass('requesting');
      cb(model);
    }).fail(errorHandler);
  };

  var queryCallback = function(model) {
    if (thereAreNoCommits(model)) {
      errorHandler();
    } else {
      configureModel(model);
      setCheckboxVisibility(model);
      setChildrenCheckboxVisibility(model);
      renderCommitsContainer(model);
    }
  };

  var queryCommitStreamRefresh = function() {
    queryCommitStream(getUrlToQuery(), queryCallback);
  };

  var getChildren = function(url) {
    return $.get(url).done(function(children) {
      return children;
    }).fail(errorHandler);
  };

  var init = function() {
    var url = getUrlToQuery();
    if (!hasAllDeps()) {
      $.getScript(requirejsUrl, function(model, status, jqxhr) {
        configureCommitStreamDependencies();
        queryCommitStream(url, queryCallback);
      }).fail(errorHandler);
    } else {
      queryCommitStream(url, queryCallback);
    }
  };

  // Put a commitStream object in the global space
  if (!window.CommitStream) {
    window.CommitStream = {
      commitsDisplay: function(csDomId,
        wi,
        eh,
        dId,
        iId,
        aKey,
        assetAndChildUrl) {

        commitStreamDomId = csDomId;
        workitem = wi;
        errorHandler = eh;
        digestId = dId;
        instanceId = iId;
        apiKey = aKey;
        getAssetAndChildNumbersUrl = assetAndChildUrl;

        try {
          if(getAssetAndChildNumbersUrl) {
          getChildren(getAssetAndChildNumbersUrl)
            .then(function(c) {
              children = c.assetNumbers;
            })
            .then(init);
          } else {
            init();
          }
        } catch (ex) {
          if (console && console.log) {
            console.log(ex);
          }
        }
      }
    };
    window.CommitStream.autoRefreshIntervalInSeconds = 30;
  }
})();
{'fraction_non_alphanumeric': 0.14188822571893653, 'fraction_numerical': 0.002116115029842648, 'mean_word_length': 2.727199191102123, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4200484', 'n_tokens_mistral': 5589, 'n_tokens_neox': 5468, 'n_words': 931}