#!/usr/local/bin/node // npm install sync-request const request = require('sync-request'); const token = '' const url = 'https://phabricator.wikimedia.org/api/maniphest.search' const { URLSearchParams } = require('url'); const getClosedTasksForMonth = function(y, m) { const params = new URLSearchParams(); params.append('api.token', token); // Inuka Kanban Closed // https://phabricator.wikimedia.org/maniphest/query/5RJEk9J02nRH/ params.append('queryKey', '5RJEk9J02nRH'); params.append('constraints[closedStart]', Date.UTC(y, m-1, 1)/1000); // month is 0-based params.append('constraints[closedEnd]', Date.UTC(y, m, 0)/1000); const res = request('POST', url, { body: params.toString(), }); const result = JSON.parse(res.getBody('utf8')); return result.result.data } // format is [year, month] const months = [ [2020, 3], [2020, 4], [2020, 5], [2020, 6] ] // returns date like 2020-12-31 const formatDate = epoch => { const d = new Date(epoch*1000) return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + (d.getDate() < 10 ? '0' + d.getDate() : d.getDate()) } months.forEach(yearMonth => { const tasks = getClosedTasksForMonth(yearMonth[0], yearMonth[1]) // prints how many tasks were closed in the given month console.log(yearMonth, tasks.length) return tasks.forEach(task => { // prints the details of a closed task console.log([ formatDate(task.fields.dateClosed), 'T' + task.id, task.fields.name, task.fields.subtype, task.fields.status.name ].join("\t")) }) })