Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Dev Pipeline - factor out the ranking function #1326

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 69 additions & 61 deletions src/js/ia/IADevPipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,74 +458,82 @@
return parseInt(moment().diff(date, "days", true));
}

// Priority is higher when:
// - last activity (especially comment) is by a contributor (non-admin)
// - last activity happened long ago (the older the activity, the higher the priority)
function rank_ia(ia) {
var score_last_comment, score_elapsed_time, score_tags, score_mention = 0;

if (ia.pr && (ia.pr.status === "open")) {
if (ia.last_comment) {
// Last comment
var idle_comment = elapsed_time(ia.last_comment.date);
if (ia.last_comment.admin) {
score_last_comment = -20;
score_elapsed_time = idle_comment;
ia.priority_msg += "- 20 (last comment by admin) \n+ elapsed time since last comment \n";
} else {
score_last_comment = 20;
score_elapsed_time = (2 * idle_comment);
ia.priority_msg += "+ 20 (last comment by contributor) \n+ twice the elapsed time since last comment \n";
}
}

if (ia.last_commit) {
// Last commit
var idle_commit = elapsed_time(ia.last_commit.date);
if (ia.last_comment && moment.utc(ia.last_comment.date).isBefore(ia.last_commit.date)) {
score_elapsed_time += (1.5 * idle_commit);
ia.priority_msg += "+ 1.5 times the elapsed time since last commit (made after last comment) \n";
} else if ((!ia.last_comment) && (!ia.last_commit.admin)) {
score_elapsed_time += (2 * idle_commit);
ia.priority_msg += "+ twice the elapsed time since last commit (there are no comments in the PR) \n";
}
}

// Priority drops if the PR is on hold
if (ia.pr && (ia.pr.status === "open")) {
var tags = ia.pr.tags;

$.each(tags, function(idx) {
var tag = tags[idx];
if (tag.name.toLowerCase() === "on hold") {
score_tags = -100;
ia.priority_msg += "- 100: the PR is on hold \n";
} else if (tag.name.toLowerCase() === "priority: high") {
score_tags = 20;
ia.priority_msg += "+ 20: the PR is high priority \n";
}
});
}

// Priority is higher if the user was mentioned in the last comment
if (ia.at_mentions && ia.at_mentions.indexOf(dev_p.data.username) !== -1) {
score_mention = 50;
ia.priority_msg += "+ 50: you have been @ mentioned in the last comment \n";
}

ia.priority_val = score_last_comment + score_elapsed_time + score_tags + score_mention;

// Has a PR, so it still has more priority than IAs which don't have one
if (ia.priority_val <= 0) {
ia.priority_val = 1;
ia.priority_msg += "final value is 1: there's a PR, so it's higher priority than IAs without a PR \n";
}
}

return ia;
}

// Sort each milestone array by priority
function sort_pipeline() {
$.each(dev_p.data.dev_milestones, function (key, val) {
$.each(dev_p.data.dev_milestones[key], function (temp_ia) {
var priority_val = 0;
var priority_msg = '';


var ia = dev_p.data.dev_milestones[key][temp_ia];

if (dev_p.by_priority) {
// Priority is higher when:
// - last activity (especially comment) is by a contributor (non-admin)
// - last activity happened long ago (the older the activity, the higher the priority)
if (ia.pr && (ia.pr.status === "open")) {
if (ia.last_comment) {
priority_val += ia.last_comment.admin? -20 : 20;
var idle_comment = elapsed_time(ia.last_comment.date);
if (ia.last_comment.admin) {
priority_val -= 20;
priority_val += idle_comment;
priority_msg += "- 20 (last comment by admin) \n+ elapsed time since last comment \n";
} else {
priority_val += 20;
priority_val += (2 * idle_comment);
priority_msg += "+ 20 (last comment by contributor) \n+ twice the elapsed time since last comment \n";
}
} if (ia.last_commit) {
var idle_commit = elapsed_time(ia.last_commit.date);
if (ia.last_comment && moment.utc(ia.last_comment.date).isBefore(ia.last_commit.date)) {
priority_val += (1.5 * idle_commit);
priority_msg += "+ 1.5 times the elapsed time since last commit (made after last comment) \n";
} else if ((!ia.last_comment) && (!ia.last_commit.admin)) {
priority_val += (2 * idle_commit);
priority_msg += "+ twice the elapsed time since last commit (there are no comments in the PR) \n";
}
}

// Priority drops if the PR is on hold
if (ia.pr && (ia.pr.status === "open")) {
var tags = ia.pr.tags;

$.each(tags, function(idx) {
var tag = tags[idx];
if (tag.name.toLowerCase() === "on hold") {
priority_val -= 100;
priority_msg += "- 100: the PR is on hold \n";
} else if (tag.name.toLowerCase() === "priority: high") {
priority_val += 20;
priority_msg += "+ 20: the PR is high priority \n";
}
});
}

// Priority is higher if the user has been mentioned in the last comment
if (ia.at_mentions && ia.at_mentions.indexOf(dev_p.data.username) !== -1) {
priority_val += 50;
priority_msg += "+ 50: you have been @ mentioned in the last comment \n";
}

// Has a PR, so it still has more priority than IAs which don't have one
if (priority_val <= 0) {
priority_val = 1;
priority_msg += "final value is 1: there's a PR, so it's higher priority than IAs without a PR \n";
}
}

dev_p.data.dev_milestones[key][temp_ia].priority = priority_val;
dev_p.data.dev_milestones[key][temp_ia].priority_msg = priority_msg;
dev_p.data.dev_milestones[key][temp_ia] = rank_ia(ia);
}
});

Expand Down