In the company I'm currently working we use Trello for managing the task of the programming team. Basically everybody has its own board and there are two extra boards: 'pending' and 'done'. Usually you have your list of things to be done in your list and the inputs are your bosses, clients calling or emailing you with some issues, etc. If the problem is something generic that everybody can do, you just put it on 'pending'. If there is just one person who can do the job, we assign the task to them.

And after a task is done, we just move it to 'done' (we have monthly 'done' lists).

However, our bosses want to have track of what has been done every day, and until now we just send an email with the small tasks requested directly by the client.

I, in the boredom of the evening have created this small script that monitors the 'done' list and generates a report with the new task added this day. A mail is being send afterwards with the report to our bosses.

The idea works like that. If you want to track a list called 'done October' you add a card with the word 'INFORME' (report, in Spanish; this can be adjusted).

After that, you start working and moving the task to the 'done October' list. When the day is over, with a cronjob we call the script below and it gets all the new cards, generating a report. The cards are blue labelled with the tag 'INFORME' to not be processed in the future.

The end result is something like:

Report of board 'Devel':
  Alice - Add the footer disclaimer at foo.example.com
  Bob - Called costumer XYZ to tell everything is in production
  Alice - Ask HR that we need an extra developer in our team

The code to do that is really straighforward:

<?php

require 'Trello/Trello.php';

define("REPORT_STARTS", "INFORME");

$key = '';
$token = '';


// Haven't figured out how variable scoping works and I'm using the fucking
// token 'global' everywhere in my code :/ I'll go to hell for that, I know
$usernames = [];


function get_user_name($id) {
    // This function caches the response of the name of the users to not
    // make too many requests for nothing
    global $trello, $usernames;
    if ( array_key_exists($id, $usernames))
        return $usernames[$id];

    $usernames[$id] = $trello->get("members/$id/fullName")->_value;
    return $usernames[$id];
}

function get_users_names($ids) {
    $result = [];
    foreach ($ids as $id)
        $result[] = get_user_name($id);
    return join(', ', $result);
}



function process_board($board) {

    global $trello;

    $cards = $trello->get("boards/$board->id/cards/visible");

    // Get the list we wanna track. It must start with "REPORT_STARTS"
    $lists_to_track = [];
    foreach ($cards as $card) {
        if (strpos($card->name, REPORT_STARTS) === 0) {
            $lists_to_track[] = $card->idList;
        }
    }

    // Set the blue label name for this board
    $trello->put("boards/$board->id/labelNames/blue", array('value' => REPORT_STARTS));

    $report = "";

    foreach ($cards as $card) {
        // If the card is not in the list_to_track, ignore it
        if (! in_array($card->idList, $lists_to_track))
            continue;

        // Ignore the REPORT card itself
        if (strpos($card->name, REPORT_STARTS) === 0)
            continue;

        // Search if the card has been already processed by looking its labels
        $already_labeled = false;
        foreach ($card->labels as $label) {
            if ($label->color === "blue") {
                $already_labeled = true;
                break;
            }
        }

        // If is a task that we have already processed, just skip it
        if ($already_labeled)
            continue;

        $report .= "  " . get_users_names($card->idMembers) . " - $card->name\n";
        //$trello->put("cards/$card->id/labels", array('value' => 'blue'));
    }

    if ($report === "") return $report;
    return "Report of board '$board->name':  \n$report\n\n";
}


$trello = new \Trello\Trello($key, null, $token);
$boards = $trello->members->get('my/boards');

$report = "";
foreach ($boards as $board) {
    $report .= process_board($board);
}

echo $report;

?>

All in all is really simple. You need, of course, to download the code to access to the API at mattzuba.bitbucket.org . I'll do a few more iterations on it and when ready I'll publish it on a bitbucket project.

If you have any question about it, do not hesitate in contacting me.

Regards, Jan.