|
#!/usr/bin/env python |
|
|
|
import os |
|
from time import time, sleep |
|
import sys |
|
import argparse |
|
import pickle |
|
from blinkt import set_clear_on_exit, set_pixel, clear, show |
|
import requests |
|
|
|
# Authentication to the Bitbucket API is through an App Password and basic auth. |
|
# |
|
USER=os.environ["BITBUCKET_USER"] |
|
PASS=os.environ["BITBUCKET_PASS"] |
|
|
|
# Read a pickle'd config file. The configuration looks like: |
|
# |
|
# { |
|
# 'colors': [(255, 0, 0), (255, 127, 0), (255, 255, 0), (0, 255, 0), (0, 0, 255), (75, 0, 130), (148, 0, 211)], |
|
# 'repositories': ['app1', 'app2', 'app3', 'app4', 'app5', 'app6', 'app7'], |
|
# 'workspace': 'team' |
|
# } |
|
|
|
with open('config.pkl', 'rb') as cfg: |
|
config = pickle.load(cfg) |
|
|
|
API_HOST = "https://bitbucket.org/api/2.0/repositories" |
|
|
|
set_clear_on_exit(False) |
|
|
|
def setup_args(): |
|
parser = argparse.ArgumentParser(description="Light up your PRs") |
|
parser.add_argument('repo', help='Name of a repository in the configuration.') |
|
parser.add_argument('-v', '--verbosity', action='store_true', dest='verbose', help='Display verbose information.') |
|
return parser.parse_args() |
|
|
|
def main(): |
|
args = setup_args() |
|
repo_index = config['repositories'].index(args.repo) |
|
|
|
if args.verbose: |
|
print("clearing pixels") |
|
clear() |
|
|
|
r, g, b = config['colors'][repo_index] |
|
set_pixel(0, r, g, b) |
|
|
|
if args.verbose: |
|
print("getting pull requests for {0}".format(args.repo)) |
|
r = requests.get("{0}/{1}/{2}/pullrequests".format(API_HOST, config['workspace'], args.repo), auth=(USER, PASS)) |
|
|
|
if r.status_code == 200: |
|
if args.verbose: |
|
print("repo status good") |
|
set_pixel(1, 0, 128, 0) |
|
else: |
|
if args.verbose: |
|
print("repo status bad") |
|
set_pixel(1, 128, 0, 0) |
|
|
|
pr_count = r.json()['size'] |
|
if args.verbose: |
|
print("lighting up {0} LEDs".format(pr_count)) |
|
for x in range(0, pr_count): |
|
set_pixel(2 + x, 128, 128, 128) |
|
|
|
if args.verbose: |
|
print("showing pixels") |
|
show() |
|
|
|
if __name__ == "__main__": |
|
main() |