MediaWiki:Gadget-BugStatusUpdate.js

/* * Bug Status Update Gadget * * Authors: * - Written by Rob Moen (robm). * - Ported to Phabricator by Matthew Flaschen (Mattflaschen (WMF)) * * Description: * - Finds and updates bug status templates on a page. * - Makes 1 JSONP request to phabricator-bug-status API (maintained by Matthew Flaschen) * - (which passes the request to Phabricator's Conduit API) * * Original source: mw:User:Robmoen/bugStatusUpdate.js * */

const target = 'https://phabricator-bug-status.toolforge.org/queryTasks';

$( => {	"use strict";	let ids = [];

// Get the Phabricator task id numbers on the page $('.mw-trackedTemplate').each( => {		let taskID = $(this).data("phabTask");		if (taskID !== null) {			ids.push(taskID);		}	}); // Do not query if no ids were found if (!ids.length) { return; }

// Make jsonp request $.ajax({		url: target,		dataType: 'jsonp',		timeout: 5000, // Give up if Tool Labs is being slow today		statusCode: {			500: => { /* Toolforge has failed, nothing to do here */ }		},		data: $.param({ids: JSON.stringify(ids)}),	}) .done(data => {		let phid, taskInfo;

// Loop over the tasks the server returned data for. for (phid in data) { taskInfo = data[phid];

// Loop over all instances of the template with this ID. $(".phab-T" + taskInfo.id).each( => {				$(this).find(".tracked-linktext").text(taskInfo.title);				let $status = $(this).find('.tracked-closure');				if ($status.length === 0) {					$status = $(' ')						.addClass('tracked-closure');					$(this).append($status);				}

// If a manual status gives the wrong class, remove it. if (taskInfo.status !== "resolved" && taskInfo.status !== "fixed") { $status.removeClass("tracked-resolved"); }				// Update the status element $status .addClass("phab-status-" + taskInfo.status) .text(taskInfo.statusName); });		}	}); });