llvmbot monitor: Add "Build In Progress" column

This column tells you if there is a newer build than the reported
last finished build. This is useful when that reported build has
been cancelled or was a long time ago.

If there's a build in progress, fine, if not, we may need to restart
the agent.

I'm assuming that 'complete' will be True even for a build
that was cancelled or otherwise failed. The docs aren't super
clear on that.

https://docs.buildbot.net/latest/developer/raml/build.html

This column is not coloured red or green because it's up to
the bot maintainer to decide if there being a running build
is required.

Flang hasn't build in a few hours? Fine, it's a low traffic
project. armv8-quick had a cancelled build 2 hours ago and has
no running build? Time to investigate.

Change-Id: I00a49772febe11659e1687b097daf6c9f9651012
diff --git a/monitor/bot-status.py b/monitor/bot-status.py
index 759e499..57b32b9 100755
--- a/monitor/bot-status.py
+++ b/monitor/bot-status.py
@@ -71,28 +71,33 @@
       return {'valid': False}
 
   reversed_builds = iter(sorted(builds['builds'], key=lambda b: -b["number"]))
+  next_build = None
   for build in reversed_builds:
-    if build['complete']:
-      time_since = (int(datetime.now().timestamp()) - int(build['complete_at']))
-      duration = int(build['complete_at']) - int(build['started_at'])
-      agent_url = "{}/#/{}/{}".format(base_url, builder_url, build['builderid'])
+    if not build['complete']:
+      next_build = build
+      continue
 
-      status = {
-        'builder_url': agent_url,
-        'number': build['number'],
-        'build_url':  "{}/builds/{}".format(agent_url, build['number']),
-        'state': build['state_string'],
-        'time_since': timedelta(seconds=time_since),
-        'duration': timedelta(seconds=duration),
-        'fail': build['state_string'] != 'build successful',
-      }
+    time_since = (int(datetime.now().timestamp()) - int(build['complete_at']))
+    duration = int(build['complete_at']) - int(build['started_at'])
+    agent_url = "{}/#/{}/{}".format(base_url, builder_url, build['builderid'])
 
-      if status['fail']:
-        buildid = build['buildid']
-        status['steps'] = list(get_bot_failing_steps(session, base_url,
-                                                     buildid))
+    status = {
+      'builder_url': agent_url,
+      'number': build['number'],
+      'build_url':  "{}/builds/{}".format(agent_url, build['number']),
+      'state': build['state_string'],
+      'time_since': timedelta(seconds=time_since),
+      'duration': timedelta(seconds=duration),
+      'fail': build['state_string'] != 'build successful',
+      'next_in_progress': next_build is not None
+    }
 
-      return status
+    if status['fail']:
+      buildid = build['buildid']
+      status['steps'] = list(get_bot_failing_steps(session, base_url,
+                                                   buildid))
+
+    return status
 
 
 # Get status for all bots named in the config
@@ -154,7 +159,8 @@
             "T Since",
             "Duration",
             "Build #",
-            "Failing steps"
+            "Failing steps",
+            "Build In Progress",
     ]
     num_columns = len(column_titles)
     column_titles_html = "<tr>{}</tr>\n".format(
@@ -219,6 +225,12 @@
           temp.write("  <td style=\"text-align:center\">{}</td>\n".format(step_list))
         else:
           temp.write(empty_cell)
+        if 'next_in_progress' in status:
+          temp.write("  <td>{}</td>\n".format(
+                     "Yes" if status['next_in_progress'] else "No"))
+        else:
+          # No value means we don't know either way.
+          temp.write(empty_cell)
         temp.write("</tr>\n")
       temp.write("</tbody>\n")
     temp.write("</table>\n")