function populateBugs()

in js/details.js [219:273]


function populateBugs(url, type, data) {
  if (!data || !data.bugs) {
    errorMsg('Response data was null. Unexpected error.');
    return;
  }
  data.bugs.forEach(function (bug) {
    // Grab the first needinfo id for this user. This is not perfect since
    // we can have multiple. If the user clears an ni using the helpers in
    // this page, only the first will get cleared. Maybe we can fix this up
    // later.
    let id = getUserId();
    let setter = 'unknown';
    let flagId, flagCreationDate, flagIdx = -1;
    for (let idx = 0; idx < bug.flags.length; idx++) {
      if (bug.flags[idx].name != 'needinfo') 
        continue;
      if (bug.flags[idx].requestee == id) {
        flagCreationDate = bug.flags[idx].creation_date;
        flagId = bug.flags[idx].id;
        flagIdx = idx;
        setter = bug.flags[idx].setter;
        break;
      }
    }

    if (flagIdx == -1) {
      errorMsg("Didn't find a flag that matched a needinfo we were looking for?? Bailing.");
      return true;
    }

    index = 0;
    let commentIdx = -1;
    bug.comments.every(function (comment) {
      if (flagCreationDate == comment.creation_time) {
        // when someone sets an ni without commenting, there won't be a comment to match here.
        // usually the right comment is the previous in the array (they forgot to set the ni when
        // submitting a comment) but lets not mess around with false positives here. leave it blank.
        //console.log(index, comment.creation_time, comment.creator);
        commentIdx = index;
        return false;
      }
      index++;
      return true;
    });

    if (commentIdx == -1) {
      processRow(flagCreationDate, bug.id, flagId, flagIdx, bug.assigned_to, bug.severity,
        bug.priority, bug.op_sys, bug.flags, "", 0, bug.summary, setter);
    } else {
      processRow(flagCreationDate, bug.id, flagId, flagIdx, bug.assigned_to, bug.severity,
        bug.priority, bug.op_sys, bug.flags, bug.comments[commentIdx].text, bug.comments[commentIdx].count,
        bug.summary, setter);
    }
  });
}