My Trello Weekly Summary

I used to write a lot about Trello.  The API, how I use it, how my day-job teams were using it.  It’s been five years since I’ve said anything new.

A big part of that is that I haven’t been doing anything new.  I did a ton of Trello-related work in about a one-year period and then was done.  But I still use it every day and recently found a gap that I decided to close.

My personal Trello board has three columns.  “Not Started,” “In Progress,” and “Done.”  Pretty simple.

The “Done” column is the one I decided needed some help.

The “Done” column is important to me.  It’d be easy to not have one, simply archiving cards as they were completed.  I think it’s easy to get lost in a never-ending “Not Started” list without seeing the things that have been completed.  Instead, I have a process that runs nightly to archive cards over two months old, after they’ve had time to pass out of my mind.

I’ve been finding of late, though, that that’s not working for me.  I see the “Done” column, I know it’s there and that there’s a lot of stuff in it, but that’s what I’ve boiled it down to.  “A lot of stuff” that’s done and easy to ignore.

So I decided to add another automated process.  This one runs weekly and sends me a message via Slack, detailing how many cards I’ve completed in the last week.

I’m not doing this for analytics or anything.  I don’t have any goals to accomplish a certain number of tasks (they’re not estimated or anything so they’re all different sizes, anyway).  I just want to get another reminder in front of my face.  This one is a little disruptive, so maybe it’ll stick differently.


For the record, the following is the code for this new process (with a little obfuscation):

<?php
use cjrasmussen\SlackApi\SlackApi;
use cjrasmussen\TrelloApi\TrelloApi;

set_time_limit(120);

// ALLOW FOR SPECIFYING A TIME TO RUN FROM VIA THE COMMAND LINE
$time = null;
$options = getopt('', ['time:']);
extract($options, EXTR_OVERWRITE);

if (is_numeric($time)) {
	$check_time = (int)$time;
} elseif ($time) {
	$check_time = strtotime($time);
} else {
	$check_time = time();
}

$back_time = strtotime('-1 week', $check_time);

$trello = new TrelloApi($trello_key, $trello_secret);

// GET THE CARD DATA FOR THE COMPLETED LIST
$data = $trello->request('GET', ('/1/lists/' . $list_id . '/cards'));

$completed = [];
foreach ($data AS $card) {
	$recent_actions = $trello->request('GET',
		('/1/cards/' . $card->id . '/actions?filter=all&since=' . date('c', $back_time) . '&limit=1'));

	if (count($recent_actions)) {
		$start_timestamp = time();
		$all_actions = $trello->request('GET', ('/1/cards/' . $card->id . '/actions?filter=all'));
		foreach ($all_actions AS $action) {
			$timestamp = strtotime($action->date);
			if ($timestamp < $start_timestamp) {
				$start_timestamp = $timestamp;
			}
		}

		$labels = [];
		foreach ($card->labels AS $label) {
			$labels[] = $label->name;
		}

		$completed[] = [
			'title' => $card->name,
			'url' => $card->url,
			'labels' => $labels,
			'start_timestamp' => $start_timestamp,
			'end_timestamp' => strtotime($recent_actions[0]->date),
		];
	}
}

$blocks = [];
$blocks[] = (object)[
	'type' => 'header',
	'text' => (object)[
		'type' => 'plain_text',
		'text' => count($completed) . ' item' . ((count($completed) === 1) ? '' : 's') . ' completed in the last week',
	],
];

foreach ($completed AS $item) {
	$blocks[] = (object)[
		'type' => 'divider',
	];
	$blocks[] = (object)[
		'type' => 'section',
		'text' => (object)[
			'type' => 'mrkdwn',
			'text' => '<' . $item['url'] . '|' . $item['title'] . '>',
		],
	];
	$blocks[] = (object)[
		'type' => 'context',
		'elements' => [
			(object)[
				'type' => 'mrkdwn',
				'text' => '*Labels:* ' . implode(', ', $item['labels']),
			],
			(object)[
				'type' => 'mrkdwn',
				'text' => '*Started:* ' . date('n/j/Y g:i A', $item['start_timestamp']),
			],
			(object)[
				'type' => 'mrkdwn',
				'text' => '*Completed:* ' . date('n/j/Y g:i A', $item['end_timestamp']),
			],
		],
	];
}

$msg = [
	'blocks' => $blocks,
];
(new SlackApi($_ENV['config']['slack']['debug_webhook']))->sendMessage($msg);

This makes use of my TrelloApi and SlackApi helper classes.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.